T
- the converted object typepublic class SourceHttpMessageConverter<T extends javax.xml.transform.Source> extends AbstractHttpMessageConverter<T>
HttpMessageConverter
that can read and write Source
objects.Modifier and Type | Class and Description |
---|---|
private static class |
SourceHttpMessageConverter.CountingOutputStream |
Modifier and Type | Field and Description |
---|---|
private static org.xml.sax.EntityResolver |
NO_OP_ENTITY_RESOLVER |
private static javax.xml.stream.XMLResolver |
NO_OP_XML_RESOLVER |
private boolean |
processExternalEntities |
private boolean |
supportDtd |
private static java.util.Set<java.lang.Class<?>> |
SUPPORTED_CLASSES |
private javax.xml.transform.TransformerFactory |
transformerFactory |
logger
Constructor and Description |
---|
SourceHttpMessageConverter()
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Long |
getContentLength(T t,
MediaType contentType)
Returns the content length for the given type.
|
boolean |
isProcessExternalEntities()
Returns the configured value for whether XML external entities are allowed.
|
boolean |
isSupportDtd()
Whether DTD parsing is supported.
|
private javax.xml.transform.dom.DOMSource |
readDOMSource(java.io.InputStream body,
HttpInputMessage inputMessage) |
protected T |
readInternal(java.lang.Class<? extends T> clazz,
HttpInputMessage inputMessage)
Abstract template method that reads the actual object.
|
private javax.xml.transform.sax.SAXSource |
readSAXSource(java.io.InputStream body,
HttpInputMessage inputMessage) |
private javax.xml.transform.Source |
readStAXSource(java.io.InputStream body,
HttpInputMessage inputMessage) |
private javax.xml.transform.stream.StreamSource |
readStreamSource(java.io.InputStream body) |
void |
setProcessExternalEntities(boolean processExternalEntities)
Indicates whether external XML entities are processed when converting to a Source.
|
void |
setSupportDtd(boolean supportDtd)
Indicates whether DTD parsing should be supported.
|
boolean |
supports(java.lang.Class<?> clazz)
Indicates whether the given class is supported by this converter.
|
private void |
transform(javax.xml.transform.Source source,
javax.xml.transform.Result result) |
protected void |
writeInternal(T t,
HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
|
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
private static final org.xml.sax.EntityResolver NO_OP_ENTITY_RESOLVER
private static final javax.xml.stream.XMLResolver NO_OP_XML_RESOLVER
private static final java.util.Set<java.lang.Class<?>> SUPPORTED_CLASSES
private final javax.xml.transform.TransformerFactory transformerFactory
private boolean supportDtd
private boolean processExternalEntities
public void setSupportDtd(boolean supportDtd)
Default is false
meaning that DTD is disabled.
public boolean isSupportDtd()
public void setProcessExternalEntities(boolean processExternalEntities)
Default is false
, meaning that external entities are not resolved.
Note: setting this option to true
also
automatically sets setSupportDtd(boolean)
to true
.
public boolean isProcessExternalEntities()
public boolean supports(java.lang.Class<?> clazz)
AbstractHttpMessageConverter
supports
in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
clazz
- the class to test for supporttrue
if supported; false
otherwiseprotected T readInternal(java.lang.Class<? extends T> clazz, HttpInputMessage inputMessage) throws java.io.IOException, HttpMessageNotReadableException
AbstractHttpMessageConverter
AbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)
.readInternal
in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
clazz
- the type of object to returninputMessage
- the HTTP input message to read fromjava.io.IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errorsprivate javax.xml.transform.dom.DOMSource readDOMSource(java.io.InputStream body, HttpInputMessage inputMessage) throws java.io.IOException
java.io.IOException
private javax.xml.transform.sax.SAXSource readSAXSource(java.io.InputStream body, HttpInputMessage inputMessage) throws java.io.IOException
java.io.IOException
private javax.xml.transform.Source readStAXSource(java.io.InputStream body, HttpInputMessage inputMessage)
private javax.xml.transform.stream.StreamSource readStreamSource(java.io.InputStream body) throws java.io.IOException
java.io.IOException
@Nullable protected java.lang.Long getContentLength(T t, @Nullable MediaType contentType)
AbstractHttpMessageConverter
By default, this returns null
, meaning that the content length is unknown.
Can be overridden in subclasses.
getContentLength
in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
t
- the type to return the content length fornull
if not knownprotected void writeInternal(T t, HttpOutputMessage outputMessage) throws java.io.IOException, HttpMessageNotWritableException
AbstractHttpMessageConverter
AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.writeInternal
in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
t
- the object to write to the output messageoutputMessage
- the HTTP output message to write tojava.io.IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errorsprivate void transform(javax.xml.transform.Source source, javax.xml.transform.Result result) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException