Search in sources :

Example 11 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_Exception.

public void test_ConstructorLjava_lang_Exception() {
    Exception e = new Exception();
    // case 1: Try to create FactoryConfigurationError
    // which is based on Exception without parameters.
    FactoryConfigurationError fce = new FactoryConfigurationError(e);
    assertNotNull(fce.getMessage());
    assertNotNull(fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
    // case 2: Try to create FactoryConfigurationError
    // which is based on Exception with String parameter.
    e = new Exception("test message");
    fce = new FactoryConfigurationError(e);
    assertEquals(e.toString(), fce.getMessage());
    assertEquals(e.toString(), fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 12 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class FactoryConfigurationErrorTest method test_getException.

public void test_getException() {
    FactoryConfigurationError fce = new FactoryConfigurationError();
    assertNull(fce.getException());
    fce = new FactoryConfigurationError("test");
    assertNull(fce.getException());
    Exception e = new Exception("msg");
    fce = new FactoryConfigurationError(e);
    assertEquals(e, fce.getException());
    NullPointerException npe = new NullPointerException();
    fce = new FactoryConfigurationError(npe);
    assertEquals(npe, fce.getException());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 13 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project JMRI by JMRI.

the class XMLUtil method createXMLReader.

/**
     * Creates a SAX parser.
     *
     * <p>
     * See {@link #parse} for hints on setting an entity resolver.
     *
     * @param validate       if true, a validating parser is returned
     * @param namespaceAware if true, a namespace aware parser is returned
     *
     * @throws FactoryConfigurationError Application developers should never
     *                                   need to directly catch errors of this
     *                                   type.
     * @throws SAXException              if a parser fulfilling given parameters
     *                                   can not be created
     *
     * @return XMLReader configured according to passed parameters
     */
public static synchronized XMLReader createXMLReader(boolean validate, boolean namespaceAware) throws SAXException {
    SAXParserFactory factory = saxes[validate ? 0 : 1][namespaceAware ? 0 : 1];
    if (factory == null) {
        try {
            factory = SAXParserFactory.newInstance();
        } catch (FactoryConfigurationError err) {
            throw err;
        }
        factory.setValidating(validate);
        factory.setNamespaceAware(namespaceAware);
        saxes[validate ? 0 : 1][namespaceAware ? 0 : 1] = factory;
    }
    try {
        return factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
        // NOI18N
        throw new SAXException("Cannot create parser satisfying configuration parameters", ex);
    }
}
Also used : ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 14 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project kernel by exoplatform.

the class ConfigurationUnmarshaller method unmarshall.

public Configuration unmarshall(final URL url) throws Exception {
    if (PropertyManager.isDevelopping()) {
        boolean valid = isValid(url);
        if (!valid) {
            LOG.info("The configuration file " + url + " was not found valid according to its XSD");
        }
    }
    // 
    DocumentBuilderFactory factory = null;
    try {
        // With Java 6, it's safer to precise the builder factory class name as it may result:
        // java.lang.AbstractMethodError: org.apache.xerces.dom.DeferredDocumentImpl.getXmlStandalone()Z
        // at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(Unknown Source)
        Method dbfniMethod = DocumentBuilderFactory.class.getMethod("newInstance", String.class, ClassLoader.class);
        factory = (DocumentBuilderFactory) dbfniMethod.invoke(null, "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", Thread.currentThread().getContextClassLoader());
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FactoryConfigurationError) {
            // do nothing and let try to instantiate later
            LOG.debug("Was not able to find document builder factory class in Java > 5, will use default", cause);
        } else {
            // Rethrow
            throw e;
        }
    } catch (NoSuchMethodException e) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("An exception occurred: " + e.getMessage());
        }
    }
    // 
    if (factory == null) {
        factory = DocumentBuilderFactory.newInstance();
    }
    // 
    factory.setNamespaceAware(true);
    final DocumentBuilderFactory builderFactory = factory;
    try {
        return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Configuration>() {

            public Configuration run() throws Exception {
                DocumentBuilder builder = builderFactory.newDocumentBuilder();
                Document doc = builder.parse(url.openStream());
                // Filter DOM
                ProfileDOMFilter filter = new ProfileDOMFilter(profiles);
                filter.process(doc.getDocumentElement());
                // SAX event stream -> String
                StringWriter buffer = new StringWriter();
                SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
                TransformerHandler hd = tf.newTransformerHandler();
                StreamResult result = new StreamResult(buffer);
                hd.setResult(result);
                Transformer serializer = tf.newTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "UTF8");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                // Transform -> SAX event stream
                SAXResult saxResult = new SAXResult(new NoKernelNamespaceSAXFilter(hd));
                // DOM -> Transform
                serializer.transform(new DOMSource(doc), saxResult);
                // Reuse the parsed document
                String document = buffer.toString();
                // Debug
                if (LOG.isTraceEnabled())
                    LOG.trace("About to parse configuration file " + document);
                // 
                IBindingFactory bfact = BindingDirectory.getFactory(Configuration.class);
                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
                return (Configuration) uctx.unmarshalDocument(new StringReader(document), null);
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause instanceof JiBXException) {
            throw (JiBXException) cause;
        } else if (cause instanceof ParserConfigurationException) {
            throw (ParserConfigurationException) cause;
        } else if (cause instanceof IOException) {
            throw (IOException) cause;
        } else if (cause instanceof SAXException) {
            throw (SAXException) cause;
        } else if (cause instanceof IllegalArgumentException) {
            throw (IllegalArgumentException) cause;
        } else if (cause instanceof TransformerException) {
            throw (TransformerException) cause;
        } else if (cause instanceof TransformerConfigurationException) {
            throw (TransformerConfigurationException) cause;
        } else if (cause instanceof TransformerFactoryConfigurationError) {
            throw (TransformerFactoryConfigurationError) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(cause);
        }
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) Configuration(org.exoplatform.container.xml.Configuration) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IBindingFactory(org.jibx.runtime.IBindingFactory) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) TransformerException(javax.xml.transform.TransformerException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) StreamResult(javax.xml.transform.stream.StreamResult) PrivilegedActionException(java.security.PrivilegedActionException) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) JiBXException(org.jibx.runtime.JiBXException) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TransformerException(javax.xml.transform.TransformerException) JiBXException(org.jibx.runtime.JiBXException) PrivilegedActionException(java.security.PrivilegedActionException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) SAXResult(javax.xml.transform.sax.SAXResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 15 with FactoryConfigurationError

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

the class XMPPPacketListener method createSOAPEnvelopeForRawMessage.

/**
 * Creates a SOAP envelope using details found in chat message.
 * @param msgCtx
 * @param chatMessage
 * @return
 */
private SOAPEnvelope createSOAPEnvelopeForRawMessage(MessageContext msgCtx, String chatMessage) throws AxisFault {
    // TODO : need to add error handling logic
    String callRemoved = chatMessage.replaceFirst("call", "");
    // extract Service name
    String serviceName = callRemoved.trim().substring(0, callRemoved.indexOf(":") - 1);
    String operationName = callRemoved.trim().substring(callRemoved.indexOf(":"), callRemoved.indexOf("(") - 1);
    // Extract parameters from IM message
    String parameterList = callRemoved.trim().substring(callRemoved.indexOf("("), callRemoved.trim().length() - 1);
    StringTokenizer st = new StringTokenizer(parameterList, ",");
    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        String name = token.substring(0, token.indexOf("="));
        String value = token.substring(token.indexOf("=") + 1);
        parameterMap.put(name, value);
    }
    SOAPEnvelope envelope = null;
    try {
        msgCtx.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
        if (serviceName != null && serviceName.trim().length() > 0) {
            AxisService axisService = msgCtx.getConfigurationContext().getAxisConfiguration().getService(serviceName);
            msgCtx.setAxisService(axisService);
            AxisOperation axisOperation = axisService.getOperationBySOAPAction("urn:" + operationName);
            if (axisOperation != null) {
                msgCtx.setAxisOperation(axisOperation);
            }
        }
        if (operationName != null && operationName.trim().length() > 0) {
            msgCtx.setSoapAction("urn:" + operationName);
        }
        XMPPOutTransportInfo xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
        // This should be only set for messages received via chat.
        // TODO : need to read from a constant
        xmppOutTransportInfo.setContentType("xmpp/text");
        msgCtx.setServerSide(true);
        // TODO : need to support SOAP12 as well
        SOAPFactory soapFactory = new SOAP11Factory();
        envelope = BuilderUtil.buildsoapMessage(msgCtx, parameterMap, soapFactory);
    // TODO : improve error handling & messages
    } catch (AxisFault e) {
        throw new AxisFault(e.getMessage());
    } catch (OMException e) {
        throw new AxisFault(e.getMessage());
    } catch (FactoryConfigurationError e) {
        throw new AxisFault(e.getMessage());
    }
    return envelope;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) StringTokenizer(java.util.StringTokenizer) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) OMException(org.apache.axiom.om.OMException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

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