Search in sources :

Example 6 with DataType

use of org.apache.camel.spi.DataType in project camel by apache.

the class ManagedValidatorRegistry method listValidators.

@SuppressWarnings("unchecked")
public TabularData listValidators() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listValidatorsTabularType());
        Collection<Validator> validators = validatorRegistry.values();
        for (Validator validator : validators) {
            CompositeType ct = CamelOpenMBeanTypes.listValidatorsCompositeType();
            DataType type = validator.getType();
            String desc = validator.toString();
            boolean isStatic = validatorRegistry.isStatic(type);
            boolean isDynamic = validatorRegistry.isDynamic(type);
            CompositeData data = new CompositeDataSupport(ct, new String[] { "type", "static", "dynamic", "description" }, new Object[] { type.toString(), isStatic, isDynamic, desc });
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) DataType(org.apache.camel.spi.DataType) Validator(org.apache.camel.spi.Validator) TabularData(javax.management.openmbean.TabularData) CompositeType(javax.management.openmbean.CompositeType)

Example 7 with DataType

use of org.apache.camel.spi.DataType in project camel by apache.

the class OrderRouteSpringTest method testXML.

@Test
public void testXML() throws Exception {
    mockCsv.whenAnyExchangeReceived(new Processor() {

        public void process(Exchange exchange) {
            Object mockBody = exchange.getIn().getBody();
            assertEquals(Order.class, mockBody.getClass());
            Order mockOrder = (Order) mockBody;
            assertEquals("Order-XML-0001", mockOrder.getOrderId());
            assertEquals("MIKAN", mockOrder.getItemId());
            assertEquals(365, mockOrder.getQuantity());
        }
    });
    mockCsv.setExpectedMessageCount(1);
    String order = "<order orderId=\"Order-XML-0001\" itemId=\"MIKAN\" quantity=\"365\"/>";
    String expectedAnswer = "<orderResponse orderId=\"Order-XML-0001\" accepted=\"true\" description=\"Order accepted:[item='MIKAN' quantity='365']\"/>";
    Exchange answer = xmlProducer.send("direct:xml", ex -> {
        ((DataTypeAware) ex.getIn()).setBody(order, new DataType("xml:XMLOrder"));
    });
    XMLUnit.compareXML(expectedAnswer, answer.getOut().getBody(String.class));
    mockCsv.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Order(org.apache.camel.example.transformer.demo.Order) Processor(org.apache.camel.Processor) DataTypeAware(org.apache.camel.spi.DataTypeAware) DataType(org.apache.camel.spi.DataType) Test(org.junit.Test)

Example 8 with DataType

use of org.apache.camel.spi.DataType in project camel by apache.

the class CamelClient method main.

public static void main(final String[] args) throws Exception {
    File csvLogFile = new File(CSV_PATH);
    if (csvLogFile.exists()) {
        LOG.info("---> Removing log file '{}'...", csvLogFile.getAbsolutePath());
        csvLogFile.delete();
    }
    // START SNIPPET: e1
    LOG.info("---> Starting 'order' camel route...");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
    context.start();
    CamelContext camelContext = context.getBean("order", CamelContext.class);
    ProducerTemplate producer = camelContext.createProducerTemplate();
    // END SNIPPET: e1
    Thread.sleep(1000);
    Order order = new Order().setOrderId("Order-Java-0001").setItemId("MILK").setQuantity(3);
    LOG.info("---> Sending '{}' to 'direct:java'", order);
    OrderResponse response = producer.requestBody("direct:java", order, OrderResponse.class);
    Thread.sleep(1000);
    LOG.info("---> Received '{}'", response);
    LOG.info("---> CSV log now contains:{}", getCsvLog());
    Thread.sleep(1000);
    String orderXml = "<order orderId=\"Order-XML-0001\" itemId=\"MIKAN\" quantity=\"365\"/>";
    LOG.info("---> Sending '{}' to 'direct:xml'", orderXml);
    Exchange answerXml = producer.send("direct:xml", ex -> {
        ((DataTypeAware) ex.getIn()).setBody(orderXml, new DataType("xml:XMLOrder"));
    });
    Thread.sleep(1000);
    LOG.info("---> Received '{}'", answerXml.getOut().getBody(String.class));
    LOG.info("---> CSV log now contains:{}", getCsvLog());
    Thread.sleep(1000);
    String orderJson = "{\"orderId\":\"Order-JSON-0001\", \"itemId\":\"MIZUYO-KAN\", \"quantity\":\"16350\"}";
    LOG.info("---> Sending '{}' to 'direct:json'", orderJson);
    Exchange answerJson = producer.send("direct:json", ex -> {
        ((DataTypeAware) ex.getIn()).setBody(orderJson, new DataType("json"));
    });
    Thread.sleep(1000);
    LOG.info("---> Received '{}'", answerJson.getOut().getBody(String.class));
    LOG.info("---> CSV log now contains:{}", getCsvLog());
    Thread.sleep(1000);
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) Order(org.apache.camel.example.transformer.demo.Order) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DataTypeAware(org.apache.camel.spi.DataTypeAware) DataType(org.apache.camel.spi.DataType) OrderResponse(org.apache.camel.example.transformer.demo.OrderResponse) File(java.io.File)

Example 9 with DataType

use of org.apache.camel.spi.DataType in project camel by apache.

the class OrderRouteSpringTest method testJSON.

@Test
public void testJSON() throws Exception {
    mockCsv.whenAnyExchangeReceived(new Processor() {

        public void process(Exchange exchange) {
            Object mockBody = exchange.getIn().getBody();
            assertEquals(Order.class, mockBody.getClass());
            Order mockOrder = (Order) mockBody;
            assertEquals("Order-JSON-0001", mockOrder.getOrderId());
            assertEquals("MIZUYO-KAN", mockOrder.getItemId());
            assertEquals(16350, mockOrder.getQuantity());
        }
    });
    mockCsv.setExpectedMessageCount(1);
    String order = "{\"orderId\":\"Order-JSON-0001\", \"itemId\":\"MIZUYO-KAN\", \"quantity\":\"16350\"}";
    OrderResponse expected = new OrderResponse().setAccepted(true).setOrderId("Order-JSON-0001").setDescription("Order accepted:[item='MIZUYO-KAN' quantity='16350']");
    ObjectMapper jsonMapper = new ObjectMapper();
    String expectedJson = jsonMapper.writeValueAsString(expected);
    Exchange answer = jsonProducer.send("direct:json", ex -> {
        ((DataTypeAware) ex.getIn()).setBody(order, new DataType("json"));
    });
    assertEquals(expectedJson, answer.getOut().getBody(String.class));
    mockCsv.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Order(org.apache.camel.example.transformer.demo.Order) Processor(org.apache.camel.Processor) DataTypeAware(org.apache.camel.spi.DataTypeAware) DataType(org.apache.camel.spi.DataType) OrderResponse(org.apache.camel.example.transformer.demo.OrderResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with DataType

use of org.apache.camel.spi.DataType in project camel by apache.

the class ManagedTransformerRegistry method listTransformers.

@SuppressWarnings("unchecked")
public TabularData listTransformers() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listTransformersTabularType());
        Collection<Transformer> transformers = transformerRegistry.values();
        for (Transformer transformer : transformers) {
            CompositeType ct = CamelOpenMBeanTypes.listTransformersCompositeType();
            String scheme = transformer.getModel();
            DataType from = transformer.getFrom();
            DataType to = transformer.getTo();
            String desc = transformer.toString();
            boolean fromStatic = scheme != null ? transformerRegistry.isStatic(scheme) : transformerRegistry.isStatic(from, to);
            boolean fromDynamic = scheme != null ? transformerRegistry.isDynamic(scheme) : transformerRegistry.isDynamic(from, to);
            CompositeData data = new CompositeDataSupport(ct, new String[] { "scheme", "from", "to", "static", "dynamic", "description" }, new Object[] { scheme, from.toString(), to.toString(), fromStatic, fromDynamic, desc });
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : Transformer(org.apache.camel.spi.Transformer) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) DataType(org.apache.camel.spi.DataType) TabularData(javax.management.openmbean.TabularData) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

DataType (org.apache.camel.spi.DataType)15 DataTypeAware (org.apache.camel.spi.DataTypeAware)8 Exchange (org.apache.camel.Exchange)5 Transformer (org.apache.camel.spi.Transformer)5 CamelContext (org.apache.camel.CamelContext)4 Processor (org.apache.camel.Processor)3 Order (org.apache.camel.example.transformer.demo.Order)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 CompositeData (javax.management.openmbean.CompositeData)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 CompositeType (javax.management.openmbean.CompositeType)2 TabularData (javax.management.openmbean.TabularData)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 OrderResponse (org.apache.camel.example.transformer.demo.OrderResponse)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DataFormatTransformer (org.apache.camel.impl.transformer.DataFormatTransformer)2 ProcessorTransformer (org.apache.camel.impl.transformer.ProcessorTransformer)2 BindingException (org.apache.camel.processor.binding.BindingException)2