Package org.apache.ws.commons.soap

Examples of org.apache.ws.commons.soap.SOAPEnvelope


        msgContext.setSoapAction(soapAction);
        msgContext.setTo(new EndpointReference(requestURI));
        msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
        msgContext.setServerSide(true);

        SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI,
                requestParameters, configurationContext);

        if (envelope == null) {
            return false;
        } else {
View Full Code Here


            msgContext.setSoapAction(soapActionHeader);
            msgContext.setTo(new EndpointReference(requestURI));
            msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
            msgContext.setServerSide(true);

            SOAPEnvelope envelope = null;
            StAXBuilder builder = null;

            if (contentType != null) {
                if (contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {

                    // It is MTOM
                    builder = TransportUtils.selectBuilderForMIME(msgContext, in, contentType);
                    envelope = (SOAPEnvelope) builder.getDocumentElement();
                } else {
                    XMLStreamReader xmlreader;

                    // Figure out the char set encoding and create the reader

                    // If charset is not specified
                    if (TransportUtils.getCharSetEncoding(contentType) == null) {
                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
                                MessageContext.DEFAULT_CHAR_SET_ENCODING);

                        // Set the encoding scheme in the message context
                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
                                MessageContext.DEFAULT_CHAR_SET_ENCODING);
                    } else {

                        // get the type of char encoding
                        String charSetEnc = TransportUtils.getCharSetEncoding(contentType);

                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
                                charSetEnc);

                        // Setting the value in msgCtx
                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEnc);
                    }

                    if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                        soap11 = false;

                        // it is SOAP 1.2
                        builder =
                                new StAXSOAPModelBuilder(xmlreader,
                                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                        envelope = (SOAPEnvelope) builder.getDocumentElement();
                    } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                        soap11 = true;

                        /**
                         * Configuration via Deployment
                         */
                        Parameter enable =
                                msgContext.getParameter(Constants.Configuration.ENABLE_REST);

                        if (((soapActionHeader == null) || (soapActionHeader.length() == 0))
                                && (enable != null)) {
                            if (Constants.VALUE_TRUE.equals(enable.getValue())) {

                                // If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
                                // the SOAP Action is absent it is rest !!
                                msgContext.setDoingREST(true);

                                SOAPFactory soapFactory = new SOAP11Factory();

                                builder = new StAXOMBuilder(xmlreader);
                                builder.setOmbuilderFactory(soapFactory);
                                envelope = soapFactory.getDefaultEnvelope();
                                envelope.getBody().addChild(builder.getDocumentElement());
                            }
                        } else {
                            builder = new StAXSOAPModelBuilder(
                                    xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                            envelope = (SOAPEnvelope) builder.getDocumentElement();
                        }
                    } else {
                        builder = new StAXSOAPModelBuilder(
                                xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                        envelope = (SOAPEnvelope) builder.getDocumentElement();
                    }
                }
            }

            String charsetEncoding = builder.getDocument().getCharsetEncoding();

            if ((charsetEncoding != null) && !"".equals(charsetEncoding)
                    && ! charsetEncoding.equalsIgnoreCase((String) msgContext.getProperty(
                    MessageContext.CHARACTER_SET_ENCODING))) {
                String faultCode;

                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
                        envelope.getNamespace().getName())) {
                    faultCode = SOAP12Constants.FAULT_CODE_SENDER;
                } else {
                    faultCode = SOAP11Constants.FAULT_CODE_SENDER;
                }

                throw new AxisFault(
                        "Character Set Encoding from " + "transport information do not match with "
                                + "character set encoding in the received SOAP message", faultCode);
            }

            msgContext.setEnvelope(envelope);

            AxisEngine engine = new AxisEngine(msgContext.getConfigurationContext());

            if (envelope.getBody().hasFault()) {
                engine.receiveFault(msgContext);
            } else {
                engine.receive(msgContext);
            }
        } catch (SOAPProcessingException e) {
View Full Code Here

            } else {
                throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
            }

            StAXBuilder builder;
            SOAPEnvelope envelope ;
            String charSetEnc =
                    (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);

            if (charSetEnc == null) {
                charSetEnc = (String) opContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
            }

            if (charSetEnc == null) {
                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
            }

            if (contentType != null) {
                msgContext.setDoingMTOM(true);
                builder = selectBuilderForMIME(msgContext, inStream,
                        (String) contentType);
                envelope = (SOAPEnvelope) builder.getDocumentElement();
            } else if (msgContext.isDoingREST()) {
                XMLStreamReader xmlreader =
                        XMLInputFactory.newInstance().createXMLStreamReader(inStream, charSetEnc);
                SOAPFactory soapFactory = new SOAP11Factory();

                builder = new StAXOMBuilder(xmlreader);
                builder.setOmbuilderFactory(soapFactory);
                envelope = soapFactory.getDefaultEnvelope();
                envelope.getBody().addChild(builder.getDocumentElement());
               
                // We now have the message inside an envolope. However, this is
                // only an OM; We need to build a SOAP model from it.

                builder = new StAXSOAPModelBuilder(envelope.getXMLStreamReader(), soapNamespaceURI);
                envelope = (SOAPEnvelope) builder.getDocumentElement();
            } else {
                XMLStreamReader xmlreader =
                        XMLInputFactory.newInstance().createXMLStreamReader(inStream, charSetEnc);
View Full Code Here

    public abstract OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out)
            throws AxisFault;

    public void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
        SOAPEnvelope envelope = msgContext.getEnvelope();
        OMElement outputMessage = envelope;

        if ((envelope != null) && msgContext.isDoingREST()) {
            outputMessage = envelope.getBody().getFirstElement();
        }

        if (outputMessage != null) {
            try {
                OMOutputFormat format = new OMOutputFormat();
View Full Code Here

                // create the SOAP Envelope
                Reader in = new InputStreamReader(socket.getInputStream());
                XMLStreamReader xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in);
                StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, null);
                SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();

                msgContext.setEnvelope(envelope);

                if (envelope.getBody().hasFault()) {
                    engine.receiveFault(msgContext);
                } else {
                    engine.receive(msgContext);
                }
            } else {
View Full Code Here

            log.debug("Exit: JMSTransport::shutdown");
        }
    }

    public void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
        SOAPEnvelope envelope = msgContext.getEnvelope();
        OMElement outputMessage = envelope;

        if ((envelope != null) && msgContext.isDoingREST()) {
            outputMessage = envelope.getBody().getFirstElement();
        }

        if (outputMessage != null) {
            try {
                OMOutputFormat format = new OMOutputFormat();
View Full Code Here

                        SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                    soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
                }

                StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
                SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();

                msgContext.setEnvelope(envelope);

                if (envelope.getBody().hasFault()) {
                    engine.receiveFault(msgContext);
                } else {
                    engine.receive(msgContext);
                }
            } else {
View Full Code Here

        boolean soap11 = false;

        try {
            msgContext.setServerSide(true);

            SOAPEnvelope envelope = null;
            StAXBuilder builder = null;

            if (contentType != null) {
                if (contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {

                    // It is MTOM
                    builder = TransportUtils.selectBuilderForMIME(msgContext, in, contentType);
                    envelope = (SOAPEnvelope) builder.getDocumentElement();
                } else {
                    XMLStreamReader xmlreader;

                    // Figure out the char set encoding and create the reader

                    // If charset is not specified
                    if (TransportUtils.getCharSetEncoding(contentType) == null) {
                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
                                MessageContext.DEFAULT_CHAR_SET_ENCODING);

                        // Set the encoding scheme in the message context
                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
                                MessageContext.DEFAULT_CHAR_SET_ENCODING);
                    } else {

                        // get the type of char encoding
                        String charSetEnc = TransportUtils.getCharSetEncoding(contentType);

                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
                                charSetEnc);

                        // Setting the value in msgCtx
                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEnc);
                    }

                    if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                        soap11 = false;

                        // it is SOAP 1.2
                        builder =
                                new StAXSOAPModelBuilder(xmlreader,
                                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                        envelope = (SOAPEnvelope) builder.getDocumentElement();
                    } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                        soap11 = true;
                        builder =
                                new StAXSOAPModelBuilder(xmlreader,
                                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                        envelope = (SOAPEnvelope) builder.getDocumentElement();
                    }
                }
            }

            String charsetEncoding = builder.getDocument().getCharsetEncoding();

            if ((charsetEncoding != null) && !"".equals(charsetEncoding)
                    && !((String) msgContext.getProperty(
                    MessageContext.CHARACTER_SET_ENCODING)).equalsIgnoreCase(charsetEncoding)) {
                String faultCode;

                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
                        envelope.getNamespace().getName())) {
                    faultCode = SOAP12Constants.FAULT_CODE_SENDER;
                } else {
                    faultCode = SOAP11Constants.FAULT_CODE_SENDER;
                }

                throw new AxisFault(
                        "Character Set Encoding from " + "transport information do not match with "
                                + "character set encoding in the received SOAP message", faultCode);
            }

            msgContext.setEnvelope(envelope);

            AxisEngine engine = new AxisEngine(msgContext.getConfigurationContext());

            if (envelope.getBody().hasFault()) {
                engine.receiveFault(msgContext);
            } else {
                engine.receive(msgContext);
            }
        } catch (SOAPProcessingException e) {
View Full Code Here

                opClient.addMessageContext(requetMessageContext);
                opClient.setOptions(options);

                opClient.execute(true);

                SOAPEnvelope result = opClient.getMessageContext(
                        WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();

                printResult(result);

                if (serviceGroupContextId == null)
                    serviceGroupContextId = getServiceGroupContextId(result);


            } else if ("c".equalsIgnoreCase(option)) {
                if (serviceGroupContextId == null) {
                    System.out.println("Error: First operation must be a New one. Please select 'n'");
                    continue;
                }

                System.out.print("Enter parameter...");
                String paramStr = reader.readLine();
                int param = Integer.parseInt(paramStr);
                String opStr = null;
                if ("+".equals(operation)) {
                    opStr = "addPrevious";
                } else if ("-".equals(operation)) {
                    opStr = "substractPrevious";
                } else if ("*".equals(operation)) {
                    opStr = "multiplyPrevious";
                }

                System.out.println("Invoking...");


                ServiceClient serviceClient = new ServiceClient();
                serviceClient.setOptions(options);
                MessageContext requetMessageContext = new MessageContext();
                requetMessageContext.setEnvelope(getPreviousRequestEnvelope(opStr, param,
                        serviceGroupContextId));

                OperationClient opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
                opClient.addMessageContext(requetMessageContext);
                opClient.setOptions(options);

                opClient.execute(true);

                SOAPEnvelope result = opClient.getMessageContext(
                        WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();

                printResult(result);

            }
View Full Code Here

    }

    public static SOAPEnvelope getRequestEnvelope(String operationName,
                                                  int param1, int param2, String groupContextId) {
        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope envelope = fac.getDefaultEnvelope();
        OMNamespace namespace = fac.createOMNamespace(
                "http://axis2/test/namespace1", "ns1");

        OMElement params = fac.createOMElement(operationName, namespace);
        OMElement param1OM = fac.createOMElement("param1", namespace);
        OMElement param2OM = fac.createOMElement("param2", namespace);
        param1OM.setText(Integer.toString(param1));
        param2OM.setText(Integer.toString(param2));
        params.addChild(param1OM);
        params.addChild(param2OM);
        envelope.getBody().setFirstChild(params);

        if (groupContextId != null) {
            OMNamespace axis2Namespace = fac.createOMNamespace(
                    Constants.AXIS2_NAMESPACE_URI,
                    Constants.AXIS2_NAMESPACE_PREFIX);
            SOAPHeaderBlock soapHeaderBlock = envelope.getHeader()
                    .addHeaderBlock(Constants.SERVICE_GROUP_ID, axis2Namespace);
            soapHeaderBlock.setText(groupContextId);
        }

        return envelope;
View Full Code Here

TOP

Related Classes of org.apache.ws.commons.soap.SOAPEnvelope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.