soapMessage = getSOAPMessagePayload(message);
try {
messageTL.set(message);
RequestHandler requestHandler = endpoint.getRequestHandler();
final Map<String, List<String>> headers = new HashMap<String, List<String>>() ;
final Properties properties = message.getProperties() ;
final String[] names = properties.getNames() ;
for(final String name: names)
{
final Object value = properties.getProperty(name) ;
if (value != null)
{
String normalisedName = name.toLowerCase() ;
if ("content-type".equals(normalisedName))
{
if ("application/octet-stream".equals(value))
{
continue;
}
else
{
// CXF needs it to be case sensitive
normalisedName = "Content-Type";
}
}
final List<String> values = headers.get(normalisedName) ;
if (values == null)
{
final List<String> newValues = new ArrayList<String>() ;
newValues.add(value.toString()) ;
headers.put(normalisedName, newValues) ;
}
else
{
values.add(value.toString()) ;
}
}
}
//CXF throws NPE in handler if content-length not set
List<String> newValues = new ArrayList<String>();
newValues.add(String.valueOf(soapMessage.length));
headers.put("content-length", newValues);
final String endpointAddress = endpoint.getAddress() ;
String path = null ;
if (endpointAddress != null)
{
try
{
path = new URI(endpointAddress).getPath() ;
}
catch (final URISyntaxException urise) {} //ignore
}
if (path == null)
{
path = getHeaderValue(headers, "path") ;
}
final SOAPProcessorHttpServletRequest servletRequest = new SOAPProcessorHttpServletRequest(path, soapMessage, headers) ;
final SOAPProcessorHttpServletResponse servletResponse = new SOAPProcessorHttpServletResponse() ;
final ServletContext servletContext = SOAPProcessorFactory.getFactory().createServletContext(endpoint) ;
EndpointAssociation.setEndpoint(endpoint);
final ClassLoader old = Thread.currentThread().getContextClassLoader();
try
{
initialiseContextClassLoader(endpoint);
requestHandler.handleHttpRequest(endpoint, servletRequest, servletResponse, servletContext) ;
}
finally
{
Thread.currentThread().setContextClassLoader(old);
EndpointAssociation.removeEndpoint();