Search in sources :

Example 16 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfRsConsumerSimpleBindingTest method createRouteBuilder.

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);
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MessageContentsList(org.apache.cxf.message.MessageContentsList) Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) InputStream(java.io.InputStream) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) List(java.util.List) CustomerList(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList) DataHandler(javax.activation.DataHandler) CustomerList(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList)

Example 17 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfEndpointBeansRouterTest method testCxfBusConfiguration.

@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
    ProducerTemplate template = camelContext.createProducerTemplate();
    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {

        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });
    Exception ex = reply.getException();
    assertTrue("Should get the fault here", ex instanceof org.apache.cxf.interceptor.Fault || ex instanceof HTTPException);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) HTTPException(org.apache.cxf.transport.http.HTTPException) ArrayList(java.util.ArrayList) List(java.util.List) HTTPException(org.apache.cxf.transport.http.HTTPException) Test(org.junit.Test)

Example 18 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfMtomDisabledProducerPayloadModeTest method testProducer.

@Override
public void testProducer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }
    Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            List<Source> elements = new ArrayList<Source>();
            elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.MTOM_DISABLED_REQ_MESSAGE)).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")));
        }
    });
    // process response - verify response attachments
    CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
    Assert.assertEquals(1, out.getBody().size());
    DataHandler dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_PHOTO_CID);
    Assert.assertEquals("application/octet-stream", dr.getContentType());
    MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
    dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_IMAGE_CID);
    Assert.assertEquals("image/jpeg", dr.getContentType());
    BufferedImage image = ImageIO.read(dr.getInputStream());
    Assert.assertEquals(560, image.getWidth());
    Assert.assertEquals(300, image.getHeight());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Processor(org.apache.camel.Processor) CxfPayload(org.apache.camel.component.cxf.CxfPayload) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) DOMSource(javax.xml.transform.dom.DOMSource) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) AttachmentDataSource(org.apache.cxf.attachment.AttachmentDataSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) BufferedImage(java.awt.image.BufferedImage) Exchange(org.apache.camel.Exchange) StringReader(java.io.StringReader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 19 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DisruptorConcurrentTest method testDisruptorConcurrentInOut.

@Test
public void testDisruptorConcurrentInOut() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(20);
    mock.allMessages().body().startsWith("Bye");
    // should at least take 3 sec
    mock.setMinimumResultWaitTime(3000);
    final ExecutorService executors = Executors.newFixedThreadPool(10);
    final List<Object> replies = new ArrayList<Object>(20);
    for (int i = 0; i < 20; i++) {
        final int num = i;
        final Object out = executors.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                return template.requestBody("disruptor:bar", "Message " + num);
            }
        });
        replies.add(out);
    }
    assertMockEndpointsSatisfied();
    assertEquals(20, replies.size());
    executors.shutdownNow();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 20 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DisruptorConcurrentTest method testDisruptorConcurrentInOutWithAsync.

@Test
public void testDisruptorConcurrentInOutWithAsync() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(20);
    mock.allMessages().body().startsWith("Bye");
    // should at least take 3 sec
    mock.setMinimumResultWaitTime(3000);
    // use our own template that has a higher thread pool than default camel that uses 5
    final ExecutorService executor = Executors.newFixedThreadPool(10);
    final ProducerTemplate pt = new DefaultProducerTemplate(context, executor);
    // must start the template
    pt.start();
    final List<Future<Object>> replies = new ArrayList<Future<Object>>(20);
    for (int i = 0; i < 20; i++) {
        final Future<Object> out = pt.asyncRequestBody("disruptor:bar", "Message " + i);
        replies.add(out);
    }
    assertMockEndpointsSatisfied();
    assertEquals(20, replies.size());
    for (int i = 0; i < 20; i++) {
        final String out = (String) replies.get(i).get();
        assertTrue(out.startsWith("Bye"));
    }
    pt.stop();
    executor.shutdownNow();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611