HttpPost postMethod = new HttpPost(targetURL.toString());
// set false as default, addContetInfo can overwrite
HttpProtocolParams.setUseExpectContinue(postMethod.getParams(),false);
Message reqMessage = msgContext.getRequestMessage();
boolean httpChunkStream = addContextInfo(postMethod, msgContext);
HttpEntity requestEntity = null;
requestEntity = new MessageRequestEntity(reqMessage, httpChunkStream,
http10 || !httpChunkStream);
postMethod.setEntity(requestEntity);
method = postMethod;
} else {
method = new HttpGet(targetURL.toString());
}
if (http10)
HttpProtocolParams.setVersion(method.getParams(),new ProtocolVersion("HTTP",1,0));
BackgroundHTTPThread methodThread = new BackgroundHTTPThread(httpClient,method);
methodThread.start();
try
{
int returnCode = methodThread.getResponseCode();
String contentType =
getHeader(methodThread, HTTPConstants.HEADER_CONTENT_TYPE);
String contentLocation =
getHeader(methodThread, HTTPConstants.HEADER_CONTENT_LOCATION);
String contentLength =
getHeader(methodThread, HTTPConstants.HEADER_CONTENT_LENGTH);
if ((returnCode > 199) && (returnCode < 300)) {
// SOAP return is OK - so fall through
} else if (msgContext.getSOAPConstants() ==
SOAPConstants.SOAP12_CONSTANTS) {
// For now, if we're SOAP 1.2, fall through, since the range of
// valid result codes is much greater
} else if ((contentType != null) && !contentType.equals("text/html")
&& ((returnCode > 499) && (returnCode < 600))) {
// SOAP Fault should be in here - so fall through
} else {
String statusMessage = methodThread.getResponseStatus();
AxisFault fault = new AxisFault("HTTP",
"(" + returnCode + ")"
+ statusMessage, null,
null);
fault.setFaultDetailString(
Messages.getMessage("return01",
"" + returnCode,
getResponseBodyAsString(methodThread)));
fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE,
Integer.toString(returnCode));
throw fault;
}
String contentEncoding =
methodThread.getFirstHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
if (contentEncoding != null) {
AxisFault fault = new AxisFault("HTTP",
"unsupported content-encoding of '"
+ contentEncoding
+ "' found", null, null);
throw fault;
}
Map<String,List<String>> responseHeaders = methodThread.getResponseHeaders();
InputStream dataStream = methodThread.getSafeInputStream();
Message outMsg = new Message(new BackgroundInputStream(methodThread,dataStream),
false, contentType, contentLocation);
// Transfer HTTP headers of HTTP message to MIME headers of SOAP message
MimeHeaders responseMimeHeaders = outMsg.getMimeHeaders();
for (String name : responseHeaders.keySet())
{
List<String> values = responseHeaders.get(name);
for (String value : values) {
responseMimeHeaders.addHeader(name,value);
}
}
outMsg.setMessageType(Message.RESPONSE);
// Put the message in the message context.
msgContext.setResponseMessage(outMsg);
// Pass off the method thread to the stream for closure