Package org.apache.axiom.om.impl.builder

Examples of org.apache.axiom.om.impl.builder.StAXBuilder


     */
    public void close() throws XMLStreamException {

        // If there is a builder, it controls its parser
        if (builder != null && builder instanceof StAXBuilder) {
            StAXBuilder staxBuilder = (StAXBuilder) builder;
            staxBuilder.close();
            setParser(null);
        } else {
            if (parser != null) {
                try {
                    if (!isClosed()) {
View Full Code Here


        if (parser != null) {
            return parser.getProperty(s);
        }
        // Delegate to the builder's parser.
        if (builder != null && builder instanceof StAXBuilder) {
            StAXBuilder staxBuilder = (StAXBuilder) builder;
            if (!staxBuilder.isClosed()) {
                // If the parser was closed by something other
                // than the builder, an IllegalStateException is
                // thrown.  For now, return null as this is unexpected
                // by the caller.
                try {
View Full Code Here

            if ((builder != null) && (builder instanceof StAXBuilder)) {
                try {
                    if (isDebugEnabled) {
                        log.debug("closing builder: " + builder);
                    }
                    StAXBuilder staxBuilder = (StAXBuilder) builder;
                    staxBuilder.close();
                } catch (Exception e) {
                    if (isDebugEnabled) {
                        log.error("Could not close builder or parser due to: ", e);
                    }
                }
View Full Code Here

    public void testCode() {
        try {
            String filename = "soap/wrongEnvelopeNamespace.xml";
            XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(
                    getTestResource(filename));
            StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null); //exception here
            fail("Builder must fail here due to wrong SOAP namespace");
        } catch (SOAPProcessingException e) {
            assertTrue(true);
        } catch (Exception e) {
            fail("Only SOAPProcessingException can be thrown here");
View Full Code Here

        if(!InvocationResponse.SUSPEND.equals(response)) {
          // Performance work - need to close the XMLStreamReader to prevent GC thrashing.
          SOAPEnvelope env = msgToInvoke.getEnvelope();
          if(env!=null){
            StAXBuilder sb = (StAXBuilder)msgToInvoke.getEnvelope().getBuilder();
            if(sb!=null){
              sb.close();
            }
          }
        }

        if (transaction != null && transaction.isActive()) {
View Full Code Here

    public void testCode() {
        try {
            String filename = "test-resources/soap/wrongEnvelopeNamespace.xml";
            XMLStreamReader xmlr = XMLInputFactory.newInstance()
                    .createXMLStreamReader(new FileInputStream(filename));
            StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null); //exception here
            fail("Builder must fail here due to wrong SOAP namespace");
        } catch (SOAPProcessingException e) {
            assertTrue(true);
        } catch (FileNotFoundException e) {
            fail("Only SOAPProcessingException can be thrown here");
View Full Code Here

            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(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                    soapVersion = VERSION_SOAP12;
                } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                    soapVersion = VERSION_SOAP11;
                }
                if (JavaUtils.indexOfIgnoreCase(contentType, HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
                    // It is MIME (MTOM or SwA)
                    builder = TransportUtils.selectBuilderForMIME(msgContext, in, contentType,true);
                    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 = StAXUtils.createXMLStreamReader(in,
                                                                    MessageContext.DEFAULT_CHAR_SET_ENCODING);

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

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

                        xmlreader = StAXUtils.createXMLStreamReader(in,
                                                                    charSetEnc);

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

                    if (soapVersion == VERSION_SOAP12) {
                        //Check for action header and set it in as soapAction in MessageContext
                        int index = contentType.indexOf("action");
                        if (index > -1) {
                            String transientString = contentType.substring(index, contentType.length());
                            int equal = transientString.indexOf("=");
                            int firstSemiColon = transientString.indexOf(";");
                            String soapAction; // This will contain "" in the string
                            if (firstSemiColon > -1) {
                                soapAction = transientString.substring(equal + 1, firstSemiColon);
                            } else {
                                soapAction = transientString.substring(equal + 1, transientString.length());
                            }
                            if ((soapAction != null) && soapAction.startsWith("\"")
                                && soapAction.endsWith("\"")) {
                                soapAction = soapAction
                                        .substring(1, soapAction.length() - 1);
                            }
                            msgContext.setSoapAction(soapAction);

                        }

                        // it is SOAP 1.2
                        builder =
                                new StAXSOAPModelBuilder(xmlreader,
                                                         SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                        envelope = (SOAPEnvelope) builder.getDocumentElement();
                    } else if (soapVersion == VERSION_SOAP11) {
                        /**
                         * Configuration via Deployment
                         */
                        Parameter enable =
                                msgContext.getParameter(Constants.Configuration.ENABLE_REST);

                        if ((soapActionHeader == null) && (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();
                        }
                    }
                }
            }

            if (builder == null) {
                XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in,
                                                                            MessageContext.DEFAULT_CHAR_SET_ENCODING);

                // Set the encoding scheme in the message context
                msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                                       MessageContext.DEFAULT_CHAR_SET_ENCODING);
                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(
                    Constants.Configuration.CHARACTER_SET_ENCODING))) {
                String faultCode;
View Full Code Here

                contentType = opContext.getProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE);
            } else {
                throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
            }

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

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

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

            if (contentType != null) {
                msgContext.setDoingMTOM(true);
                builder = selectBuilderForMIME(msgContext, inStream,
                        (String) contentType,true);
                envelope = (SOAPEnvelope) builder.getDocumentElement();
            } else if (msgContext.isDoingREST()) {
                XMLStreamReader xmlreader =
                        StAXUtils.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 =
                        StAXUtils.createXMLStreamReader(inStream, charSetEnc);

                builder = new StAXSOAPModelBuilder(xmlreader, soapNamespaceURI);
                envelope = (SOAPEnvelope) builder.getDocumentElement();
            }

            return envelope;
        } catch (Exception e) {
            throw new AxisFault(e);
View Full Code Here

    }

  public static StAXBuilder selectBuilderForMIME(MessageContext msgContext,
      InputStream inStream, String contentTypeString, boolean isSOAP)
      throws OMException, XMLStreamException, FactoryConfigurationError {
    StAXBuilder builder = null;

    Object cacheAttachmentProperty = msgContext
        .getProperty(Constants.Configuration.CACHE_ATTACHMENTS);
    String cacheAttachmentString = null;
    boolean fileCacheForAttachments;
View Full Code Here

    public static SOAPEnvelope getSOAPEnvelope(
        Message message, MessageContext msgContext, InputStream in)
        throws XMLStreamException {

        SOAPEnvelope envelope = null;
        StAXBuilder builder = null;

        String contentType = JMSUtils.getProperty(message, JMSConstants.CONTENT_TYPE);

        if (contentType != null) {
            if (contentType.indexOf(
                HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
                // It is MTOM
                builder = TransportUtils.selectBuilderForMIME(
                    msgContext, in, contentType,true);
                envelope = (SOAPEnvelope) builder.getDocumentElement();

            } else {
                // Figure out the char set encoding and create the reader
                XMLStreamReader xmlreader;

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

                    // Set the encoding scheme in the message context
                    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                                           MessageContext.DEFAULT_CHAR_SET_ENCODING);

                } else {
                    // get the type of char encoding
                    String charSetEnc = TransportUtils.getCharSetEncoding(contentType);
                    xmlreader = StAXUtils.createXMLStreamReader(in, charSetEnc);

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

                if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                    // 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) {
                    // SOAP 1.1
                    builder =  new StAXSOAPModelBuilder(xmlreader,
                                                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                    envelope = (SOAPEnvelope) builder.getDocumentElement();
                }
            }
        }

        if (builder == null) {
            SOAPFactory soapFactory = new SOAP11Factory();
            try {
                XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader
                    (in, MessageContext.DEFAULT_CHAR_SET_ENCODING);

                // Set the encoding scheme in the message context
                msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                                       MessageContext.DEFAULT_CHAR_SET_ENCODING);
                builder = new StAXOMBuilder(xmlreader);
                builder.setOMBuilderFactory(soapFactory);

                String ns = builder.getDocumentElement().getNamespace().getNamespaceURI();
                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns)) {
                    envelope = getEnvelope(in, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns)) {
                    envelope = getEnvelope(in, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                } else {
                    // this is POX ... mark MC as REST
                    msgContext.setDoingREST(true);
                    envelope = soapFactory.getDefaultEnvelope();
                    envelope.getBody().addChild(builder.getDocumentElement());
                }
            } catch (Exception e) {
                log.debug("Non SOAP/XML JMS message received");

                Parameter operationParam = msgContext.getAxisService().
                    getParameter(JMSConstants.OPERATION_PARAM);
                QName operationQName = (operationParam != null ?
                    getQName(operationParam.getValue()) : JMSConstants.DEFAULT_OPERATION);

                AxisOperation operation = msgContext.getAxisService().getOperation(operationQName);
                if (operation != null) {
                    msgContext.setAxisOperation(operation);
                } else {
                    handleException("Cannot find operation : " + operationQName + " on the service "
                        + msgContext.getAxisService());
                }


                Parameter wrapperParam = msgContext.getAxisService().
                    getParameter(JMSConstants.WRAPPER_PARAM);
                QName wrapperQName = (wrapperParam != null ?
                    getQName(wrapperParam.getValue()) : JMSConstants.DEFAULT_WRAPPER);

                OMElement wrapper = soapFactory.createOMElement(wrapperQName, null);

                try {
                    if (message instanceof TextMessage) {
                        OMTextImpl textData = (OMTextImpl) soapFactory.createOMText(
                            ((TextMessage) message).getText());
                        wrapper.addChild(textData);
                    } else if (message instanceof BytesMessage) {
                        BytesMessage bm = (BytesMessage) message;
                        byte[] msgBytes = new byte[(int) bm.getBodyLength()];
                        bm.reset();
                        bm.readBytes(msgBytes);
                        DataHandler dataHandler = new DataHandler(
                            new ByteArrayDataSource(msgBytes));
                        OMText textData = soapFactory.createOMText(dataHandler, true);
                        wrapper.addChild(textData);
                        msgContext.setDoingMTOM(true);
                    } else {
                        handleException("Unsupported JMS Message format : " + message.getJMSType());
                    }
                    envelope = soapFactory.getDefaultEnvelope();
                    envelope.getBody().addChild(wrapper);

                } catch (JMSException j) {
                    handleException("Error wrapping JMS message into a SOAP envelope ", j);
                }
            }
        }

        String charEncOfMessage = builder == null ? null :
            builder.getDocument() == null ? null : builder.getDocument().getCharsetEncoding();
        String charEncOfTransport = ((String) msgContext.getProperty(
            Constants.Configuration.CHARACTER_SET_ENCODING));

        if (charEncOfMessage != null &&
            !(charEncOfMessage.trim().length() == 0) &&
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.impl.builder.StAXBuilder

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.