in shared-libraries/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingInOperationInterceptor.java [53:121]
public void handleMessage(Message message) {
QName itf = null;
QName op = null;
QName svc = null;
String ep = null;
String nsUri = null;
for (QName qname : message.getSoapHeaders().keySet()) {
if (isWSANamespace(qname.getNamespaceURI())) {
if (nsUri == null) {
nsUri = qname.getNamespaceURI();
} else if (!nsUri.equals(qname.getNamespaceURI())) {
throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
}
if (WSAddressingConstants.EL_ACTION.equals(qname.getLocalPart())) {
String action = getHeaderText(message.getSoapHeaders().get(qname));
String[] parts = URIResolver.split3(action);
itf = new QName(parts[0], parts[1]);
op = new QName(parts[0], parts[2]);
} else if (WSAddressingConstants.EL_TO.equals(qname.getLocalPart())) {
String to = getHeaderText(message.getSoapHeaders().get(qname));
String[] parts = URIResolver.split3(to);
svc = new QName(parts[0], parts[1]);
ep = parts[2];
} else {
// TODO: what ?
}
}
}
if (svc != null && ep != null) {
try {
ComponentContext ctx = message.get(ComponentContext.class);
ServiceEndpoint se = ctx.getEndpoint(svc, ep);
Document doc = ctx.getEndpointDescriptor(se);
Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, doc);
Service wsdlSvc = def.getService(svc);
if (wsdlSvc == null) {
if (def.getServices().size() == 0 && def.getPortTypes().size() == 1) {
PortType portType = (PortType) def.getPortTypes().values().iterator().next();
Definition newDef = PortTypeDecorator.createImportDef(def, svc.getNamespaceURI(), "urn:import");
PortTypeDecorator.decorate(newDef, portType, "jbi:" + svc.toString() + ":" + ep,
portType.getQName().getLocalPart() + "JBI",
svc.getLocalPart(), ep, "1.1");
wsdlSvc = newDef.getService(svc);
}
}
Port wsdlPort = wsdlSvc.getPort(ep);
Binding b = BindingFactory.createBinding(wsdlPort);
message.put(Binding.class, b);
message.put(ServiceEndpoint.class, se);
} catch (Exception e) {
throw new SoapFault(e);
}
}
if (itf != null && op != null) {
Binding<?> binding = message.get(Binding.class);
List<Operation<?>> matching = new ArrayList<Operation<?>>();
for (Operation<?> operation : binding.getOperations()) {
if (operation.getName().equals(op)) {
matching.add(operation);
}
}
if (matching.size() == 1) {
Operation operation = matching.get(0);
message.put(Operation.class, operation);
message.put(org.apache.servicemix.soap.api.model.Message.class,
isServer() ? operation.getOutput() : operation.getInput());
}
}
}