/**
* {@inheritDoc}
*/
public void handleMessage(final Exchange exchange) throws HandlerException {
Message message = exchange.getMessage();
Node request = message.getContent(Node.class);
Map<String, Object> headers = new HashMap<String, Object>();
for (Property p : exchange.getContext().getProperties()) {
if (p.hasLabel(EndpointLabel.SOAP.label())) {
headers.put(p.getName(), p.getValue());
}
}
try {
// Find part name associated with operation on port type
javax.wsdl.Operation operation =
_portType.getOperation(exchange.getContract().
getProviderOperation().getName(),
null, null);
Element newreq =
WSDLHelper.wrapRequestMessagePart((Element) request,
operation);
// Invoke the operation on the BPEL process
Element response = _engine.invoke(_serviceName, null,
exchange.getContract().
getProviderOperation().getName(),
newreq, headers);
if (exchange.getContract().getProviderOperation().
getExchangePattern().equals(ExchangePattern.IN_OUT)) {
Message reply = exchange.createMessage();
// Strip off wrapper and part to just return
// the part contents
reply.setContent(WSDLHelper.unwrapMessagePart(response));
// Set header parts for a response message
for (Map.Entry<String, Object> e : headers.entrySet()) {
exchange.getContext(reply).setProperty(e.getKey(),
headers.get(e.getKey())).addLabels(EndpointLabel.SOAP.label());
}
exchange.send(reply);
}
} catch (Fault f) {
SOAPFault fault = null;
try {
fault = javax.xml.soap.SOAPFactory.newInstance().
createFault("", f.getFaultName());
Detail detail=fault.addDetail();
Node cloned=detail.getOwnerDocument().importNode(WSDLHelper.unwrapMessagePart(f.getFaultMessage()), true);
detail.appendChild(cloned);
} catch (Exception e) {
throw new HandlerException(e);
}
Message msg = exchange.createMessage().setContent(fault);
exchange.sendFault(msg);
} catch (Exception e) {
throw new HandlerException(e);
}