if (SOAP_MESSAGE_FACTORY == null)
{
throw new WebServiceException("Failed to instantiate SOAP Message Factory") ;
}
final MAP soapIncomingProps = AddressingContext.getAddressingProperties() ;
final Message esbReq = MessageFactory.getInstance().getMessage() ;
final ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader() ;
final ClassLoader deploymentClassLoader = LifecycleResourceManager.getSingleton().getClassLoaderForDeployment(deployment) ;
if (deploymentClassLoader != null)
{
Thread.currentThread().setContextClassLoader(deploymentClassLoader) ;
}
try
{
final SOAPBody soapBody = request.getSOAPBody() ;
if (soapBody == null)
{
throw new WebServiceException("Missing SOAP body from request") ;
}
// There is a bug in JBossWS extractContentAsDocument so we do this ourselves
final Iterator children = soapBody.getChildElements() ;
boolean found = false ;
while(children.hasNext())
{
final Node node = (Node)children.next() ;
if (node instanceof SOAPElement)
{
if (found)
{
throw new SOAPException("Found multiple SOAPElements in SOAPBody") ;
}
final StringWriter sw = new StringWriter() ;
final XMLEventWriter writer = XMLHelper.getXMLEventWriter(new StreamResult(sw)) ;
XMLHelper.readDomNode(node, writer, true) ;
requestProxy.setPayload(esbReq, sw.toString()) ;
found = true ;
}
}
if (!found)
{
throw new SOAPException("Could not find SOAPElement in SOAPBody") ;
}
if (soapIncomingProps != null)
{
initialiseWSAProps(esbReq, soapIncomingProps) ;
}
// Extract security info from SOAPMessage.
AuthenticationRequest authRequest = extractSecurityDetails(request, esbReq);
ExtractorUtil.addAuthRequestToMessage(authRequest, esbReq);
// We should be able to return null here but this causes JBossWS to NPE.
final Message esbRes = deliverMessage(esbReq) ;
final SOAPMessage response = SOAP_MESSAGE_FACTORY.createMessage();
if (esbRes != null)
{
final Object input = responseProxy.getPayload(esbRes) ;
if (input == null)
{
throw new SOAPException("Null response from service") ;
}
final String soapRes = input.toString();
final Document root = parseAsDom(soapRes) ;
response.getSOAPBody().addDocument(root) ;
}
if (soapIncomingProps == null)
{
AddressingContext.setAddressingProperties(null) ;
}
else
{
final MAP soapOutgoingProps = ADDRESSING_BUILDER.newMap() ;
if (action != null)
{
soapOutgoingProps.setAction(action) ;
}
AddressingContext.setAddressingProperties(soapOutgoingProps) ;
}
return response ;