use of javax.xml.parsers.SAXParserFactory in project feign by OpenFeign.
the class JAXBDecoder method decode.
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404)
return Util.emptyValueOf(type);
if (response.body() == null)
return null;
if (!(type instanceof Class)) {
throw new UnsupportedOperationException("JAXB only supports decoding raw types. Found " + type);
}
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
/* Explicitly control sax configuration to prevent XXE attacks */
saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParserFactory.setNamespaceAware(namespaceAware);
Source source = new SAXSource(saxParserFactory.newSAXParser().getXMLReader(), new InputSource(response.body().asInputStream()));
Unmarshaller unmarshaller = jaxbContextFactory.createUnmarshaller((Class) type);
return unmarshaller.unmarshal(source);
} catch (JAXBException e) {
throw new DecodeException(e.toString(), e);
} catch (ParserConfigurationException e) {
throw new DecodeException(e.toString(), e);
} catch (SAXException e) {
throw new DecodeException(e.toString(), e);
} finally {
if (response.body() != null) {
response.body().close();
}
}
}
use of javax.xml.parsers.SAXParserFactory in project OpenGrok by OpenGrok.
the class SubversionHistoryParser method initSaxParser.
/**
* Initialize the SAX parser instance.
* @throws HistoryException
*/
private void initSaxParser() throws HistoryException {
SAXParserFactory factory = SAXParserFactory.newInstance();
saxParser = null;
try {
saxParser = factory.newSAXParser();
} catch (Exception ex) {
throw new HistoryException("Failed to create SAX parser", ex);
}
}
use of javax.xml.parsers.SAXParserFactory in project Openfire by igniterealtime.
the class SimplePresence method parse.
// public Presence convertSIPPresenceToXMPP(String sipPresence) {
// Presence xmppPresence = new Presence();
//
// SAXParser saxParser;
// try {
// SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
// saxParser = saxParserFactory.newSAXParser();
//
// } catch (Exception e) {
// Log.debug("Unable to load parser to parse SIP presence to XMPP Presence.", e);
// return xmppPresence;
// }
//
// return xmppPresence;
// }
// public String convertXMPPPresenceToSIP(Presence xmppPresence) {
// String sipPresence = "";
// String basic = "open";
// String rpid = "unknown";
// String dmNote = "";
//
// if (!xmppPresence.isAvailable()) {
// // Prepare "closed" basic presence.
// basic = "closed";
// } else {
// Presence.Show xmppPresenceShow = xmppPresence.getShow();
// if (xmppPresenceShow.equals(Presence.Show.away)) {
// rpid = "away";
// } else if (xmppPresenceShow.equals(Presence.Show.chat)) {
// rpid = "away";
// } else if (xmppPresenceShow.equals(Presence.Show.dnd)) {
// rpid = "busy";
// } else if (xmppPresenceShow.equals(Presence.Show.xa)) {
// rpid = "away";
// } else {
// rpid = "";
// }
// }
//
// sipPresence = "<?xml version='1.0' encoding='UTF-8'?>"
// + "<presence xmlns='urn:ietf:params:xml:ns:pidf' xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' "
// + "xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' "
// + "entity='pres:sip:sipdemo1@192.168.1.199'>"
// + "<tuple><status><basic>" + basic + "</basic></status></tuple>"
// + "<dm:person id='p3e32d940'><rpid:activities><rpid:" + rpid + "/></rpid:activities></dm:person></presence>";
//
// return sipPresence;
// }
public void parse(String simplePresenceXml) throws Exception {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
ByteArrayInputStream bais = new ByteArrayInputStream(simplePresenceXml.getBytes());
saxParser.parse(bais, new SimplePresenceParser());
bais.close();
}
use of javax.xml.parsers.SAXParserFactory in project jmonkeyengine by jMonkeyEngine.
the class SceneMaterialLoader method load.
public MaterialList load(AssetManager assetManager, String folderName, InputStream in) throws IOException {
try {
this.assetManager = assetManager;
this.folderName = folderName;
reset();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = null;
try {
r = new InputStreamReader(in);
xr.parse(new InputSource(r));
} finally {
if (r != null) {
r.close();
}
}
return materialList;
} catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
} catch (ParserConfigurationException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
}
}
use of javax.xml.parsers.SAXParserFactory in project jersey by jersey.
the class JaxbStringReaderProviderTest method stringReaderDoesNotReadExternalDtds.
@Test
public void stringReaderDoesNotReadExternalDtds() {
Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {
final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));
@Override
public SAXParserFactory get() {
return spf.get();
}
};
JaxbStringReaderProvider.RootElementProvider provider = new JaxbStringReaderProvider.RootElementProvider(saxParserFactoryProvider, new Providers() {
@Override
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return null;
}
@Override
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return null;
}
@Override
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
return null;
}
@Override
public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
return null;
}
});
String content = "<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>";
provider.getConverter(RootObject.class, null, null).fromString(content);
}
Aggregations