Search in sources :

Example 1 with SOAPBinding

use of com.sun.xml.ws.api.model.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateBindingOperation.

protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    List<ParameterImpl> bodyParams = new ArrayList<>();
    List<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    operation.soapOperation().soapAction(soapBinding.getSOAPAction());
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    BodyType body = input._element(Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse() == Use.LITERAL) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAPHeaders(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            StringBuilder parts = new StringBuilder();
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
                if (param != null) {
                    if (isRpc) {
                        int i = 0;
                        for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                            if (i++ > 0) {
                                parts.append(" ");
                            }
                            parts.append(parameter.getPartName());
                        }
                    } else {
                        parts = new StringBuilder(param.getPartName());
                    }
                }
            }
            body.parts(parts.toString());
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAPHeaders(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) BodyType(com.sun.xml.ws.wsdl.writer.document.soap.BodyType) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body)

Example 2 with SOAPBinding

use of com.sun.xml.ws.api.model.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateBinding.

/**
 * Generates the Binding section of the WSDL
 */
protected void generateBinding() {
    Binding newBinding = serviceDefinitions.binding().name(model.getBoundPortTypeName().getLocalPart());
    extension.addBindingExtension(newBinding);
    newBinding.type(model.getPortTypeName());
    boolean first = true;
    for (JavaMethodImpl method : model.getJavaMethods()) {
        if (first) {
            SOAPBinding sBinding = method.getBinding();
            SOAPVersion soapVersion = sBinding.getSOAPVersion();
            if (soapVersion == SOAPVersion.SOAP_12) {
                com.sun.xml.ws.wsdl.writer.document.soap12.SOAPBinding soapBinding = newBinding.soap12Binding();
                soapBinding.transport(this.binding.getBindingId().getTransport());
                if (sBinding.getStyle().equals(Style.DOCUMENT))
                    soapBinding.style(DOCUMENT);
                else
                    soapBinding.style(RPC);
            } else {
                com.sun.xml.ws.wsdl.writer.document.soap.SOAPBinding soapBinding = newBinding.soapBinding();
                soapBinding.transport(this.binding.getBindingId().getTransport());
                if (sBinding.getStyle().equals(Style.DOCUMENT))
                    soapBinding.style(DOCUMENT);
                else
                    soapBinding.style(RPC);
            }
            first = false;
        }
        if (this.binding.getBindingId().getSOAPVersion() == SOAPVersion.SOAP_12)
            generateSOAP12BindingOperation(method, newBinding);
        else
            generateBindingOperation(method, newBinding);
    }
}
Also used : SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) WSBinding(com.sun.xml.ws.api.WSBinding) Binding(com.sun.xml.ws.wsdl.writer.document.Binding) JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding)

Example 3 with SOAPBinding

use of com.sun.xml.ws.api.model.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateSOAP12BindingOperation.

protected void generateSOAP12BindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    ArrayList<ParameterImpl> bodyParams = new ArrayList<>();
    ArrayList<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    String soapAction = soapBinding.getSOAPAction();
    if (soapAction != null) {
        operation.soap12Operation().soapAction(soapAction);
    }
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    com.sun.xml.ws.wsdl.writer.document.soap12.BodyType body = input._element(com.sun.xml.ws.wsdl.writer.document.soap12.Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse().equals(Use.LITERAL)) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAP12Headers(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(com.sun.xml.ws.wsdl.writer.document.soap12.Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0) {
                            parts.append(" ");
                        }
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAP12Headers(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        com.sun.xml.ws.wsdl.writer.document.soap12.SOAPFault soapFault = fault._element(com.sun.xml.ws.wsdl.writer.document.soap12.SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)

Aggregations

SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)3 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)2 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)2 ParameterImpl (com.sun.xml.ws.model.ParameterImpl)2 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)2 BindingOperationType (com.sun.xml.ws.wsdl.writer.document.BindingOperationType)2 Fault (com.sun.xml.ws.wsdl.writer.document.Fault)2 Body (com.sun.xml.ws.wsdl.writer.document.soap.Body)2 SOAPFault (com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 ParameterBinding (com.sun.xml.ws.api.model.ParameterBinding)1 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 Binding (com.sun.xml.ws.wsdl.writer.document.Binding)1 BodyType (com.sun.xml.ws.wsdl.writer.document.soap.BodyType)1