}
PostMethod method = new PostMethod(getRelUri(locationURI));
SoapMessage soapMessage = new SoapMessage();
soapHelper.getJBIMarshaler().fromNMS(soapMessage, nm);
Context context = soapHelper.createContext(soapMessage);
soapHelper.onSend(context);
SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapMessage);
copyHeaderInformation(nm, method);
RequestEntity entity = writeMessage(writer);
// remove content-type header that may have been part of the in message
if (!endpoint.isWantContentTypeHeaderFromExchangeIntoHttpRequest()) {
method.removeRequestHeader(HEADER_CONTENT_TYPE);
method.addRequestHeader(HEADER_CONTENT_TYPE, entity.getContentType());
}
// override content-type header
overrideContentType(method);
if (entity.getContentLength() < 0) {
method.removeRequestHeader(HEADER_CONTENT_LENGTH);
} else {
method.setRequestHeader(HEADER_CONTENT_LENGTH, Long.toString(entity.getContentLength()));
}
if (endpoint.isSoap() && method.getRequestHeader(HEADER_SOAP_ACTION) == null) {
if (endpoint.getSoapAction() != null) {
method.setRequestHeader(HEADER_SOAP_ACTION, endpoint.getSoapAction());
} else {
method.setRequestHeader(HEADER_SOAP_ACTION, "\"\"");
}
}
method.setRequestEntity(entity);
boolean close = true;
try {
// Set the retry handler
int retries = getConfiguration().isStreamingEnabled() ? 0 : getConfiguration().getRetryCount();
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(retries, true));
// Set authentication
if (endpoint.getBasicAuthentication() != null) {
endpoint.getBasicAuthentication().applyCredentials(getClient(), exchange, nm);
}
// Execute the HTTP method
int response = getClient().executeMethod(getHostConfiguration(locationURI, exchange, nm), method);
if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
if (!(exchange instanceof InOnly)) {
SoapReader reader = soapHelper.getSoapMarshaler().createReader();
Header contentType = method.getResponseHeader(HEADER_CONTENT_TYPE);
soapMessage = reader.read(method.getResponseBodyAsStream(),
contentType != null ? contentType.getValue() : null);
context.setFaultMessage(soapMessage);
soapHelper.onAnswer(context);
Fault fault = exchange.createFault();
fault.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
soapHelper.getJBIMarshaler().toNMS(fault, soapMessage);
exchange.setFault(fault);