Skip to content

Commit

Permalink
Add follow redirect http param
Browse files Browse the repository at this point in the history
  • Loading branch information
walien committed Jul 21, 2015
1 parent d2f8768 commit eb56995
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions srv/src/main/java/qzui/domain/HttpConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ public class HttpConfiguration {

public static final String TRUST_ALL_CERTS_PROPERTY = "http.ssl.trustAllCerts";
public static final String TRUST_ALL_HOSTS_PROPERTY = "http.ssl.trustAllHosts";
public static final String FOLLOW_REDIRECT_PROPERTY = "http.followRedirect";

public static final String TRUST_ALL_CERTS_FIELD = "httpSSLTrustAllCerts";
public static final String TRUST_ALL_HOSTS_FIELD = "httpSSLTrustAllHosts";
public static final String FOLLOW_REDIRECT_FIELD = "httpFollowRedirect";

private boolean trustAllCerts;

private boolean trustAllHosts;

private boolean followRedirect;

public boolean isTrustAllCerts() {
return trustAllCerts;
}
Expand All @@ -29,4 +33,13 @@ public HttpConfiguration setTrustAllHosts(final boolean trustAllHosts) {
this.trustAllHosts = trustAllHosts;
return this;
}

public boolean isFollowRedirect() {
return followRedirect;
}

public HttpConfiguration setFollowRedirect(final boolean followRedirect) {
this.followRedirect = followRedirect;
return this;
}
}
11 changes: 9 additions & 2 deletions srv/src/main/java/qzui/domain/HttpJobDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,19 @@ public JobDetail buildJobDetail() {
private void configure(JobDataMap dataMap) {
Optional<String> trustAllCerts;
Optional<String> trustAllHosts;
Optional<String> followRedirect;
if (getHttpConfiguration() == null) {
trustAllCerts = Optional.fromNullable(System.getProperty(HttpConfiguration.TRUST_ALL_CERTS_PROPERTY));
trustAllHosts = Optional.fromNullable(System.getProperty(HttpConfiguration.TRUST_ALL_HOSTS_PROPERTY));
followRedirect = Optional.fromNullable(System.getProperty(HttpConfiguration.FOLLOW_REDIRECT_PROPERTY));
} else {
trustAllCerts = Optional.of(Boolean.toString(getHttpConfiguration().isTrustAllCerts()));
trustAllHosts = Optional.of(Boolean.toString(getHttpConfiguration().isTrustAllHosts()));
followRedirect = Optional.of(Boolean.toString(getHttpConfiguration().isFollowRedirect()));
}
dataMap.put(HttpConfiguration.TRUST_ALL_CERTS_FIELD, trustAllCerts.or(Boolean.toString(false)));
dataMap.put(HttpConfiguration.TRUST_ALL_HOSTS_FIELD, trustAllHosts.or(Boolean.toString(false)));
dataMap.put(HttpConfiguration.FOLLOW_REDIRECT_FIELD, followRedirect.or(Boolean.toString(false)));
}

@Override
Expand Down Expand Up @@ -172,7 +176,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {

setContentType(jobDataMap, request);
setCrendentials(jobDataMap, request);
setSecurityParams(jobDataMap, request);
setHttpParams(jobDataMap, request);

request.send(body);
int code = request.code();
Expand All @@ -181,13 +185,16 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
logger.info("{} {} => {}\n{}", method, url, code, responseBody);
}

private void setSecurityParams(JobDataMap jobDataMap, HttpRequest request) {
private void setHttpParams(JobDataMap jobDataMap, HttpRequest request) {
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_HOSTS_FIELD)) {
request.trustAllHosts();
}
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_CERTS_FIELD)) {
request.trustAllCerts();
}
if (jobDataMap.getBooleanFromString(HttpConfiguration.FOLLOW_REDIRECT_FIELD)) {
request.followRedirects(true);
}
}

private void setCrendentials(JobDataMap jobDataMap, HttpRequest request) {
Expand Down

0 comments on commit eb56995

Please sign in to comment.