|
|
|
@ -20,7 +20,6 @@ import java.io.IOException; |
|
|
|
import javax.xml.transform.Result; |
|
|
|
import javax.xml.transform.Result; |
|
|
|
import javax.xml.transform.Source; |
|
|
|
import javax.xml.transform.Source; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.InitializingBean; |
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException; |
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException; |
|
|
|
import org.springframework.http.converter.HttpMessageNotWritableException; |
|
|
|
import org.springframework.http.converter.HttpMessageNotWritableException; |
|
|
|
@ -44,8 +43,7 @@ import org.springframework.util.Assert; |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @since 3.0 |
|
|
|
* @since 3.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object> |
|
|
|
public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object> { |
|
|
|
implements InitializingBean { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Marshaller marshaller; |
|
|
|
private Marshaller marshaller; |
|
|
|
|
|
|
|
|
|
|
|
@ -66,18 +64,11 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve |
|
|
|
* {@code Unmarshaller} interface, so that you can safely use this constructor. |
|
|
|
* {@code Unmarshaller} interface, so that you can safely use this constructor. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param marshaller object used as marshaller and unmarshaller |
|
|
|
* @param marshaller object used as marshaller and unmarshaller |
|
|
|
* @throws IllegalArgumentException when <code>marshaller</code> does not implement the {@link Unmarshaller} interface
|
|
|
|
|
|
|
|
* as well |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MarshallingHttpMessageConverter(Marshaller marshaller) { |
|
|
|
public MarshallingHttpMessageConverter(Marshaller marshaller) { |
|
|
|
Assert.notNull(marshaller, "marshaller must not be null"); |
|
|
|
Assert.notNull(marshaller, "marshaller must not be null"); |
|
|
|
if (!(marshaller instanceof Unmarshaller)) { |
|
|
|
this.marshaller = marshaller; |
|
|
|
throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " + |
|
|
|
if (marshaller instanceof Unmarshaller) { |
|
|
|
"interface. Please set an Unmarshaller explicitely by using the " + |
|
|
|
|
|
|
|
"MarshallingHttpMessageConverter(Marshaller, Unmarshaller) constructor."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.marshaller = marshaller; |
|
|
|
|
|
|
|
this.unmarshaller = (Unmarshaller) marshaller; |
|
|
|
this.unmarshaller = (Unmarshaller) marshaller; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -106,17 +97,13 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve |
|
|
|
this.unmarshaller = unmarshaller; |
|
|
|
this.unmarshaller = unmarshaller; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void afterPropertiesSet() { |
|
|
|
|
|
|
|
Assert.notNull(this.marshaller, "Property 'marshaller' is required"); |
|
|
|
|
|
|
|
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean supports(Class<?> clazz) { |
|
|
|
public boolean supports(Class<?> clazz) { |
|
|
|
return unmarshaller.supports(clazz); |
|
|
|
return unmarshaller.supports(clazz); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Object readFromSource(Class<Object> clazz, HttpHeaders headers, Source source) throws IOException { |
|
|
|
protected Object readFromSource(Class<Object> clazz, HttpHeaders headers, Source source) throws IOException { |
|
|
|
|
|
|
|
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return unmarshaller.unmarshal(source); |
|
|
|
return unmarshaller.unmarshal(source); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -127,6 +114,7 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException { |
|
|
|
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException { |
|
|
|
|
|
|
|
Assert.notNull(this.marshaller, "Property 'marshaller' is required"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
marshaller.marshal(o, result); |
|
|
|
marshaller.marshal(o, result); |
|
|
|
} |
|
|
|
} |
|
|
|
|