Search in sources :

Example 26 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project wso2-axis2-transports by wso2.

the class XMPPPacketListener method buildSOAPEnvelope.

/**
 * builds SOAP envelop using message contained in packet
 * @param packet
 * @param msgContext
 * @throws AxisFault
 */
private void buildSOAPEnvelope(Packet packet, MessageContext msgContext) throws AxisFault {
    Message message = (Message) packet;
    String logMsg = "Trying to create " + "message content using XMPP message received :" + packet.toXML();
    String messageBody = StringEscapeUtils.unescapeXml(message.getBody());
    if (msgContext.isServerSide()) {
        log.debug("Received Envelope : " + messageBody);
    }
    InputStream inputStream = new ByteArrayInputStream(messageBody.getBytes());
    SOAPEnvelope envelope = null;
    try {
        Object obj = message.getProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE);
        if (obj != null && ((Boolean) obj).booleanValue()) {
            String contentType = (String) message.getProperty(XMPPConstants.CONTENT_TYPE);
            if (contentType == null) {
                throw new AxisFault("Can not Find Content type Property in the XMPP Message");
            }
            envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, contentType);
            msgContext.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
        } else {
            // This message could either be a service call or a help command
            if (!(messageContainsCommandsFromChat(messageBody, msgContext))) {
                envelope = createSOAPEnvelopeForRawMessage(msgContext, messageBody);
            }
        }
        if (envelope != null) {
            msgContext.setEnvelope(envelope);
        }
    } catch (OMException e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (XMLStreamException e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (FactoryConfigurationError e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (AxisFault e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMException(org.apache.axiom.om.OMException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 27 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project drools by kiegroup.

the class ExtensibleXmlParser method read.

/**
 * Read a <code>RuleSet</code> from an <code>InputSource</code>.
 *
 * @param in
 *            The rule-set input-source.
 *
 * @return The rule-set.
 * @throws ParserConfigurationException
 */
public Object read(final InputSource in) throws SAXException, IOException {
    if (this.docFragment == null) {
        DocumentBuilderFactory f;
        try {
            f = DocumentBuilderFactory.newInstance();
        } catch (FactoryConfigurationError e) {
            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4633368
            try {
                f = (DocumentBuilderFactory) Class.forName("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl").newInstance();
            } catch (Exception e1) {
                throw new RuntimeException("Unable to create new DOM Document", e1);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to create new DOM Document", e);
        }
        // XXE protection start
        try {
            f.setFeature("http://xml.org/sax/features/external-general-entities", false);
            f.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        } catch (ParserConfigurationException e) {
            logger.warn("Unable to set parser features due to {}", e.getMessage());
        }
        // XXE protection end
        try {
            this.document = f.newDocumentBuilder().newDocument();
        } catch (Exception e) {
            throw new RuntimeException("Unable to create new DOM Document", e);
        }
        this.docFragment = this.document.createDocumentFragment();
    }
    SAXParser localParser = null;
    if (this.parser == null) {
        SAXParserFactory factory = null;
        try {
            factory = SAXParserFactory.newInstance();
        } catch (FactoryConfigurationError e) {
            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4633368
            try {
                factory = (SAXParserFactory) Class.forName("org.apache.xerces.jaxp.SAXParserFactoryImpl").newInstance();
            } catch (Exception e1) {
                throw new RuntimeException("Unable to create new DOM Document", e1);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to create new DOM Document", e);
        }
        factory.setNamespaceAware(true);
        // XXE protection start
        try {
            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        } catch (ParserConfigurationException e) {
            logger.warn("Unable to set parser features due to {}", e.getMessage());
        }
        if (System.getProperty("drools.schema.validating") != null) {
            this.isValidating = Boolean.getBoolean("drools.schema.validating");
        }
        if (this.isValidating == true) {
            factory.setValidating(true);
            try {
                localParser = factory.newSAXParser();
            } catch (final ParserConfigurationException e) {
                throw new RuntimeException(e.getMessage());
            }
            try {
                localParser.setProperty(ExtensibleXmlParser.JAXP_SCHEMA_LANGUAGE, ExtensibleXmlParser.W3C_XML_SCHEMA);
            } catch (final SAXNotRecognizedException e) {
                boolean hideWarnings = Boolean.getBoolean("drools.schema.hidewarnings");
                if (!hideWarnings) {
                    logger.warn("Your SAX parser is not JAXP 1.2 compliant - turning off validation.");
                }
                localParser = null;
            }
        }
        if (localParser == null) {
            // not jaxp1.2 compliant so turn off validation
            try {
                this.isValidating = false;
                factory.setValidating(this.isValidating);
                localParser = factory.newSAXParser();
            } catch (final ParserConfigurationException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    } else {
        localParser = this.parser;
    }
    if (!localParser.isNamespaceAware()) {
        throw new RuntimeException("parser must be namespace-aware");
    }
    localParser.parse(in, this);
    return this.data;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

FactoryConfigurationError (javax.xml.parsers.FactoryConfigurationError)27 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 SAXException (org.xml.sax.SAXException)10 IOException (java.io.IOException)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Document (org.w3c.dom.Document)4 SAXParseException (org.xml.sax.SAXParseException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Properties (java.util.Properties)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)3 StringReader (java.io.StringReader)2 Constructor (java.lang.reflect.Constructor)2 Hashtable (java.util.Hashtable)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 Element (org.w3c.dom.Element)2 InputSource (org.xml.sax.InputSource)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1