|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -17,6 +17,7 @@ |
|
|
|
package org.springframework.http.converter.xml; |
|
|
|
package org.springframework.http.converter.xml; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.StringReader; |
|
|
|
import java.io.StringReader; |
|
|
|
|
|
|
|
import java.nio.charset.Charset; |
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException; |
|
|
|
import javax.xml.parsers.ParserConfigurationException; |
|
|
|
import javax.xml.parsers.SAXParser; |
|
|
|
import javax.xml.parsers.SAXParser; |
|
|
|
@ -134,7 +135,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception { |
|
|
|
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception { |
|
|
|
try { |
|
|
|
try { |
|
|
|
source = processSource(source); |
|
|
|
source = processSource(source, detectCharset(headers)); |
|
|
|
Unmarshaller unmarshaller = createUnmarshaller(clazz); |
|
|
|
Unmarshaller unmarshaller = createUnmarshaller(clazz); |
|
|
|
if (clazz.isAnnotationPresent(XmlRootElement.class)) { |
|
|
|
if (clazz.isAnnotationPresent(XmlRootElement.class)) { |
|
|
|
return unmarshaller.unmarshal(source); |
|
|
|
return unmarshaller.unmarshal(source); |
|
|
|
@ -159,9 +160,12 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Source processSource(Source source) { |
|
|
|
protected Source processSource(Source source, @Nullable Charset charset) { |
|
|
|
if (source instanceof StreamSource streamSource) { |
|
|
|
if (source instanceof StreamSource streamSource) { |
|
|
|
InputSource inputSource = new InputSource(streamSource.getInputStream()); |
|
|
|
InputSource inputSource = new InputSource(streamSource.getInputStream()); |
|
|
|
|
|
|
|
if (charset != null) { |
|
|
|
|
|
|
|
inputSource.setEncoding(charset.name()); |
|
|
|
|
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
// By default, Spring will prevent the processing of external entities.
|
|
|
|
// By default, Spring will prevent the processing of external entities.
|
|
|
|
// This is a mitigation against XXE attacks.
|
|
|
|
// This is a mitigation against XXE attacks.
|
|
|
|
|