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();
if (ce != null) {
contentEncoding = ce.getValue();
}
if (contentEncoding != null
&& contentEncoding.indexOf("gzip") != -1) {
GZIPInputStream gzipin = new GZIPInputStream(response
.getEntity().getContent());
Scanner in = new Scanner(new InputStreamReader(gzipin, "UTF-8"));
StringBuilder sb = new StringBuilder();
while (in.hasNextLine()) {
sb.append(in.nextLine()).append(
System.getProperty("line.separator"));
}
res = sb.toString();
} else {
res = EntityUtils.toString(response.getEntity(), "UTF-8");
}
log.info(res);
log.info("==============");
if (!connStrategy.keepAlive(response, context)) {
conn.close();
} else {
log.info("Connection kept alive...");
}
} finally {