Skip to content

Commit

Permalink
improve http request options
Browse files Browse the repository at this point in the history
  • Loading branch information
walien committed Mar 25, 2016
1 parent eb56995 commit 596b116
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions srv/src/main/java/qzui/domain/HttpJobDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,10 @@ 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)));
HttpConfiguration httpConfiguration = Optional.fromNullable(getHttpConfiguration()).or(new HttpConfiguration());
dataMap.put(HttpConfiguration.TRUST_ALL_CERTS_FIELD, Boolean.toString(httpConfiguration.isTrustAllCerts()));
dataMap.put(HttpConfiguration.TRUST_ALL_HOSTS_FIELD, Boolean.toString(httpConfiguration.isTrustAllHosts()));
dataMap.put(HttpConfiguration.FOLLOW_REDIRECT_FIELD, Boolean.toString(httpConfiguration.isFollowRedirect()));
}

@Override
Expand Down Expand Up @@ -185,14 +174,21 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
logger.info("{} {} => {}\n{}", method, url, code, responseBody);
}

private boolean property(String name) {
return Boolean.valueOf(Optional.fromNullable(System.getProperty(name)).or(Boolean.FALSE.toString()));
}

private void setHttpParams(JobDataMap jobDataMap, HttpRequest request) {
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_HOSTS_FIELD)) {
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_HOSTS_FIELD)
|| property(HttpConfiguration.TRUST_ALL_HOSTS_PROPERTY)) {
request.trustAllHosts();
}
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_CERTS_FIELD)) {
if (jobDataMap.getBooleanFromString(HttpConfiguration.TRUST_ALL_CERTS_FIELD)
|| property(HttpConfiguration.TRUST_ALL_CERTS_PROPERTY)) {
request.trustAllCerts();
}
if (jobDataMap.getBooleanFromString(HttpConfiguration.FOLLOW_REDIRECT_FIELD)) {
if (jobDataMap.getBooleanFromString(HttpConfiguration.FOLLOW_REDIRECT_FIELD)
|| property(HttpConfiguration.FOLLOW_REDIRECT_PROPERTY)) {
request.followRedirects(true);
}
}
Expand Down

0 comments on commit 596b116

Please sign in to comment.