Java Code Examples for javax.xml.stream.XMLInputFactory#setXMLResolver()

The following examples show how to use javax.xml.stream.XMLInputFactory#setXMLResolver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceHttpMessageConverter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Source readStAXSource(InputStream body, HttpInputMessage inputMessage) {
	try {
		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
		inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd());
		inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
		if (!isProcessExternalEntities()) {
			inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
		}
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
		return new StAXSource(streamReader);
	}
	catch (XMLStreamException ex) {
		throw new HttpMessageNotReadableException(
				"Could not parse document: " + ex.getMessage(), ex, inputMessage);
	}
}
 
Example 2
Source File: SourceHttpMessageConverter.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Source readStAXSource(InputStream body, HttpInputMessage inputMessage) {
	try {
		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
		inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd());
		inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
		if (!isProcessExternalEntities()) {
			inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
		}
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
		return new StAXSource(streamReader);
	}
	catch (XMLStreamException ex) {
		throw new HttpMessageNotReadableException(
				"Could not parse document: " + ex.getMessage(), ex, inputMessage);
	}
}
 
Example 3
Source File: Jackson2ObjectMapperBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static XMLInputFactory xmlInputFactory() {
	XMLInputFactory inputFactory = XMLInputFactory.newInstance();
	inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
	inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
	inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
	return inputFactory;
}
 
Example 4
Source File: Jaxb2CollectionHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a {@code XMLInputFactory} that this converter will use to create {@link
 * javax.xml.stream.XMLStreamReader} and {@link javax.xml.stream.XMLEventReader} objects.
 * <p>Can be overridden in subclasses, adding further initialization of the factory.
 * The resulting factory is cached, so this method will only be called once.
 */
protected XMLInputFactory createXmlInputFactory() {
	XMLInputFactory inputFactory = XMLInputFactory.newInstance();
	inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
	inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
	inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
	return inputFactory;
}
 
Example 5
Source File: SourceHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Source readStAXSource(InputStream body) {
	try {
		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
		inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd());
		inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
		if (!isProcessExternalEntities()) {
			inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
		}
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
		return new StAXSource(streamReader);
	}
	catch (XMLStreamException ex) {
		throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
	}
}
 
Example 6
Source File: Jackson2ObjectMapperBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public ObjectMapper create() {
	XMLInputFactory inputFactory = XMLInputFactory.newInstance();
	inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
	inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
	inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
	return new XmlMapper(inputFactory);
}
 
Example 7
Source File: Jaxb2CollectionHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@code XMLInputFactory} that this converter will use to create {@link
 * javax.xml.stream.XMLStreamReader} and {@link javax.xml.stream.XMLEventReader} objects.
 * <p>Can be overridden in subclasses, adding further initialization of the factory.
 * The resulting factory is cached, so this method will only be called once.
 */
protected XMLInputFactory createXmlInputFactory() {
	XMLInputFactory inputFactory = XMLInputFactory.newInstance();
	inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
	inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
	inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
	return inputFactory;
}
 
Example 8
Source File: SourceHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Source readStAXSource(InputStream body) {
	try {
		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
		inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd());
		inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
		if (!isProcessExternalEntities()) {
			inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
		}
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
		return new StAXSource(streamReader);
	}
	catch (XMLStreamException ex) {
		throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
	}
}
 
Example 9
Source File: EmptyEntityResolver.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Configures the given {@link XMLInputFactory} to not parse external entities.
 * No further configuration on is needed, all required entity resolvers are configured.
 */
public static void configureXMLInputFactory(XMLInputFactory inputFactory) {
  // don't enable validation of DTDs:
  trySetStAXProperty(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
  // enable this to *not* produce parsing failure on external entities:
  trySetStAXProperty(inputFactory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
  inputFactory.setXMLResolver(EmptyEntityResolver.STAX_INSTANCE);
}
 
Example 10
Source File: EmptyEntityResolver.java    From hadoop-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the given {@link XMLInputFactory} to not parse external entities.
 * No further configuration on is needed, all required entity resolvers are configured.
 */
public static void configureXMLInputFactory(XMLInputFactory inputFactory) {
  // don't enable validation of DTDs:
  trySetStAXProperty(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
  // enable this to *not* produce parsing failure on external entities:
  trySetStAXProperty(inputFactory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
  inputFactory.setXMLResolver(EmptyEntityResolver.STAX_INSTANCE);
}
 
Example 11
Source File: AbstractBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings( { "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
	XMLInputFactory staxFactory = XMLInputFactory.newInstance();
	staxFactory.setXMLResolver( xmlResourceResolver );
	return staxFactory;
}
 
Example 12
Source File: JaxbCfgProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings( { "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
	XMLInputFactory staxFactory = XMLInputFactory.newInstance();
	staxFactory.setXMLResolver( xmlResourceResolver );
	return staxFactory;
}