Search in sources :

Example 1 with MarshalServiceRuntimeDescription

use of org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription in project axis-axis2-java-core by apache.

the class DocLitBareMethodMarshaller method demarshalResponse.

public Object demarshalResponse(Message message, Object[] signatureArgs, OperationDescription operationDesc) throws WebServiceException {
    EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
    EndpointDescription endpointDesc = ed.getEndpointDescription();
    // Note all exceptions are caught and rethrown with a WebServiceException
    try {
        // Sample Document message
        // ..
        // <soapenv:body>
        // <m:return ... >...</m:param>
        // </soapenv:body>
        // 
        // Important points.
        // 1) There is no operation element in the message
        // 2) The data blocks are located underneath the operation element.
        // 3) The name of the data blocks (m:param) are defined by the schema.
        // (SOAP indicates that the name of the element is not important, but
        // for document processing, we will assume that the name corresponds to
        // a schema root element)
        // 4) The type of the data block is defined by schema; thus in most cases
        // an xsi:type will not be present
        ParameterDescription[] pds = operationDesc.getParameterDescriptions();
        MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
        TreeSet<String> packages = marshalDesc.getPackages();
        // the next time.
        if (shouldRegisterUnmarshalInfo(operationDesc, message.getMessageContext())) {
            MethodMarshallerUtils.registerUnmarshalInfo(message.getMessageContext(), packages, marshalDesc.getPackagesKey());
        }
        // Get the return value.
        Class returnType = operationDesc.getResultActualType();
        Object returnValue = null;
        boolean hasReturnInBody = false;
        if (returnType != void.class) {
            AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
            if (attachmentDesc != null) {
                if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
                    String cid = message.getAttachmentID(0);
                    returnValue = message.getDataHandler(cid);
                } else {
                    throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
                }
            } else {
                // If the webresult is in the header, we need the name of the header so that we can find it.
                Element returnElement = null;
                if (operationDesc.isResultHeader()) {
                    returnElement = MethodMarshallerUtils.getReturnElement(packages, message, null, false, true, operationDesc.getResultTargetNamespace(), operationDesc.getResultName(), MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
                } else {
                    returnElement = MethodMarshallerUtils.getReturnElement(packages, message, null, false, false, null, null, MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
                    hasReturnInBody = true;
                }
                returnValue = returnElement.getTypeValue();
            }
            if (ConvertUtils.isConvertable(returnValue, returnType)) {
                returnValue = ConvertUtils.convert(returnValue, returnType);
            }
        }
        // Unmarshall the ParamValues from the Message
        List<PDElement> pvList = MethodMarshallerUtils.getPDElements(pds, message, packages, // output
        false, hasReturnInBody, // always unmarshal with "by element" mode
        null);
        // Populate the response Holders
        MethodMarshallerUtils.updateResponseSignatureArgs(pds, pvList, signatureArgs);
        return returnValue;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}
Also used : AttachmentDescription(org.apache.axis2.jaxws.description.AttachmentDescription) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) WebServiceException(javax.xml.ws.WebServiceException) MarshalServiceRuntimeDescription(org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription) ParameterDescription(org.apache.axis2.jaxws.description.ParameterDescription)

Example 2 with MarshalServiceRuntimeDescription

use of org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription in project axis-axis2-java-core by apache.

the class DocLitBareMethodMarshaller method marshalFaultResponse.

public Message marshalFaultResponse(Throwable throwable, OperationDescription operationDesc, Protocol protocol) throws WebServiceException {
    EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
    EndpointDescription endpointDesc = ed.getEndpointDescription();
    MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
    // It the protocol is null, then use the Protocol defined by the binding
    if (protocol == null) {
        protocol = Protocol.getProtocolForBinding(endpointDesc.getBindingType());
    }
    // Note all exceptions are caught and rethrown with a WebServiceException
    try {
        // Create the message
        MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
        Message m = mf.create(protocol);
        // Put the fault onto the message
        MethodMarshallerUtils.marshalFaultResponse(throwable, marshalDesc, operationDesc, m);
        return m;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}
Also used : MarshalServiceRuntimeDescription(org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription) MessageFactory(org.apache.axis2.jaxws.message.factory.MessageFactory) Message(org.apache.axis2.jaxws.message.Message) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) WebServiceException(javax.xml.ws.WebServiceException)

Example 3 with MarshalServiceRuntimeDescription

use of org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription in project axis-axis2-java-core by apache.

the class DocLitBareMethodMarshaller method demarshalFaultResponse.

public Throwable demarshalFaultResponse(Message message, OperationDescription operationDesc) throws WebServiceException {
    EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
    EndpointDescription endpointDesc = ed.getEndpointDescription();
    MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
    // Note all exceptions are caught and rethrown with a WebServiceException
    try {
        Throwable t = MethodMarshallerUtils.demarshalFaultResponse(operationDesc, marshalDesc, message);
        return t;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}
Also used : MarshalServiceRuntimeDescription(org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) WebServiceException(javax.xml.ws.WebServiceException)

Example 4 with MarshalServiceRuntimeDescription

use of org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription in project axis-axis2-java-core by apache.

the class DocLitBareMethodMarshaller method marshalResponse.

public Message marshalResponse(Object returnObject, Object[] signatureArgs, OperationDescription operationDesc, Protocol protocol) throws WebServiceException {
    EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
    EndpointDescription endpointDesc = ed.getEndpointDescription();
    // It the protocol is null, then use the Protocol defined by the binding
    if (protocol == null) {
        protocol = Protocol.getProtocolForBinding(endpointDesc.getBindingType());
    }
    // Note all exceptions are caught and rethrown with a WebServiceException
    try {
        // Sample Document message
        // ..
        // <soapenv:body>
        // <m:return ... >...</m:param>
        // </soapenv:body>
        // 
        // Important points.
        // 1) There is no operation element in the message
        // 2) The data blocks are located underneath the operation element.
        // 3) The name of the data blocks (m:param) are defined by the schema.
        // (SOAP indicates that the name of the element is not important, but
        // for document processing, we will assume that the name corresponds to
        // a schema root element)
        // 4) The type of the data block is defined by schema; thus in most cases
        // an xsi:type will not be present
        // Get the operation information
        ParameterDescription[] pds = operationDesc.getParameterDescriptions();
        MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
        TreeSet<String> packages = marshalDesc.getPackages();
        // Create the message
        MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
        Message m = mf.create(protocol);
        // Put the return object onto the message
        Class returnType = operationDesc.getResultActualType();
        if (returnType != void.class) {
            AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
            if (attachmentDesc != null) {
                if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
                    // Create an Attachment object with the signature value
                    Attachment attachment = new Attachment(returnObject, returnType, attachmentDesc, operationDesc.getResultPartName());
                    m.addDataHandler(attachment.getDataHandler(), attachment.getContentID());
                    m.setDoingSWA(true);
                } else {
                    throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
                }
            } else {
                Element returnElement = null;
                QName returnQName = new QName(operationDesc.getResultTargetNamespace(), operationDesc.getResultName());
                if (marshalDesc.getAnnotationDesc(returnType).hasXmlRootElement()) {
                    returnElement = new Element(returnObject, returnQName);
                } else {
                    /* when a schema defines a SimpleType with xsd list jaxws tooling generates art-effects with array rather than a java.util.List
                         * However the ObjectFactory definition uses a List and thus marshalling fails. Lets convert the Arrays to List.
                         */
                    if (operationDesc.isListType()) {
                        List list = new ArrayList();
                        if (returnType.isArray()) {
                            for (int count = 0; count < Array.getLength(returnObject); count++) {
                                Object obj = Array.get(returnObject, count);
                                list.add(obj);
                            }
                            returnElement = new Element(list, returnQName, List.class);
                        }
                    } else {
                        returnElement = new Element(returnObject, returnQName, returnType);
                    }
                }
                MethodMarshallerUtils.toMessage(returnElement, returnType, operationDesc.isListType(), marshalDesc, m, // always marshal using "by element" mode
                null, operationDesc.isResultHeader());
            }
        }
        // Convert the holder objects into a list of JAXB objects for marshalling
        List<PDElement> pvList = MethodMarshallerUtils.getPDElements(marshalDesc, pds, signatureArgs, // output
        false, false, false);
        // Put values onto the message
        MethodMarshallerUtils.toMessage(pvList, m, packages, null);
        // Enable SWA for nested SwaRef attachments
        if (operationDesc.hasResponseSwaRefAttachments()) {
            m.setDoingSWA(true);
        }
        return m;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}
Also used : MessageFactory(org.apache.axis2.jaxws.message.factory.MessageFactory) Message(org.apache.axis2.jaxws.message.Message) QName(javax.xml.namespace.QName) AttachmentDescription(org.apache.axis2.jaxws.description.AttachmentDescription) ArrayList(java.util.ArrayList) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) WebServiceException(javax.xml.ws.WebServiceException) MarshalServiceRuntimeDescription(org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription) ArrayList(java.util.ArrayList) List(java.util.List) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription) ParameterDescription(org.apache.axis2.jaxws.description.ParameterDescription)

Example 5 with MarshalServiceRuntimeDescription

use of org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription in project axis-axis2-java-core by apache.

the class DocLitBareMinimalMethodMarshaller method demarshalFaultResponse.

public Throwable demarshalFaultResponse(Message message, OperationDescription operationDesc) throws WebServiceException {
    EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
    EndpointDescription endpointDesc = ed.getEndpointDescription();
    MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
    // Note all exceptions are caught and rethrown with a WebServiceException
    try {
        Throwable t = MethodMarshallerUtils.demarshalFaultResponse(operationDesc, marshalDesc, message);
        return t;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}
Also used : MarshalServiceRuntimeDescription(org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) WebServiceException(javax.xml.ws.WebServiceException)

Aggregations

MarshalServiceRuntimeDescription (org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription)40 WebServiceException (javax.xml.ws.WebServiceException)39 EndpointDescription (org.apache.axis2.jaxws.description.EndpointDescription)37 EndpointInterfaceDescription (org.apache.axis2.jaxws.description.EndpointInterfaceDescription)37 ParameterDescription (org.apache.axis2.jaxws.description.ParameterDescription)26 Message (org.apache.axis2.jaxws.message.Message)18 MessageFactory (org.apache.axis2.jaxws.message.factory.MessageFactory)18 ArrayList (java.util.ArrayList)15 QName (javax.xml.namespace.QName)15 JAXBElement (javax.xml.bind.JAXBElement)13 Block (org.apache.axis2.jaxws.message.Block)11 JAXBBlockContext (org.apache.axis2.jaxws.message.databinding.JAXBBlockContext)11 JAXBWrapperTool (org.apache.axis2.jaxws.wrapper.JAXBWrapperTool)10 JAXBWrapperToolImpl (org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl)10 List (java.util.List)7 AttachmentDescription (org.apache.axis2.jaxws.description.AttachmentDescription)7 JAXBBlockFactory (org.apache.axis2.jaxws.message.factory.JAXBBlockFactory)7 XMLStreamException (javax.xml.stream.XMLStreamException)6 Protocol (org.apache.axis2.jaxws.message.Protocol)6 AnnotationDesc (org.apache.axis2.jaxws.runtime.description.marshal.AnnotationDesc)6