org.springframework.oxm.Marshaller Java Examples
The following examples show how to use
org.springframework.oxm.Marshaller.
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: MarshallingHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void writeWithMarshallingFailureException() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MarshallingFailureException ex = new MarshallingFailureException("forced"); Marshaller marshaller = mock(Marshaller.class); willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class)); try { MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); fail("HttpMessageNotWritableException should be thrown"); } catch (HttpMessageNotWritableException e) { assertTrue("Invalid exception hierarchy", e.getCause() == ex); } }
Example #2
Source File: MarshallingHttpMessageConverterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void writeWithMarshallingFailureException() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MarshallingFailureException ex = new MarshallingFailureException("forced"); Marshaller marshaller = mock(Marshaller.class); willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class)); try { MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); fail("HttpMessageNotWritableException should be thrown"); } catch (HttpMessageNotWritableException e) { assertTrue("Invalid exception hierarchy", e.getCause() == ex); } }
Example #3
Source File: MarshallingHttpMessageConverterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void writeWithMarshallingFailureException() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MarshallingFailureException ex = new MarshallingFailureException("forced"); Marshaller marshaller = mock(Marshaller.class); willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class)); try { MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); fail("HttpMessageNotWritableException should be thrown"); } catch (HttpMessageNotWritableException e) { assertTrue("Invalid exception hierarchy", e.getCause() == ex); } }
Example #4
Source File: MarshallingHttpMessageConverterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void readWithTypeMismatchException() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]); Marshaller marshaller = mock(Marshaller.class); Unmarshaller unmarshaller = mock(Unmarshaller.class); given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller); try { converter.read(String.class, inputMessage); fail("Should have thrown HttpMessageNotReadableException"); } catch (HttpMessageNotReadableException ex) { assertTrue(ex.getCause() instanceof TypeMismatchException); } }
Example #5
Source File: MarshallingHttpMessageConverterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void readWithTypeMismatchException() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]); Marshaller marshaller = mock(Marshaller.class); Unmarshaller unmarshaller = mock(Unmarshaller.class); given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller); try { converter.read(String.class, inputMessage); fail("Should have thrown HttpMessageNotReadableException"); } catch (HttpMessageNotReadableException ex) { assertTrue(ex.getCause() instanceof TypeMismatchException); } }
Example #6
Source File: MarshallingMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { marshallerMock = mock(Marshaller.class); unmarshallerMock = mock(Unmarshaller.class); sessionMock = mock(Session.class); converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock); }
Example #7
Source File: MarshallingHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void write() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Marshaller marshaller = mock(Marshaller.class); willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders() .getContentType()); }
Example #8
Source File: MarshallingHttpMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void canWrite() { Marshaller marshaller = mock(Marshaller.class); given(marshaller.supports(Integer.class)).willReturn(false); given(marshaller.supports(String.class)).willReturn(true); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(); converter.setMarshaller(marshaller); assertFalse(converter.canWrite(Boolean.class, MediaType.TEXT_PLAIN)); assertFalse(converter.canWrite(Integer.class, MediaType.TEXT_XML)); assertTrue(converter.canWrite(String.class, MediaType.TEXT_XML)); }
Example #9
Source File: MarshallingMessageConverter.java From spring-analysis-note with MIT License | 5 votes |
/** * Constructor with {@link Marshaller}. If the given {@link Marshaller} also * implements {@link Unmarshaller}, it is also used for unmarshalling. * <p>Note that all {@code Marshaller} implementations in Spring also implement * {@code Unmarshaller} so that you can safely use this constructor. * @param marshaller object used as marshaller and unmarshaller */ public MarshallingMessageConverter(Marshaller marshaller) { this(); Assert.notNull(marshaller, "Marshaller must not be null"); this.marshaller = marshaller; if (marshaller instanceof Unmarshaller) { this.unmarshaller = (Unmarshaller) marshaller; } }
Example #10
Source File: StandardXRoadConsumerCallback.java From j-road with Apache License 2.0 | 5 votes |
protected Marshaller getMarshaller() { XmlBeansMarshaller marshaller = new XmlBeansMarshaller(); marshaller.setXmlOptions(new XmlOptions().setSaveSyntheticDocumentElement(new QName(metadata.getRequestElementNs(), metadata.getRequestElementName(), StandardXRoadConsumer.ROOT_NS))); return marshaller; }
Example #11
Source File: MarshallingHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void canWrite() throws Exception { Marshaller marshaller = mock(Marshaller.class); given(marshaller.supports(Integer.class)).willReturn(false); given(marshaller.supports(String.class)).willReturn(true); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(); converter.setMarshaller(marshaller); assertFalse(converter.canWrite(Boolean.class, MediaType.TEXT_PLAIN)); assertFalse(converter.canWrite(Integer.class, MediaType.TEXT_XML)); assertTrue(converter.canWrite(String.class, MediaType.TEXT_XML)); }
Example #12
Source File: MarshallingHttpMessageConverter.java From spring-analysis-note with MIT License | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given * {@code Marshaller} and {@code Unmarshaller}. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #13
Source File: MarshallingMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the * given Marshaller and Unmarshaller. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #14
Source File: MarshallingSource.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new {@code MarshallingSource} with the given marshaller and content. * @param marshaller the marshaller to use * @param content the object to be marshalled */ public MarshallingSource(Marshaller marshaller, Object content) { super(new MarshallingXMLReader(marshaller, content), new InputSource()); Assert.notNull(marshaller, "'marshaller' must not be null"); Assert.notNull(content, "'content' must not be null"); this.marshaller = marshaller; this.content = content; }
Example #15
Source File: MarshallingHttpMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void write() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Marshaller marshaller = mock(Marshaller.class); willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType()); }
Example #16
Source File: MarshallingSource.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a new {@code MarshallingSource} with the given marshaller and content. * @param marshaller the marshaller to use * @param content the object to be marshalled */ public MarshallingSource(Marshaller marshaller, Object content) { super(new MarshallingXMLReader(marshaller, content), new InputSource()); Assert.notNull(marshaller, "'marshaller' must not be null"); Assert.notNull(content, "'content' must not be null"); this.marshaller = marshaller; this.content = content; }
Example #17
Source File: MarshallingMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given {@link Marshaller} set. * <p>If the given {@link Marshaller} also implements the {@link Unmarshaller} interface, * it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown. * <p>Note that all {@link Marshaller} implementations in Spring also implement the * {@link Unmarshaller} interface, so that you can safely use this constructor. * @param marshaller object used as marshaller and unmarshaller * @throws IllegalArgumentException when {@code marshaller} does not implement the * {@link Unmarshaller} interface as well */ public MarshallingMessageConverter(Marshaller marshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); if (!(marshaller instanceof Unmarshaller)) { throw new IllegalArgumentException( "Marshaller [" + marshaller + "] does not implement the Unmarshaller " + "interface. Please set an Unmarshaller explicitly by using the " + "MarshallingMessageConverter(Marshaller, Unmarshaller) constructor."); } else { this.marshaller = marshaller; this.unmarshaller = (Unmarshaller) marshaller; } }
Example #18
Source File: MarshallingMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { marshallerMock = mock(Marshaller.class); unmarshallerMock = mock(Unmarshaller.class); sessionMock = mock(Session.class); converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock); }
Example #19
Source File: MarshallingHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test(expected = TypeMismatchException.class) public void readWithTypeMismatchException() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]); Marshaller marshaller = mock(Marshaller.class); Unmarshaller unmarshaller = mock(Unmarshaller.class); given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller); converter.read(String.class, inputMessage); }
Example #20
Source File: MarshallingMessageConverter.java From java-technology-stack with MIT License | 5 votes |
/** * Constructor with {@link Marshaller}. If the given {@link Marshaller} also * implements {@link Unmarshaller}, it is also used for unmarshalling. * <p>Note that all {@code Marshaller} implementations in Spring also implement * {@code Unmarshaller} so that you can safely use this constructor. * @param marshaller object used as marshaller and unmarshaller */ public MarshallingMessageConverter(Marshaller marshaller) { this(); Assert.notNull(marshaller, "Marshaller must not be null"); this.marshaller = marshaller; if (marshaller instanceof Unmarshaller) { this.unmarshaller = (Unmarshaller) marshaller; } }
Example #21
Source File: MarshallingHttpMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given * {@code Marshaller} and {@code Unmarshaller}. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #22
Source File: MarshallingHttpMessageConverter.java From java-technology-stack with MIT License | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given * {@code Marshaller} and {@code Unmarshaller}. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #23
Source File: MarshallingHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void canWrite() { Marshaller marshaller = mock(Marshaller.class); given(marshaller.supports(Integer.class)).willReturn(false); given(marshaller.supports(String.class)).willReturn(true); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(); converter.setMarshaller(marshaller); assertFalse(converter.canWrite(Boolean.class, MediaType.TEXT_PLAIN)); assertFalse(converter.canWrite(Integer.class, MediaType.TEXT_XML)); assertTrue(converter.canWrite(String.class, MediaType.TEXT_XML)); }
Example #24
Source File: MarshallingHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void write() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Marshaller marshaller = mock(Marshaller.class); willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType()); }
Example #25
Source File: MarshallingSource.java From java-technology-stack with MIT License | 5 votes |
/** * Create a new {@code MarshallingSource} with the given marshaller and content. * @param marshaller the marshaller to use * @param content the object to be marshalled */ public MarshallingSource(Marshaller marshaller, Object content) { super(new MarshallingXMLReader(marshaller, content), new InputSource()); Assert.notNull(marshaller, "'marshaller' must not be null"); Assert.notNull(content, "'content' must not be null"); this.marshaller = marshaller; this.content = content; }
Example #26
Source File: MarshallingMessageConverter.java From java-technology-stack with MIT License | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given {@link Marshaller} set. * <p>If the given {@link Marshaller} also implements the {@link Unmarshaller} interface, * it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown. * <p>Note that all {@link Marshaller} implementations in Spring also implement the * {@link Unmarshaller} interface, so that you can safely use this constructor. * @param marshaller object used as marshaller and unmarshaller * @throws IllegalArgumentException when {@code marshaller} does not implement the * {@link Unmarshaller} interface as well */ public MarshallingMessageConverter(Marshaller marshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); if (!(marshaller instanceof Unmarshaller)) { throw new IllegalArgumentException( "Marshaller [" + marshaller + "] does not implement the Unmarshaller " + "interface. Please set an Unmarshaller explicitly by using the " + "MarshallingMessageConverter(Marshaller, Unmarshaller) constructor."); } else { this.marshaller = marshaller; this.unmarshaller = (Unmarshaller) marshaller; } }
Example #27
Source File: MarshallingMessageConverter.java From java-technology-stack with MIT License | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the * given Marshaller and Unmarshaller. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #28
Source File: MarshallingMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Constructor with {@link Marshaller}. If the given {@link Marshaller} also * implements {@link Unmarshaller}, it is also used for unmarshalling. * <p>Note that all {@code Marshaller} implementations in Spring also implement * {@code Unmarshaller} so that you can safely use this constructor. * @param marshaller object used as marshaller and unmarshaller */ public MarshallingMessageConverter(Marshaller marshaller) { this(); Assert.notNull(marshaller, "Marshaller must not be null"); this.marshaller = marshaller; if (marshaller instanceof Unmarshaller) { this.unmarshaller = (Unmarshaller) marshaller; } }
Example #29
Source File: MarshallingHttpMessageConverter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Construct a new {@code MarshallingMessageConverter} with the given * {@code Marshaller} and {@code Unmarshaller}. * @param marshaller the Marshaller to use * @param unmarshaller the Unmarshaller to use */ public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); Assert.notNull(unmarshaller, "Unmarshaller must not be null"); this.marshaller = marshaller; this.unmarshaller = unmarshaller; }
Example #30
Source File: MarshallingMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { marshallerMock = mock(Marshaller.class); unmarshallerMock = mock(Unmarshaller.class); sessionMock = mock(Session.class); converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock); }