We have a custom implementation of Spring's CommonsHttpInvokerRequestExecutor
. Now, we wish to upgrade from httpclient 3.1 to httpclient 4.3.3, so I need to implement HttpComponentsHttpInvokerRequestExecutor
instead.
However, the API is so different that I have been stuck on two points for a while now (I am new to httpclient, both 3 and 4, but I make my way using the API docs).
Does somebody have a clue on how to change this:
public CustomCommonsHttpInvokerRequestExecutor() {
super();
// No retry.
getHttpClient().getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
}
@Override
protected void executePostMethod(final HttpInvokerClientConfiguration config, final HttpClient httpClient, final PostMethod postMethod) throws IOException {
HttpState state = ((CustomHttpInvokerClientConfiguration) config).getState();
if (state.getCredentials(AuthScope.ANY) != null) {
postMethod.setDoAuthentication(true);
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(AuthScope.ANY, state.getCredentials(AuthScope.ANY));
} else {
httpClient.getParams().setAuthenticationPreemptive(false);
}
httpClient.executeMethod(null, postMethod, state);
}
to this:
public CustomHttpComponentsHttpInvokerRequestExecutor() {
super();
// FIXME default: no retry
// HttpClient client = getHttpClient();
}
@Override
protected HttpResponse executeHttpPost(final HttpInvokerClientConfiguration config, final HttpClient httpClient,
final HttpPost httpPost) throws IOException {
// FIXME Implement
// get credentials with AuthScope.ANY
// if (not null) {
// preemptive authentication
// } else {
// HTTP authentication preemptive is not supported by default
// The else should not be needed
// }
return super.executeHttpPost(config, httpClient, httpPost);
}
- Concerning the 'no retry' problematic, most examples I have seen just assume the implementation of HttpClient and do a savage cast, which I would try to avoid.
- Concerning the 'preemptive authentication' topic, since it is not supported natively anymore, I have searched and found examples on how to set it as always active, but no case such as in my own case.
Any help or lead greatly appreciated.