Search in sources :

Example 6 with BeanInvocation

use of org.apache.camel.component.bean.BeanInvocation 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 7 with BeanInvocation

use of org.apache.camel.component.bean.BeanInvocation in project camel by apache.

the class MultiPartCxfServerTest method testSendRequestWithInAndInOutParts.

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

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("saveCustomer", SaveCustomer.class, Product.class, Holder.class));
            Customer customer = new Customer();
            customer.setName("TestCustomer");
            customer.setRevenue(50000);
            SaveCustomer saveCustomer = new SaveCustomer();
            saveCustomer.setCustomer(customer);
            Product product = new Product();
            product.setName("Multiuse Product");
            product.setDescription("Useful for lots of things.");
            Holder<Company> holder = new Holder<Company>();
            Object[] args = new Object[] { saveCustomer, product, holder };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    @SuppressWarnings("unchecked") List<Object> headers = (List<Object>) exchange.getOut().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
    assertTrue(headers.size() == 1);
    Object companyHeaderObj = headers.get(0);
    assertTrue(companyHeaderObj instanceof Company);
    assertTrue(((Company) companyHeaderObj).getName().equals("MultipartSoft"));
}
Also used : Company(com.example.customerservice.multipart.Company) Processor(org.apache.camel.Processor) Customer(com.example.customerservice.multipart.Customer) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Holder(javax.xml.ws.Holder) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Product(com.example.customerservice.multipart.Product) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Exchange(org.apache.camel.Exchange) List(java.util.List) Test(org.junit.Test)

Example 8 with BeanInvocation

use of org.apache.camel.component.bean.BeanInvocation in project camel by apache.

the class MultiPartCxfServerTest method testSendRequestWithReusedInAndInOutParts.

/**
     * This test validates the end-to-end behavior of the service interface mapping when a parameter type
     * is defined with a different QName in two different Web method. It also tests the case where a 
     * QName and type are directly reused across methods.
     */
@Test
public void testSendRequestWithReusedInAndInOutParts() throws Exception {
    Exchange exchange = producerTemplate.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("saveCustomerToo", SaveCustomer.class, Product.class, Holder.class));
            Customer customer = new Customer();
            customer.setName("TestCustomerToo");
            customer.setRevenue(50000);
            SaveCustomer saveCustomer = new SaveCustomer();
            saveCustomer.setCustomer(customer);
            Product product = new Product();
            product.setName("Multiuse Product");
            product.setDescription("Useful for lots of things.");
            Holder<Company> holder = new Holder<Company>();
            Object[] args = new Object[] { saveCustomer, product, holder };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    @SuppressWarnings("unchecked") List<Object> headers = (List<Object>) exchange.getOut().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
    assertTrue(headers.size() == 1);
    Object companyHeaderObj = headers.get(0);
    assertTrue(companyHeaderObj instanceof Company);
    assertTrue(((Company) companyHeaderObj).getName().equals("MultipartSoft"));
}
Also used : Company(com.example.customerservice.multipart.Company) Processor(org.apache.camel.Processor) Customer(com.example.customerservice.multipart.Customer) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Holder(javax.xml.ws.Holder) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Product(com.example.customerservice.multipart.Product) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Exchange(org.apache.camel.Exchange) List(java.util.List) Test(org.junit.Test)

Example 9 with BeanInvocation

use of org.apache.camel.component.bean.BeanInvocation 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

BeanInvocation (org.apache.camel.component.bean.BeanInvocation)9 Exchange (org.apache.camel.Exchange)5 Product (com.example.customerservice.multipart.Product)4 Processor (org.apache.camel.Processor)4 Test (org.junit.Test)4 Company (com.example.customerservice.multipart.Company)2 Customer (com.example.customerservice.multipart.Customer)2 GetCustomersByName (com.example.customerservice.multipart.GetCustomersByName)2 SaveCustomer (com.example.customerservice.multipart.SaveCustomer)2 List (java.util.List)2 Holder (javax.xml.ws.Holder)2 GetCustomersByNameResponse (com.example.customerservice.multipart.GetCustomersByNameResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Annotation (java.lang.annotation.Annotation)1 RemoteException (java.rmi.RemoteException)1 UID (java.rmi.server.UID)1