org.springframework.oxm.mime.MimeContainer Java Examples

The following examples show how to use org.springframework.oxm.mime.MimeContainer. 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: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void marshal(Object graph, Result result, @Nullable MimeContainer mimeContainer) throws XmlMappingException {
	try {
		Marshaller marshaller = createMarshaller();
		if (this.mtomEnabled && mimeContainer != null) {
			marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer));
		}
		if (StaxUtils.isStaxResult(result)) {
			marshalStaxResult(marshaller, graph, result);
		}
		else {
			marshaller.marshal(graph, result);
		}
	}
	catch (JAXBException ex) {
		throw convertJaxbException(ex);
	}
}
 
Example #2
Source File: Jaxb2MarshallerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	marshaller = new Jaxb2Marshaller();
	marshaller.setClassesToBeBound(BinaryObject.class);
	marshaller.setMtomEnabled(true);
	marshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.convertToXopPackage()).willReturn(true);
	byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream());
	BinaryObject object = new BinaryObject(bytes, dataHandler);
	StringWriter writer = new StringWriter();
	marshaller.marshal(object, new StreamResult(writer), mimeContainer);
	assertTrue("No XML written", writer.toString().length() > 0);
	verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class));
}
 
Example #3
Source File: Jaxb2UnmarshallerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	unmarshaller = new Jaxb2Marshaller();
	unmarshaller.setClassesToBeBound(BinaryObject.class);
	unmarshaller.setMtomEnabled(true);
	unmarshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.isXopPackage()).willReturn(true);
	given(mimeContainer.getAttachment("<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler);
	String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
			"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</bytes>" + "<dataHandler>" +
			"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</dataHandler>" +
			"<swaDataHandler>[email protected]</swaDataHandler>" +
			"</binaryObject>";

	StringReader reader = new StringReader(content);
	Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer);
	assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
	BinaryObject object = (BinaryObject) result;
	assertNotNull("bytes property not set", object.getBytes());
	assertTrue("bytes property not set", object.getBytes().length > 0);
	assertNotNull("datahandler property not set", object.getSwaDataHandler());
}
 
Example #4
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void marshal(Object graph, Result result, @Nullable MimeContainer mimeContainer) throws XmlMappingException {
	try {
		Marshaller marshaller = createMarshaller();
		if (this.mtomEnabled && mimeContainer != null) {
			marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer));
		}
		if (StaxUtils.isStaxResult(result)) {
			marshalStaxResult(marshaller, graph, result);
		}
		else {
			marshaller.marshal(graph, result);
		}
	}
	catch (JAXBException ex) {
		throw convertJaxbException(ex);
	}
}
 
Example #5
Source File: Jaxb2MarshallerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	marshaller = new Jaxb2Marshaller();
	marshaller.setClassesToBeBound(BinaryObject.class);
	marshaller.setMtomEnabled(true);
	marshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.convertToXopPackage()).willReturn(true);
	byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream());
	BinaryObject object = new BinaryObject(bytes, dataHandler);
	StringWriter writer = new StringWriter();
	marshaller.marshal(object, new StreamResult(writer), mimeContainer);
	assertTrue("No XML written", writer.toString().length() > 0);
	verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class));
}
 
Example #6
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void marshal(Object graph, Result result, MimeContainer mimeContainer) throws XmlMappingException {
	try {
		Marshaller marshaller = createMarshaller();
		if (this.mtomEnabled && mimeContainer != null) {
			marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer));
		}
		if (StaxUtils.isStaxResult(result)) {
			marshalStaxResult(marshaller, graph, result);
		}
		else {
			marshaller.marshal(graph, result);
		}
	}
	catch (JAXBException ex) {
		throw convertJaxbException(ex);
	}
}
 
Example #7
Source File: Jaxb2MarshallerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	marshaller = new Jaxb2Marshaller();
	marshaller.setClassesToBeBound(BinaryObject.class);
	marshaller.setMtomEnabled(true);
	marshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.convertToXopPackage()).willReturn(true);
	byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream());
	BinaryObject object = new BinaryObject(bytes, dataHandler);
	StringWriter writer = new StringWriter();
	marshaller.marshal(object, new StreamResult(writer), mimeContainer);
	assertTrue("No XML written", writer.toString().length() > 0);
	verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class));
}
 
Example #8
Source File: Jaxb2UnmarshallerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	unmarshaller = new Jaxb2Marshaller();
	unmarshaller.setClassesToBeBound(BinaryObject.class);
	unmarshaller.setMtomEnabled(true);
	unmarshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.isXopPackage()).willReturn(true);
	given(mimeContainer.getAttachment("<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler);
	String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
			"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</bytes>" + "<dataHandler>" +
			"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</dataHandler>" +
			"<swaDataHandler>[email protected]</swaDataHandler>" +
			"</binaryObject>";

	StringReader reader = new StringReader(content);
	Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer);
	assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
	BinaryObject object = (BinaryObject) result;
	assertNotNull("bytes property not set", object.getBytes());
	assertTrue("bytes property not set", object.getBytes().length > 0);
	assertNotNull("datahandler property not set", object.getSwaDataHandler());
}
 
Example #9
Source File: Jaxb2UnmarshallerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void marshalAttachments() throws Exception {
	unmarshaller = new Jaxb2Marshaller();
	unmarshaller.setClassesToBeBound(BinaryObject.class);
	unmarshaller.setMtomEnabled(true);
	unmarshaller.afterPropertiesSet();
	MimeContainer mimeContainer = mock(MimeContainer.class);

	Resource logo = new ClassPathResource("spring-ws.png", getClass());
	DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));

	given(mimeContainer.isXopPackage()).willReturn(true);
	given(mimeContainer.getAttachment("<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler);
	given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler);
	String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
			"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</bytes>" + "<dataHandler>" +
			"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
			"</dataHandler>" +
			"<swaDataHandler>[email protected]</swaDataHandler>" +
			"</binaryObject>";

	StringReader reader = new StringReader(content);
	Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer);
	assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
	BinaryObject object = (BinaryObject) result;
	assertNotNull("bytes property not set", object.getBytes());
	assertTrue("bytes property not set", object.getBytes().length > 0);
	assertNotNull("datahandler property not set", object.getSwaDataHandler());
}
 
Example #10
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public Jaxb2AttachmentMarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}
 
Example #11
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public Jaxb2AttachmentUnmarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}
 
Example #12
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 4 votes vote down vote up
public Jaxb2AttachmentMarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}
 
Example #13
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 4 votes vote down vote up
public Jaxb2AttachmentUnmarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}
 
Example #14
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public Jaxb2AttachmentMarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}
 
Example #15
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public Jaxb2AttachmentUnmarshaller(MimeContainer mimeContainer) {
	this.mimeContainer = mimeContainer;
}