new RequestContent(), new RequestTargetHost(),
// Recommended protocol interceptors
new RequestConnControl(), new RequestUserAgent(),
new RequestExpectContinue() });
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
HttpContext context = new BasicHttpContext(null);
// log.info("ip:port - " + ip + ":" + port );
HttpHost host = new HttpHost(ip, port);// TODO
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
conn.setSocketTimeout(10000);
HttpConnectionParams.setSoTimeout(params, 10000);
ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
String res = null;
try {
// HttpEntity requestBody = new
// ByteArrayEntity(xml.getBytes("UTF-8"));// TODO
byte[] b = xml.getBytes("UTF-8"); // must be UTF-8
InputStream is = new ByteArrayInputStream(b, 0, b.length);
HttpEntity requestBody = new InputStreamEntity(is, b.length,
ContentType.create("text/xml;charset=UTF-8"));// must be
// UTF-8
// .create("application/xop+xml; charset=UTF-8; type=\"text/xml\""));//
// TODO
// RequestEntity re = new InputStreamRequestEntity(is, b.length,
// "application/xop+xml; charset=UTF-8; type=\"text/xml\"");
// postmethod.setRequestEntity(re);
if (!conn.isOpen()) {
Socket socket = new Socket(host.getHostName(), host.getPort());
conn.bind(socket, params);
}
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
"POST", action);
// add the 3 headers below
request.addHeader("Accept-Encoding", "gzip,deflate");
request.addHeader("SOAPAction", hosturl + action
+ method);// SOAP action
request.addHeader("uuid", "itest");// for editor token of DR-Api
request.setEntity(requestBody);
log.info(">> Request URI: " + request.getRequestLine().getUri());
request.setParams(params);
httpexecutor.preProcess(request, httpproc, context);
HttpResponse response = httpexecutor
.execute(request, conn, context);
response.setParams(params);
httpexecutor.postProcess(response, httpproc, context);
log.info("<< Response: " + response.getStatusLine());
String contentEncoding = null;
Header ce = response.getEntity().getContentEncoding();