I know that there are a lot of questions regarding the error Malformed reply from SOCKS server
which mostly point to a wrong configuration for the proxy.
However, in my case, I'm using the system HTTP(!) proxy for a POST request with the apache httpclient library 4.3.5 (httpcore 4.3.2) like this:
SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(
ProxySelector.getDefault());
CloseableHttpClient httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
This is what has also been advised in https://mcmap.net/q/678315/-how-do-i-replace-deprecated-httpclient-getparams-with-requestconfig
In most situations this httpclient
and the following http POST request work very well. At one customer however, it fails with the following log error:
Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute
Information: I/O exception (java.net.SocketException) caught when processing request to {}->http://proxy.local:80->http://my-webservice.tld:80: Malformed reply from SOCKS server
Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute
Information: Retrying request to {}->http://proxy.local:80->http://my-webservice.tld:80
The local system proxy settings (on Windows 7) aren't configured as a SOCKS proxy, but as an HTTP proxy! I confirmed this by logging different RoutePlanner
and Proxy
parameters:
TunnelType: PLAIN
TargetHost: http://my-webservice.tld:80
ProxyHost: http://proxy.local:80
ProxyPort: 80
ProxyType: HTTP
However, my POST request isn't beeing sent correctly. In the proxy logfiles it appears as follows:
2015-03-05 10:11:04 119973 192.168.124.111 0 TCP_ERR_MISS 0 4 unknown - - / - - - - - - PROXIED - - xxx.xxx.xxx.xxx SG-HTTP-Service
This is my uploadFile()
method which uses the mentioned SystemDefaultRoutePlanner
and creates and executes the HttpPost
:
private String uploadFile(File fileToUpload) throws Exception {
SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
CloseableHttpClient httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
try {
HttpPost httppost = new HttpPost(webserviceURL);
MultipartEntityBuilder requestEntity = MultipartEntityBuilder.create();
requestEntity.addPart("project", new StringBody(paramProjekt, ContentType.TEXT_PLAIN));
requestEntity.addPart("param1", new StringBody(param1, ContentType.TEXT_PLAIN));
requestEntity.addPart("param2", new StringBody(param2, ContentType.TEXT_PLAIN));
requestEntity.addPart("debug", new StringBody(paramDebug, ContentType.TEXT_PLAIN));
requestEntity.addPart("xmlFile", new FileBody(fileToUpload));
ProgressHttpEntityWrapper.ProgressCallback progressCallback = new ProgressHttpEntityWrapper.ProgressCallback() {
@Override
public void progress(float progress) {
int min = 5;
int max = 40;
int diff = max - min;
gui.updateProgress(min + (int)(diff * progress / 100));
if (progress == 100) {
gui.setStep(GUI.STEP.PROCESSING);
}
}
};
httppost.setEntity(new ProgressHttpEntityWrapper(requestEntity.build(), progressCallback));
logger.info("executing request " + httppost.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httppost);
try {
logger.info("Response Status: " + response.getStatusLine());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
String responseString = EntityUtils.toString(resEntity);
return responseString;
}
EntityUtils.consume(resEntity);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
response.close();
}
} finally {
httpclient.close();
}
return null;
}
The last thing in my logfile is the executing request
log info but the Response Status:
log information never shows up...
Mrz 05, 2015 10:09:04 AM de.company.product.WebserviceClient.WebserviceClient uploadFile
Information: executing request POST http://my-webservice.tld HTTP/1.1
Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute
Information: I/O exception (java.net.SocketException) caught when processing request to {}->http://proxy.local:80->http://my-webservice.tld:80: Malformed reply from SOCKS server
Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute
Information: Retrying request to {}->http://proxy.local:80->http://my-webservice.tld:80
Does anyone has a clue why
- it is showing the
Malformed reply from SOCKS server
error when there is a HTTP proxy defined in the system and I use the system proxy settings? - how to configure either the
httpclient
or thehttppost
in the right way to recognize system HTTP proxy settings and work well with and without HTTP proxy?