@Override protected Properties useOverridePropertiesWithPropertiesComponent() { Properties extra = new Properties(); extra.put( "router.address", "http://localhost:" + CXFTestSupport.getPort1() + "/CxfEndpointBeansRouterTest/router"); extra.put( "service.address", "http://localhost:" + CXFTestSupport.getPort2() + "/CxfEndpointBeansRouterTest/service"); extra.put("test.address", "http://localhost:" + CXFTestSupport.getPort3() + "/testEndpoint"); return extra; }
@Test public void testCxfEndpointBeanDefinitionParser() { CxfEndpoint routerEndpoint = context.getEndpoint("routerEndpoint", CxfEndpoint.class); assertEquals( "Got the wrong endpoint address", routerEndpoint.getAddress(), "http://localhost:" + CXFTestSupport.getPort1() + "/CxfEndpointBeansRouterTest/router"); assertEquals( "Got the wrong endpont service class", "org.apache.camel.component.cxf.HelloService", routerEndpoint.getServiceClass().getName()); }
public class CxfRsConsumerWithBeanTest extends CamelTestSupport { private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConsumerWithBeanTest"; private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource"; private static final String CXF_RS_ENDPOINT_URI_2 = "cxfrs://http://localhost:" + CXT + "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource"; @Override protected Context createJndiContext() throws Exception { Context context = super.createJndiContext(); context.bind("service", new ServiceUtil()); return context; } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from(CXF_RS_ENDPOINT_URI).to("bean://service?multiParameterArray=true"); from(CXF_RS_ENDPOINT_URI_2).bean(ServiceUtil.class, "invoke", true); }; }; } @Test public void testPutConsumer() throws Exception { sendPutRequest("http://localhost:" + CXT + "/rest/customerservice/c20"); sendPutRequest("http://localhost:" + CXT + "/rest2/customerservice/c20"); } private void sendPutRequest(String uri) throws Exception { HttpPut put = new HttpPut(uri); StringEntity entity = new StringEntity("string"); entity.setContentType("text/plain"); put.setEntity(entity); CloseableHttpClient httpclient = HttpClientBuilder.create().build(); try { HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("c20string", EntityUtils.toString(response.getEntity())); } finally { httpclient.close(); } } }
public class CxfRsConvertBodyToTest extends CamelTestSupport { private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>123</id></Customer>"; private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConvertBodyToTest"; private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"; protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { Response ok = Response.ok().build(); from(CXF_RS_ENDPOINT_URI) // should be able to convert to Customer .convertBodyTo(Customer.class) .to("mock:result") // respond with OK .transform(constant(ok)); }; }; } @Test public void testPutConsumer() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); mock.message(0).body().isInstanceOf(Customer.class); HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers"); StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1"); entity.setContentType("text/xml; charset=ISO-8859-1"); put.addHeader("test", "header1;header2"); put.setEntity(entity); HttpClient httpclient = new DefaultHttpClient(); try { HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("", EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } } }
@Test public void testCxfBeanWithCamelPropertiesHolder() throws Exception { // get the camelContext from application context CxfEndpoint testEndpoint = context.getEndpoint("cxf:bean:testEndpoint", CxfEndpoint.class); QName endpointName = QName.valueOf("{http://org.apache.camel.component.cxf}myEndpoint"); QName serviceName = QName.valueOf("{http://org.apache.camel.component.cxf}myService"); assertEquals( "Got a wrong address", "http://localhost:" + CXFTestSupport.getPort3() + "/testEndpoint", testEndpoint.getAddress()); assertEquals( "Got a wrong bindingId", "http://schemas.xmlsoap.org/wsdl/soap12/", testEndpoint.getBindingId()); assertEquals( "Got a wrong transportId", "http://cxf.apache.org/transports/http", testEndpoint.getTransportId()); assertEquals("Got a wrong endpointName", endpointName, testEndpoint.getPortName()); assertEquals("Got a wrong WsdlURL", "wsdl/test.wsdl", testEndpoint.getWsdlURL()); assertEquals("Got a wrong serviceName", serviceName, testEndpoint.getServiceName()); }
/** * Unit test for exercising MTOM enabled end-to-end router in PAYLOAD mode * * @version */ @ContextConfiguration public class CxfMtomPOJOProducerTest extends AbstractJUnit4SpringContextTests { static int port = CXFTestSupport.getPort1(); @Autowired protected CamelContext context; private Endpoint endpoint; @Before public void setUp() throws Exception { endpoint = Endpoint.publish( "http://localhost:" + port + "/CxfMtomPOJOProducerTest/jaxws-mtom/hello", getImpl()); SOAPBinding binding = (SOAPBinding) endpoint.getBinding(); binding.setMTOMEnabled(true); } @After public void tearDown() throws Exception { if (endpoint != null) { endpoint.stop(); } } @SuppressWarnings("unchecked") @Test public void testInvokingServiceFromCxfProducer() throws Exception { if (MtomTestHelper.isAwtHeadless(logger, null)) { return; } final Holder<byte[]> photo = new Holder<byte[]>(MtomTestHelper.REQ_PHOTO_DATA); final Holder<Image> image = new Holder<Image>(getImage("/java.jpg")); Exchange exchange = context .createProducerTemplate() .send( "direct://testEndpoint", new Processor() { @Override public void process(Exchange exchange) throws Exception { exchange.getIn().setBody(new Object[] {photo, image}); } }); assertEquals("The attachement size should be 2 ", 2, exchange.getOut().getAttachments().size()); Object[] result = exchange.getOut().getBody(Object[].class); Holder<byte[]> photo1 = (Holder<byte[]>) result[1]; MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, photo1.value); Holder<Image> image1 = (Holder<Image>) result[2]; Assert.assertNotNull(image1.value); if (image.value instanceof BufferedImage) { Assert.assertEquals(560, ((BufferedImage) image1.value).getWidth()); Assert.assertEquals(300, ((BufferedImage) image1.value).getHeight()); } } private Image getImage(String name) throws Exception { return ImageIO.read(getClass().getResource(name)); } protected Object getImpl() { return new HelloImpl(); } }
public class CxfRsSslProducerTest extends CamelSpringTestSupport { private static int port1 = CXFTestSupport.getSslPort(); @Override public boolean isCreateCamelContextPerClass() { return true; } public int getPort1() { return port1; } @Override protected AbstractXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext( "org/apache/camel/component/cxf/jaxrs/CxfRsSpringSslProducer.xml"); } protected void setupDestinationURL(Message inMessage) { // do nothing here } @Test public void testCorrectTrustStore() { Exchange exchange = template.send("direct://trust", new MyProcessor()); // get the response message Customer response = (Customer) exchange.getOut().getBody(); assertNotNull("The response should not be null ", response); assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123"); assertEquals("Get a wrong customer name", response.getName(), "John"); assertEquals( "Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key")); } @Test public void testNoTrustStore() { Exchange exchange = template.send("direct://noTrust", new MyProcessor()); assertThat(exchange.isFailed(), is(true)); Exception e = exchange.getException(); assertThat( e.getCause().getClass().getCanonicalName(), is("javax.net.ssl.SSLHandshakeException")); } @Test public void testWrongTrustStore() { Exchange exchange = template.send("direct://wrongTrust", new MyProcessor()); assertThat(exchange.isFailed(), is(true)); Exception e = exchange.getException(); assertThat( e.getCause().getClass().getCanonicalName(), is("javax.net.ssl.SSLHandshakeException")); } private class MyProcessor implements Processor { @Override public void process(Exchange exchange) throws Exception { exchange.setPattern(ExchangePattern.InOut); Message inMessage = exchange.getIn(); setupDestinationURL(inMessage); // using the http central client API inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE); // set the Http method inMessage.setHeader(Exchange.HTTP_METHOD, "GET"); // set the relative path inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123"); // Specify the response class , cxfrs will use InputStream as the response object type inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class); // set a customer header inMessage.setHeader("key", "value"); // since we use the Get method, so we don't need to set the message body inMessage.setBody(null); } } }
/** Tests for the Simple Binding style of CXF JAX-RS consumers. */ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport { private static final String PORT_PATH = CXFTestSupport.getPort1() + "/CxfRsConsumerTest"; private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + PORT_PATH + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerServiceResource&bindingStyle=SimpleConsumer"; private JAXBContext jaxb; private CloseableHttpClient httpclient; public void setUp() throws Exception { super.setUp(); httpclient = HttpClientBuilder.create().build(); jaxb = JAXBContext.newInstance(CustomerList.class, Customer.class, Order.class, Product.class); } public void tearDown() throws Exception { super.tearDown(); httpclient.close(); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from(CXF_RS_ENDPOINT_URI).recipientList(simple("direct:${header.operationName}")); from("direct:getCustomer") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertNotNull(exchange.getIn().getHeader("id")); long id = exchange.getIn().getHeader("id", Long.class); if (id == 123) { assertEquals("123", exchange.getIn().getHeader("id")); assertEquals( MessageContentsList.class, exchange.getIn().getBody().getClass()); exchange.getOut().setBody(new Customer(123, "Raul")); exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200); } else if (id == 456) { exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404); } else { fail(); } } }); from("direct:updateCustomer") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("123", exchange.getIn().getHeader("id")); Customer c = exchange.getIn().getBody(Customer.class); assertEquals(123, c.getId()); assertNotNull(c); } }); from("direct:newCustomer") .process( new Processor() { public void process(Exchange exchange) throws Exception { Customer c = exchange.getIn().getBody(Customer.class); assertNotNull(c); assertEquals(123, c.getId()); } }); from("direct:listVipCustomers") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("gold", exchange.getIn().getHeader("status", String.class)); assertEquals(MessageContentsList.class, exchange.getIn().getBody().getClass()); assertEquals(0, exchange.getIn().getBody(MessageContentsList.class).size()); CustomerList response = new CustomerList(); List<Customer> list = new ArrayList<Customer>(2); list.add(new Customer(123, "Raul")); list.add(new Customer(456, "Raul2")); response.setCustomers(list); exchange.getOut().setBody(response); } }); from("direct:updateVipCustomer") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("gold", exchange.getIn().getHeader("status", String.class)); assertEquals("123", exchange.getIn().getHeader("id")); Customer c = exchange.getIn().getBody(Customer.class); assertEquals(123, c.getId()); assertNotNull(c); } }); from("direct:deleteVipCustomer") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("gold", exchange.getIn().getHeader("status", String.class)); assertEquals("123", exchange.getIn().getHeader("id")); } }); from("direct:uploadImageInputStream") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("123", exchange.getIn().getHeader("id")); assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type")); assertTrue( InputStream.class.isAssignableFrom(exchange.getIn().getBody().getClass())); InputStream is = exchange.getIn().getBody(InputStream.class); is.close(); exchange.getOut().setBody(null); } }); from("direct:uploadImageDataHandler") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("123", exchange.getIn().getHeader("id")); assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type")); assertTrue( DataHandler.class.isAssignableFrom(exchange.getIn().getBody().getClass())); DataHandler dh = exchange.getIn().getBody(DataHandler.class); assertEquals("image/jpeg", dh.getContentType()); dh.getInputStream().close(); exchange.getOut().setBody(null); } }); from("direct:multipartPostWithParametersAndPayload") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertEquals("abcd", exchange.getIn().getHeader("query")); assertEquals("123", exchange.getIn().getHeader("id")); assertNotNull(exchange.getIn().getAttachment("part1")); assertNotNull(exchange.getIn().getAttachment("part2")); assertNull(exchange.getIn().getHeader("part1")); assertNull(exchange.getIn().getHeader("part2")); assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass()); exchange.getOut().setBody(null); } }); from("direct:multipartPostWithoutParameters") .process( new Processor() { public void process(Exchange exchange) throws Exception { assertNotNull(exchange.getIn().getAttachment("part1")); assertNotNull(exchange.getIn().getAttachment("part2")); assertNull(exchange.getIn().getHeader("part1")); assertNull(exchange.getIn().getHeader("part2")); assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass()); exchange.getOut().setBody(null); } }); } }; } @Test public void testGetCustomerOnlyHeaders() throws Exception { HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123"); get.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent()); assertEquals(123, entity.getId()); } @Test public void testGetCustomerHttp404CustomStatus() throws Exception { HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/456"); get.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(get); assertEquals(404, response.getStatusLine().getStatusCode()); } @Test public void testUpdateCustomerBodyAndHeaders() throws Exception { HttpPut put = new HttpPut("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123"); StringWriter sw = new StringWriter(); jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw); put.setEntity(new StringEntity(sw.toString())); put.addHeader("Content-Type", "text/xml"); put.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testNewCustomerOnlyBody() throws Exception { HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers"); StringWriter sw = new StringWriter(); jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw); post.setEntity(new StringEntity(sw.toString())); post.addHeader("Content-Type", "text/xml"); post.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testListVipCustomers() throws Exception { HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold"); get.addHeader("Content-Type", "text/xml"); get.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); CustomerList cl = (CustomerList) jaxb.createUnmarshaller() .unmarshal(new StringReader(EntityUtils.toString(response.getEntity()))); List<Customer> vips = cl.getCustomers(); assertEquals(2, vips.size()); assertEquals(123, vips.get(0).getId()); assertEquals(456, vips.get(1).getId()); } @Test public void testUpdateVipCustomer() throws Exception { HttpPut put = new HttpPut( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123"); StringWriter sw = new StringWriter(); jaxb.createMarshaller().marshal(new Customer(123, "Raul2"), sw); put.setEntity(new StringEntity(sw.toString())); put.addHeader("Content-Type", "text/xml"); put.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testDeleteVipCustomer() throws Exception { HttpDelete delete = new HttpDelete( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123"); delete.addHeader("Accept", "text/xml"); HttpResponse response = httpclient.execute(delete); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testUploadInputStream() throws Exception { HttpPost post = new HttpPost( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_inputstream"); post.addHeader("Content-Type", "image/jpeg"); post.addHeader("Accept", "text/xml"); post.setEntity( new InputStreamEntity( this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100)); HttpResponse response = httpclient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testUploadDataHandler() throws Exception { HttpPost post = new HttpPost( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_datahandler"); post.addHeader("Content-Type", "image/jpeg"); post.addHeader("Accept", "text/xml"); post.setEntity( new InputStreamEntity( this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100)); HttpResponse response = httpclient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testMultipartPostWithParametersAndPayload() throws Exception { HttpPost post = new HttpPost( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/multipart/123?query=abcd"); MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.STRICT); builder.addBinaryBody( "part1", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg"); builder.addBinaryBody( "part2", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg"); StringWriter sw = new StringWriter(); jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw); builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8)); post.setEntity(builder.build()); HttpResponse response = httpclient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); } @Test public void testMultipartPostWithoutParameters() throws Exception { HttpPost post = new HttpPost( "http://localhost:" + PORT_PATH + "/rest/customerservice/customers/multipart/withoutParameters"); MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.STRICT); builder.addBinaryBody( "part1", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg"); builder.addBinaryBody( "part2", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg"); StringWriter sw = new StringWriter(); jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw); builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8)); post.setEntity(builder.build()); HttpResponse response = httpclient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); } }
/** * Unit test for exercising MTOM feature of a CxfConsumer in PAYLOAD mode * * @version */ @ContextConfiguration public class CxfMtomConsumerPayloadModeTest extends AbstractJUnit4SpringContextTests { static int port = CXFTestSupport.getPort1(); @Autowired protected CamelContext context; @Test public void testConsumer() throws Exception { if (MtomTestHelper.isAwtHeadless(logger, null)) { return; } context .createProducerTemplate() .send( "cxf:bean:consumerEndpoint", new Processor() { public void process(Exchange exchange) throws Exception { exchange.setPattern(ExchangePattern.InOut); assertEquals( "Get a wrong Content-Type header", "application/xop+xml", exchange.getIn().getHeader("Content-Type")); List<Source> elements = new ArrayList<Source>(); elements.add( new DOMSource( DOMUtils.readXml(new StringReader(getRequestMessage())) .getDocumentElement())); CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null); exchange.getIn().setBody(body); exchange .getIn() .addAttachment( MtomTestHelper.REQ_PHOTO_CID, new DataHandler( new ByteArrayDataSource( MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream"))); exchange .getIn() .addAttachment( MtomTestHelper.REQ_IMAGE_CID, new DataHandler( new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg"))); } }); } // START SNIPPET: consumer public static class MyProcessor implements Processor { @SuppressWarnings("unchecked") public void process(Exchange exchange) throws Exception { CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class); // verify request assertEquals(1, in.getBody().size()); Map<String, String> ns = new HashMap<String, String>(); ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS); ns.put("xop", MtomTestHelper.XOP_NS); XPathUtils xu = new XPathUtils(ns); Element body = new XmlConverter().toDOMElement(in.getBody().get(0)); Element ele = (Element) xu.getValue("//ns:Detail/ns:photo/xop:Include", body, XPathConstants.NODE); String photoId = ele.getAttribute("href").substring(4); // skip "cid:" assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId); ele = (Element) xu.getValue("//ns:Detail/ns:image/xop:Include", body, XPathConstants.NODE); String imageId = ele.getAttribute("href").substring(4); // skip "cid:" assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId); DataHandler dr = exchange.getIn().getAttachment(photoId); assertEquals("application/octet-stream", dr.getContentType()); MtomTestHelper.assertEquals( MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream())); dr = exchange.getIn().getAttachment(imageId); assertEquals("image/jpeg", dr.getContentType()); MtomTestHelper.assertEquals( MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream())); // create response List<Source> elements = new ArrayList<Source>(); elements.add( new DOMSource( DOMUtils.readXml(new StringReader(MtomTestHelper.RESP_MESSAGE)) .getDocumentElement())); CxfPayload<SoapHeader> sbody = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null); exchange.getOut().setBody(sbody); exchange .getOut() .addAttachment( MtomTestHelper.RESP_PHOTO_CID, new DataHandler( new ByteArrayDataSource( MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream"))); exchange .getOut() .addAttachment( MtomTestHelper.RESP_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg"))); } } // END SNIPPET: consumer protected String getRequestMessage() { return MtomTestHelper.REQ_MESSAGE; } }