james_a_woods
Sep 26th, 2005, 09:27 PM
I am writing an application using the spring HTTP remote invocation framework in conjunction with the Commons HttpClient.
I found I was having great difficulty diagnosising problems that I was having as the CommonsHttpInvokerRequestExecutor.executePostMetho d(...) method ignores the HTTP status code. I was then just getting a corrupted stream error on the read operation later on in the process.
I have worked around this in a rather simplistic manner by subclassing the CommonsHttpInvokerRequestExecutor and implementing:
protected void executePostMethod(HttpInvokerClientConfiguration pConfig, HttpClient pHttpClient, PostMethod postMethod) throws IOException {
try {
super.executePostMethod(pConfig, pHttpClient, postMethod);
} catch (IOException e) {
HttpClient httpClient = getHttpClient();
if (httpClient.getHostConfiguration().isProxySet() ) {
throw new HttpRemoteException("Error communicating with proxy server", e);
} else {
throw new HttpRemoteException("Error communicating with remote server", e);
}
}
if (postMethod.getStatusCode() >= 300) {
throw new HttpRemoteException("HTTP error communicating with remote server: ",
postMethod.getStatusCode(), postMethod.getStatusText());
}
}
Though I'm sure a more sophisticated approach would be required for general consumption, I though that this would be worth posting as a suggestion.
Cheers
James
I found I was having great difficulty diagnosising problems that I was having as the CommonsHttpInvokerRequestExecutor.executePostMetho d(...) method ignores the HTTP status code. I was then just getting a corrupted stream error on the read operation later on in the process.
I have worked around this in a rather simplistic manner by subclassing the CommonsHttpInvokerRequestExecutor and implementing:
protected void executePostMethod(HttpInvokerClientConfiguration pConfig, HttpClient pHttpClient, PostMethod postMethod) throws IOException {
try {
super.executePostMethod(pConfig, pHttpClient, postMethod);
} catch (IOException e) {
HttpClient httpClient = getHttpClient();
if (httpClient.getHostConfiguration().isProxySet() ) {
throw new HttpRemoteException("Error communicating with proxy server", e);
} else {
throw new HttpRemoteException("Error communicating with remote server", e);
}
}
if (postMethod.getStatusCode() >= 300) {
throw new HttpRemoteException("HTTP error communicating with remote server: ",
postMethod.getStatusCode(), postMethod.getStatusText());
}
}
Though I'm sure a more sophisticated approach would be required for general consumption, I though that this would be worth posting as a suggestion.
Cheers
James