Search in sources :

Example 1 with SoapBinding

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.

the class SoapBindingFactory method createSoapBinding.

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.isEmpty()) {
                bodyParts = new ArrayList<>();
                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.isEmpty()) {
                bodyParts = new ArrayList<>();
                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);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) WSDLManager(org.apache.cxf.wsdl.WSDLManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 2 with SoapBinding

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.

the class SoapBindingFactory method createBindingInfo.

public BindingInfo createBindingInfo(ServiceInfo service, javax.wsdl.Binding binding, String ns) {
    SoapBindingInfo bi = new SoapBindingInfo(service, ns);
    // Copy all the extensors
    initializeBindingInfo(service, binding, bi);
    SoapBinding wSoapBinding = SOAPBindingUtil.getSoapBinding(bi.getExtensors(ExtensibilityElement.class));
    bi.setTransportURI(wSoapBinding.getTransportURI());
    bi.setStyle(wSoapBinding.getStyle());
    for (BindingOperationInfo boi : bi.getOperations()) {
        initializeBindingOperation(bi, boi);
    }
    return bi;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 3 with SoapBinding

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.

the class ServiceImpl method initializePorts.

private void initializePorts() {
    try {
        Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL);
        javax.wsdl.Service serv = def.getService(serviceName);
        if (serv == null) {
            throw new WebServiceException("Could not find service named " + serviceName + " in wsdl " + wsdlURL);
        }
        Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts());
        for (Port port : wsdlports.values()) {
            QName name = new QName(serviceName.getNamespaceURI(), port.getName());
            String address = null;
            String bindingID = null;
            List<? extends ExtensibilityElement> extensions = CastUtils.cast(port.getBinding().getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                } else if (e instanceof SOAP12Binding) {
                    bindingID = SOAPBinding.SOAP12HTTP_BINDING;
                } else if (e instanceof javax.wsdl.extensions.soap.SOAPBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                }
            }
            extensions = CastUtils.cast(port.getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapAddress) {
                    address = ((SoapAddress) e).getLocationURI();
                } else if (e instanceof AddressType) {
                    address = ((AddressType) e).getLocation();
                } else if (e instanceof SOAP12Address) {
                    address = ((SOAP12Address) e).getLocationURI();
                } else if (e instanceof SOAPAddress) {
                    address = ((SOAPAddress) e).getLocationURI();
                } else if (e instanceof HTTPAddress) {
                    address = ((HTTPAddress) e).getLocationURI();
                }
            }
            addPort(name, bindingID, address);
        }
    } catch (WebServiceException e) {
        throw e;
    } catch (Throwable e) {
        if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, e.getLocalizedMessage(), e);
        }
        WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
        Service service = sf.create();
        for (ServiceInfo si : service.getServiceInfos()) {
            for (EndpointInfo ei : si.getEndpoints()) {
                String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId());
                addPort(ei.getName(), bindingID, ei.getAddress());
            }
        }
    }
}
Also used : HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) Port(javax.wsdl.Port) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) SoapAddress(org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLManager(org.apache.cxf.wsdl.WSDLManager) AddressType(org.apache.cxf.wsdl.http.AddressType)

Example 4 with SoapBinding

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.

the class ServiceProcessor method processOperation.

private void processOperation(JavaModel model, BindingOperationInfo bop, BindingInfo binding) throws ToolException {
    boolean enableOpMime = false;
    JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
    if (bind != null && bind.isEnableMime()) {
        enableOpMime = true;
    }
    JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
    if (bopBinding != null && bopBinding.isEnableMime()) {
        enableOpMime = true;
        if (bopBinding.getJaxwsParas() != null) {
            jaxwsBinding.setJaxwsParas(bopBinding.getJaxwsParas());
        }
    }
    JavaInterface jf = null;
    for (JavaInterface jf2 : model.getInterfaces().values()) {
        if (binding.getInterface().getName().getLocalPart().equals(jf2.getWebServiceName())) {
            jf = jf2;
        }
    }
    if (jf == null) {
        throw new ToolException("No Java Interface available");
    }
    if (isSoapBinding()) {
        SoapBinding soapBinding = (SoapBinding) bindingObj;
        if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
            jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
        } else {
            jf.setSOAPStyle(SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()));
        }
    } else {
        // REVISIT: fix for xml binding
        jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
    }
    Object[] methods = jf.getMethods().toArray();
    for (int i = 0; i < methods.length; i++) {
        JavaMethod jm = (JavaMethod) methods[i];
        if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
            if (isSoapBinding()) {
                // TODO: add customize here
                // doCustomizeOperation(jf, jm, bop);
                Map<String, Object> prop = getSoapOperationProp(bop);
                String soapAction = prop.get(soapOPAction) == null ? "" : (String) prop.get(soapOPAction);
                String soapStyle = prop.get(soapOPStyle) == null ? "" : (String) prop.get(soapOPStyle);
                jm.setSoapAction(soapAction);
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
                    org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED", LOG);
                    throw new ToolException(msg);
                }
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
                    jm.setSoapStyle(jf.getSOAPStyle());
                } else {
                    jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
                }
            } else {
                // REVISIT: fix for xml binding
                jm.setSoapStyle(jf.getSOAPStyle());
            }
            if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
                jm.getAnnotationMap().remove("SOAPBinding");
            }
            OperationProcessor processor = new OperationProcessor(context);
            int headerType = isNonWrappable(bop);
            OperationInfo opinfo = bop.getOperationInfo();
            JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
            JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
            boolean enableMime = enableOpMime;
            boolean enableWrapperStyle = true;
            if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = infBinding.isEnableWrapperStyle();
            }
            if (infBinding != null && infBinding.isSetEnableMime()) {
                enableMime = infBinding.isEnableMime();
            }
            if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = opBinding.isEnableWrapperStyle();
            }
            if (opBinding != null && opBinding.isSetEnableMime()) {
                enableMime = opBinding.isEnableMime();
            }
            if (jaxwsBinding.isEnableMime() || enableMime) {
                jm.setMimeEnable(true);
            }
            if ((jm.isWrapperStyle() && headerType > this.noHEADER) || !jaxwsBinding.isEnableWrapperStyle() || (jm.enableMime() && jm.isWrapperStyle()) || !enableWrapperStyle) {
                // changed wrapper style
                jm.setWrapperStyle(false);
                processor.processMethod(jm, bop.getOperationInfo());
                jm.getAnnotationMap().remove("ResponseWrapper");
                jm.getAnnotationMap().remove("RequestWrapper");
            } else {
                processor.processMethod(jm, bop.getOperationInfo());
            }
            if (headerType == this.resultHeader) {
                JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
                if (resultAnno != null) {
                    resultAnno.addElement(new JAnnotationElement("header", true, true));
                }
            }
            processParameter(jm, bop);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) Message(org.apache.cxf.common.i18n.Message) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException)

Example 5 with SoapBinding

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.

the class WSDLToSoapProcessor method setSoapBindingExtElement.

private void setSoapBindingExtElement() throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    SOAPBindingUtil.addSOAPNamespace(wsdlDefinition, isSOAP12());
    SoapBinding soapBinding = null;
    try {
        soapBinding = SOAPBindingUtil.createSoapBinding(extReg, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapBinding.setStyle((String) env.get(ToolConstants.CFG_STYLE));
    binding.addExtensibilityElement(soapBinding);
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)

Aggregations

SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)13 ToolException (org.apache.cxf.tools.common.ToolException)8 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)7 QName (javax.xml.namespace.QName)7 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)7 Binding (javax.wsdl.Binding)6 BindingOperation (javax.wsdl.BindingOperation)6 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)6 File (java.io.File)5 SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)5 Test (org.junit.Test)5 BindingInput (javax.wsdl.BindingInput)4 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 Message (org.apache.cxf.common.i18n.Message)3 BindingFault (javax.wsdl.BindingFault)2 SOAP12Body (javax.wsdl.extensions.soap12.SOAP12Body)2 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)2 SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)2 WSDLManager (org.apache.cxf.wsdl.WSDLManager)2