Search in sources :

Example 1 with CheckedExceptionImpl

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

the class WSDLGenerator method generatePortType.

/**
 * Generates the WSDL portType
 */
protected void generatePortType() {
    PortType portType = portDefinitions.portType().name(model.getPortTypeName().getLocalPart());
    extension.addPortTypeExtension(portType);
    for (JavaMethodImpl method : model.getJavaMethods()) {
        Operation operation = portType.operation().name(method.getOperationName());
        generateParameterOrder(operation, method);
        extension.addOperationExtension(operation, method);
        switch(method.getMEP()) {
            case REQUEST_RESPONSE:
                // input message
                generateInputMessage(operation, method);
                // output message
                generateOutputMessage(operation, method);
                break;
            case ONE_WAY:
                generateInputMessage(operation, method);
                break;
            default:
                break;
        }
        // faults
        for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
            QName messageName = new QName(model.getTargetNamespace(), exception.getMessageName());
            FaultType paramType = operation.fault().message(messageName).name(exception.getMessageName());
            extension.addOperationFaultExtension(paramType, method, exception);
        }
    }
}
Also used : JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) QName(javax.xml.namespace.QName) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) Operation(com.sun.xml.ws.wsdl.writer.document.Operation) FaultType(com.sun.xml.ws.wsdl.writer.document.FaultType) PortType(com.sun.xml.ws.wsdl.writer.document.PortType)

Example 2 with CheckedExceptionImpl

use of com.sun.xml.ws.model.CheckedExceptionImpl 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 3 with CheckedExceptionImpl

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

the class WSDLGenerator method generateSOAPMessages.

/**
 * Generates messages for a SOAPBinding
 * @param method The {@link JavaMethod} to generate messages for
 * @param binding The {@link com.sun.xml.ws.api.model.soap.SOAPBinding} to add the generated messages to
 */
protected void generateSOAPMessages(JavaMethodImpl method, com.sun.xml.ws.api.model.soap.SOAPBinding binding) {
    boolean isDoclit = binding.isDocLit();
    // Message message = portDefinitions.message().name(method.getOperation().getName().getLocalPart());
    Message message = portDefinitions.message().name(method.getRequestMessageName());
    extension.addInputMessageExtension(message, method);
    com.sun.xml.ws.wsdl.writer.document.Part part;
    BindingContext jaxbContext = model.getBindingContext();
    boolean unwrappable = true;
    for (ParameterImpl param : method.getRequestParameters()) {
        if (isDoclit) {
            if (isHeaderParameter(param))
                unwrappable = false;
            part = message.part().name(param.getPartName());
            part.element(param.getName());
        } else {
            if (param.isWrapperStyle()) {
                for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                    part = message.part().name(childParam.getPartName());
                    part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                }
            } else {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            }
        }
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        message = portDefinitions.message().name(method.getResponseMessageName());
        extension.addOutputMessageExtension(message, method);
        for (ParameterImpl param : method.getResponseParameters()) {
            if (isDoclit) {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            } else {
                if (param.isWrapperStyle()) {
                    for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                        part = message.part().name(childParam.getPartName());
                        part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                    }
                } else {
                    part = message.part().name(param.getPartName());
                    part.element(param.getName());
                }
            }
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        QName tagName = exception.getDetailType().tagName;
        String messageName = exception.getMessageName();
        QName messageQName = new QName(model.getTargetNamespace(), messageName);
        if (processedExceptions.contains(messageQName))
            continue;
        message = portDefinitions.message().name(messageName);
        extension.addFaultMessageExtension(message, method, exception);
        // tagName.getLocalPart());
        part = message.part().name("fault");
        part.element(tagName);
        processedExceptions.add(messageQName);
    }
}
Also used : Message(com.sun.xml.ws.wsdl.writer.document.Message) QName(javax.xml.namespace.QName) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) BindingContext(com.sun.xml.ws.spi.db.BindingContext) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 4 with CheckedExceptionImpl

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

the class WsaTubeHelper method getFaultActionFromSEIModel.

String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
    String action = null;
    if (seiModel == null || wsdlPort == null) {
        return action;
    }
    try {
        SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
        if (sm == null) {
            return action;
        }
        if (sm.getSOAPBody() == null) {
            return action;
        }
        if (sm.getSOAPBody().getFault() == null) {
            return action;
        }
        Detail detail = sm.getSOAPBody().getFault().getDetail();
        if (detail == null) {
            return action;
        }
        String ns = detail.getFirstChild().getNamespaceURI();
        String name = detail.getFirstChild().getLocalName();
        WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
        JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl) wsdlOp.getJavaMethod() : null;
        if (jm != null) {
            for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
                if (ce.getDetailType().tagName.getLocalPart().equals(name) && ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
                    return ce.getFaultAction();
                }
            }
        }
        return action;
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
Also used : WSDLOperationMapping(com.sun.xml.ws.api.model.WSDLOperationMapping) JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) WebServiceException(jakarta.xml.ws.WebServiceException) SOAPException(jakarta.xml.soap.SOAPException) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail)

Example 5 with CheckedExceptionImpl

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

the class SOAPFaultBuilder method createException.

/**
 * This should be called from the client side to throw an {@link Exception} for a given soap mesage
 */
public Throwable createException(Map<QName, CheckedExceptionImpl> exceptions) throws JAXBException {
    DetailType dt = getDetail();
    Node detail = null;
    if (dt != null)
        detail = dt.getDetail(0);
    // return ProtocolException if the detail is not present or there is no checked exception
    if (detail == null || exceptions == null) {
        // throw a protocol exception
        return attachServerException(getProtocolException());
    }
    // check if the detail is a checked exception, if not throw a ProtocolException
    QName detailName = new QName(detail.getNamespaceURI(), detail.getLocalName());
    CheckedExceptionImpl ce = exceptions.get(detailName);
    if (ce == null) {
        // No Checked exception for the received detail QName, throw a SOAPFault exception
        return attachServerException(getProtocolException());
    }
    if (ce.getExceptionType().equals(ExceptionType.UserDefined)) {
        return attachServerException(createUserDefinedException(ce));
    }
    Class exceptionClass = ce.getExceptionClass();
    try {
        Constructor constructor = exceptionClass.getConstructor(String.class, (Class) ce.getDetailType().type);
        Exception exception = (Exception) constructor.newInstance(getFaultString(), getJAXBObject(detail, ce));
        return attachServerException(exception);
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) Constructor(java.lang.reflect.Constructor) Node(org.w3c.dom.Node) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) ProtocolException(jakarta.xml.ws.ProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException) SerializationException(com.sun.xml.ws.encoding.soap.SerializationException) JAXBException(jakarta.xml.bind.JAXBException)

Aggregations

CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)6 QName (javax.xml.namespace.QName)5 WebServiceException (jakarta.xml.ws.WebServiceException)4 ParameterImpl (com.sun.xml.ws.model.ParameterImpl)3 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)3 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)2 SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)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 ArrayList (java.util.ArrayList)2 WSDLOperationMapping (com.sun.xml.ws.api.model.WSDLOperationMapping)1 SerializationException (com.sun.xml.ws.encoding.soap.SerializationException)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 FaultType (com.sun.xml.ws.wsdl.writer.document.FaultType)1 Message (com.sun.xml.ws.wsdl.writer.document.Message)1 Operation (com.sun.xml.ws.wsdl.writer.document.Operation)1 PortType (com.sun.xml.ws.wsdl.writer.document.PortType)1