Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JENKINS-15564
  • Loading branch information
gboissinot committed Oct 21, 2012
1 parent b0dd8ad commit f2b5be1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
55 changes: 42 additions & 13 deletions src/main/java/org/jenkinsci/plugins/urltrigger/URLTrigger.java
Expand Up @@ -167,15 +167,19 @@ protected String getName() {
}

private Client getClientObject(URLTriggerEntry entry, XTriggerLog log) {

Client client = createClient(entry);
if (isAuthBasic(entry)) {
addBasicAuth(entry, log, client);
}

/* Set a connect and read timeout. If this hangs, it can actually
take down all of the jenkins schedule events.
This is 5 minutes expressed as milliseconds. */
client.setConnectTimeout(300000);
client.setReadTimeout(300000);
*/
int timeout = entry.getTimeout();
client.setConnectTimeout(timeout*1000); //in milliseconds
client.setReadTimeout(timeout*1000); //in milliseconds

return client;
}

Expand Down Expand Up @@ -337,6 +341,18 @@ private URLTriggerEntry fillAndGetEntry(StaplerRequest req, JSONObject entryObje
urlTriggerEntry.setPassword(encryptedValue);
}

//Process timeout
urlTriggerEntry.setTimeout(5 * 60); // 5 minutes by default
String timeout = entryObject.getString("timeout");
if (timeout != null) {
try {
int timeoutSeconds = Integer.parseInt(timeout);
urlTriggerEntry.setTimeout(timeoutSeconds);
} catch (NumberFormatException ne) {
//no change default timeout
}
}

//Process checkStatus
Object checkStatusObject = entryObject.get("checkStatus");
if (checkStatusObject != null) {
Expand Down Expand Up @@ -406,32 +422,45 @@ public DescriptorExtensionList getListURLTriggerDescriptors() {
return DescriptorExtensionList.createDescriptorList(Hudson.getInstance(), URLTriggerContentType.class);
}

public FormValidation doCheckStatus(@QueryParameter String value) {
public FormValidation doCheckURL(@QueryParameter String value) {

if (value == null || value.trim().isEmpty()) {
return FormValidation.ok();
return FormValidation.error("The url field is mandatory.");
}
try {
Integer.parseInt(value);
ClientConfig cc = new DefaultClientConfig();
Client client = Client.create(cc);
client.resource(value).get(ClientResponse.class);
return FormValidation.ok();
} catch (Exception e) {
return FormValidation.error("You must provide a valid number status such as 200, 301, ...");
return FormValidation.error(e.getMessage());
}
}

public FormValidation doCheckTimeout(@QueryParameter String value) {

public FormValidation doCheckURL(@QueryParameter String value) {
if ((value != null) && (value.trim().length() != 0)) {
int timeout = 0;
try {
timeout = Integer.parseInt(value);
} catch (NumberFormatException ne) {
return FormValidation.error("You must provide a timeout number (in seconds).");
}
}

return FormValidation.ok();
}

public FormValidation doCheckStatus(@QueryParameter String value) {

if (value == null || value.trim().isEmpty()) {
return FormValidation.error("The url field is mandatory.");
return FormValidation.ok();
}
try {
ClientConfig cc = new DefaultClientConfig();
Client client = Client.create(cc);
client.resource(value).get(ClientResponse.class);
Integer.parseInt(value);
return FormValidation.ok();
} catch (Exception e) {
return FormValidation.error(e.getMessage());
return FormValidation.error("You must provide a valid number status such as 200, 301, ...");
}
}

Expand Down
Expand Up @@ -19,6 +19,7 @@ public class URLTriggerEntry implements Serializable {
private boolean proxyActivated;
private boolean checkStatus;
private int statusCode;
private int timeout; //in seconds
private boolean checkETag;
private boolean checkLastModificationDate;
private boolean inspectingContent;
Expand Down Expand Up @@ -132,4 +133,12 @@ public String getETag() {
public void setETag(String ETag) {
this.ETag = ETag;
}

public int getTimeout() {
return timeout;
}

public void setTimeout(int timeout) {
this.timeout = timeout;
}
}
Expand Up @@ -12,6 +12,7 @@
</f:entry>

<f:advanced>

<f:entry field="proxyActivated">
<f:checkbox
field="proxyActivated"
Expand All @@ -20,6 +21,14 @@
title="${%Activate the Jenkins Proxy}"/>
</f:entry>

<f:section title="${%Client parameters}">
<f:entry field="timeout" title="${%Timeout}">
<f:textbox name="timeout"
checkUrl="'${rootURL}/trigger/URLTrigger/checkTimeout?value='+encodeURIComponent(this.value)"
value="${urlElements.timeout}"/>
</f:entry>
</f:section>

<f:section title="${%Basic Authentication}">
<f:entry field="username" title="${%User}">
<f:textbox name="username"
Expand Down
@@ -0,0 +1,7 @@
<div>
<p>
Set a connect and read timeout in seconds.<br/>
The value must be an integer. <br/>
By default, the timeout is 5 minutes (300 seconds).
</p>
</div>

0 comments on commit f2b5be1

Please sign in to comment.