}
private synchronized String sendRequest(String body, String address, String soapAddress, String method, boolean secondTry)
{
//ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
HttpParams params = null;
BasicHttpProcessor httpproc = null;
try
{
logger.trace("Will send body: " + body);
URL url = new URL(address);
if(params == null)
{
params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
//HttpProtocolParams.setUserAgent(params, "MSN Explorer/9.0 (MSN 8.0; TmstmpExt)");
HttpProtocolParams.setUseExpectContinue(params, false);
httpproc = new BasicHttpProcessor();
// Required protocol interceptors
httpproc.addInterceptor(new RequestContent());
httpproc.addInterceptor(new RequestTargetHost());
// Recommended protocol interceptors
httpproc.addInterceptor(new RequestConnControl());
httpproc.addInterceptor(new RequestUserAgent());
httpproc.addInterceptor(new RequestExpectContinue());
}
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
HttpContext context = new BasicHttpContext(null);
HttpHost host = new HttpHost(url.getHost(), 443, "https");
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
if (!conn.isOpen())
{
// msn change their certificate with invalid one,
// which prevents us from retreiving contacts and maging them
// we install dummy trust man ager in order to fix it
SSLContext sc = SSLContext.getInstance("SSLv3");
TrustManager[] tma = {new DummyTrustManager()};
sc.init(null, tma, null);
SSLSocketFactory factory = sc.getSocketFactory();
Socket socket = factory.createSocket(host.getHostName(), host.getPort());
conn.bind(socket, params);
}
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
method,
url.getPath());
request.setEntity(new XmlEntity(body));
context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
request.setParams(params);
if(soapAddress != null)
request.addHeader("SOAPAction", soapAddress);
request.addHeader("Host", url.getHost());
request.addHeader("Accept", "text/*");
httpexecutor.preProcess(request, httpproc, context);
HttpResponse response = httpexecutor.execute(request, conn, context);
httpexecutor.postProcess(response, httpproc, context);
String resultStr = EntityUtils.toString(response.getEntity());
logger.debug(response.getStatusLine() + " / " + resultStr);
//if (!connStrategy.keepAlive(response, context))
try
{
conn.close();
}
catch (Exception e)
{
logger.error("error closing connection", e);
}