private void initializeBindingOperation(SoapBindingInfo bi, BindingOperationInfo boi) { SoapOperationInfo soi = new SoapOperationInfo(); SoapOperation soapOp = SOAPBindingUtil.getSoapOperation(boi.getExtensors(ExtensibilityElement.class)); if (soapOp != null) { String action = soapOp.getSoapActionURI(); if (action == null) { action = ""; } soi.setAction(action); soi.setStyle(soapOp.getStyle()); } boi.addExtensor(soi); if (boi.getInput() != null) { initializeMessage(bi, boi, boi.getInput()); } if (boi.getOutput() != null) { initializeMessage(bi, boi, boi.getOutput()); } }
private SoapMessage setUpMessage() throws Exception { SoapMessage message = new SoapMessage(new MessageImpl()); Exchange exchange = new ExchangeImpl(); BindingOperationInfo bop = setUpBindingOperationInfo( "http://foo/bar", "opReq", "opResp", SEI.class.getMethod("op", new Class[0])); SoapOperationInfo sop = new SoapOperationInfo(); sop.setAction("http://foo/bar/SEI/opReq"); bop.addExtensor(sop); exchange.put(BindingOperationInfo.class, bop); message.setExchange(exchange); message.put(Message.REQUESTOR_ROLE, Boolean.TRUE); control.replay(); return message; }
@Test public void testRequestorOutboundDispatchedSoapAction() throws Exception { SoapMessage message = setUpMessage(); BindingOperationInfo dbop = setUpBindingOperationInfo( "http://foo/bar/d", "opDReq", "opDResp", SEI.class.getMethod("op", new Class[0])); SoapOperationInfo soi = new SoapOperationInfo(); soi.setAction("http://foo/bar/d/SEI/opDReq"); dbop.addExtensor(soi); BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class); bop.setProperty("dispatchToOperation", dbop); interceptor.handleMessage(message); control.verify(); Map<String, List<String>> reqHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS)); assertNotNull(reqHeaders); List<String> soapaction = reqHeaders.get("soapaction"); assertTrue(null != soapaction && soapaction.size() == 1); assertEquals("\"http://foo/bar/d/SEI/opDReq\"", soapaction.get(0)); }
private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException { boolean isSoap12 = bi.getSoapVersion() instanceof Soap12; Bus bs = getBus(); WSDLManager m = bs.getExtension(WSDLManager.class); ExtensionRegistry extensionRegistry = m.getExtensionRegistry(); SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12); soapBinding.setStyle(bi.getStyle()); soapBinding.setTransportURI(bi.getTransportURI()); bi.addExtensor(soapBinding); for (BindingOperationInfo b : bi.getOperations()) { for (BindingFaultInfo faultInfo : b.getFaults()) { SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12); soapFault.setUse("literal"); soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart()); faultInfo.addExtensor(soapFault); } SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class); SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12); soapOperation.setSoapActionURI(soi.getAction()); soapOperation.setStyle(soi.getStyle()); boolean isRpc = "rpc".equals(soapOperation.getStyle()); b.addExtensor(soapOperation); if (b.getInput() != null) { List<String> bodyParts = null; List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class); if (headerInfos != null && headerInfos.size() > 0) { bodyParts = new ArrayList<String>(); for (MessagePartInfo part : b.getInput().getMessageParts()) { bodyParts.add(part.getName().getLocalPart()); } for (SoapHeaderInfo headerInfo : headerInfos) { SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12); soapHeader.setMessage(b.getInput().getMessageInfo().getName()); soapHeader.setPart(headerInfo.getPart().getName().getLocalPart()); soapHeader.setUse("literal"); bodyParts.remove(headerInfo.getPart().getName().getLocalPart()); headerInfo.getPart().setProperty(HEADER, true); b.getInput().addExtensor(soapHeader); } } SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12); body.setUse("literal"); if (isRpc) { body.setNamespaceURI(b.getName().getNamespaceURI()); } if (bodyParts != null) { body.setParts(bodyParts); } b.getInput().addExtensor(body); } if (b.getOutput() != null) { List<String> bodyParts = null; List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class); if (headerInfos != null && headerInfos.size() > 0) { bodyParts = new ArrayList<String>(); for (MessagePartInfo part : b.getOutput().getMessageParts()) { bodyParts.add(part.getName().getLocalPart()); } for (SoapHeaderInfo headerInfo : headerInfos) { SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12); soapHeader.setMessage(b.getOutput().getMessageInfo().getName()); soapHeader.setPart(headerInfo.getPart().getName().getLocalPart()); soapHeader.setUse("literal"); bodyParts.remove(headerInfo.getPart().getName().getLocalPart()); b.getOutput().addExtensor(soapHeader); } } SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12); body.setUse("literal"); if (isRpc) { body.setNamespaceURI(b.getName().getNamespaceURI()); } if (bodyParts != null) { body.setParts(bodyParts); } b.getOutput().addExtensor(body); } } }
public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) { SoapBindingConfiguration config; if (conf instanceof SoapBindingConfiguration) { config = (SoapBindingConfiguration) conf; } else { config = new SoapBindingConfiguration(); } if (WSDLConstants.NS_SOAP12.equals(bindingid) || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) { config.setVersion(Soap12.getInstance()); config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT); } SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion()); info.setName(config.getBindingName(si)); info.setStyle(config.getStyle()); info.setTransportURI(config.getTransportURI()); if (config.isMtomEnabled()) { info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE); } for (OperationInfo op : si.getInterface().getOperations()) { SoapOperationInfo sop = new SoapOperationInfo(); sop.setAction(config.getSoapAction(op)); sop.setStyle(config.getStyle(op)); BindingOperationInfo bop = info.buildOperation(op.getName(), op.getInputName(), op.getOutputName()); bop.addExtensor(sop); info.addOperation(bop); BindingMessageInfo bInput = bop.getInput(); if (bInput != null) { MessageInfo input = null; BindingMessageInfo unwrappedMsg = bInput; if (bop.isUnwrappedCapable()) { input = bop.getOperationInfo().getUnwrappedOperation().getInput(); unwrappedMsg = bop.getUnwrappedOperation().getInput(); } else { input = bop.getOperationInfo().getInput(); } setupHeaders(bop, bInput, unwrappedMsg, input, config); } BindingMessageInfo bOutput = bop.getOutput(); if (bOutput != null) { MessageInfo output = null; BindingMessageInfo unwrappedMsg = bOutput; if (bop.isUnwrappedCapable()) { output = bop.getOperationInfo().getUnwrappedOperation().getOutput(); unwrappedMsg = bop.getUnwrappedOperation().getOutput(); } else { output = bop.getOperationInfo().getOutput(); } setupHeaders(bop, bOutput, unwrappedMsg, output, config); } } try { createSoapBinding(info); } catch (WSDLException e) { e.printStackTrace(); } return info; }