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());
}
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());
}
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);
}
}
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);
}
}
}
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;
}
Aggregations