Search in sources :

Example 1 with GetCustomersByName

use of com.example.customerservice.multipart.GetCustomersByName in project camel by apache.

the class MultiPartClientMarshalTest method testSendPayload.

@Test
public void testSendPayload() throws Exception {
    Exchange exchange = template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            GetCustomersByName getCustomersByName = new GetCustomersByName();
            getCustomersByName.setName("Dr. Multipart");
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("getCustomersByName", GetCustomersByName.class, com.example.customerservice.multipart.Product.class));
            Product product = new Product();
            product.setName("Multiuse Product");
            product.setDescription("Useful for lots of things.");
            Object[] args = new Object[] { getCustomersByName, product };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    Map<String, String> nsMap = new HashMap<String, String>();
    nsMap.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
    nsMap.put("example", "http://multipart.customerservice.example.com/");
    XQueryBuilder builder = XQueryBuilder.xquery("//soap:Envelope/soap:Header/example:product/name");
    builder.setNamespaces(nsMap);
    String result = builder.evaluateAsString(exchange);
    assertTrue(result.equals("Multiuse Product"));
    builder = XQueryBuilder.xquery("//soap:Envelope/soap:Body/example:getCustomersByName/name");
    builder.setNamespaces(nsMap);
    result = builder.evaluateAsString(exchange);
    assertTrue(result.equals("Dr. Multipart"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) GetCustomersByName(com.example.customerservice.multipart.GetCustomersByName) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) XQueryBuilder(org.apache.camel.component.xquery.XQueryBuilder) Product(com.example.customerservice.multipart.Product) Test(org.junit.Test)

Example 2 with GetCustomersByName

use of com.example.customerservice.multipart.GetCustomersByName in project camel by apache.

the class MultiPartCxfServerTest method testSendRequestWithInPart.

@Test
public void testSendRequestWithInPart() throws Exception {
    Exchange exchange = producerTemplate.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            GetCustomersByName getCustomersByName = new GetCustomersByName();
            getCustomersByName.setName("Dr. Multipart");
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("getCustomersByName", GetCustomersByName.class, com.example.customerservice.multipart.Product.class));
            Product product = new Product();
            product.setName("Multipart Product");
            product.setDescription("Useful for lots of things.");
            Object[] args = new Object[] { getCustomersByName, product };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    Object responseObj = exchange.getOut().getBody();
    assertTrue(responseObj instanceof GetCustomersByNameResponse);
    GetCustomersByNameResponse response = (GetCustomersByNameResponse) responseObj;
    assertTrue(response.getReturn().get(0).getName().equals("Multipart Product"));
}
Also used : Exchange(org.apache.camel.Exchange) GetCustomersByNameResponse(com.example.customerservice.multipart.GetCustomersByNameResponse) Processor(org.apache.camel.Processor) GetCustomersByName(com.example.customerservice.multipart.GetCustomersByName) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Product(com.example.customerservice.multipart.Product) Test(org.junit.Test)

Aggregations

GetCustomersByName (com.example.customerservice.multipart.GetCustomersByName)2 Product (com.example.customerservice.multipart.Product)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 BeanInvocation (org.apache.camel.component.bean.BeanInvocation)2 Test (org.junit.Test)2 GetCustomersByNameResponse (com.example.customerservice.multipart.GetCustomersByNameResponse)1 HashMap (java.util.HashMap)1 XQueryBuilder (org.apache.camel.component.xquery.XQueryBuilder)1