Search in sources :

Example 26 with DataFormat

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

the class NettyDataFormatTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog  listener on a random port.
            from("netty4:udp://127.0.0.1:" + serverPort + "?sync=false&allowDefaultCodec=false").unmarshal(syslogDataFormat).process(new Processor() {

                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                    SyslogMessage message = ex.getIn().getBody(SyslogMessage.class);
                }
            }).to("mock:syslogReceiver").marshal(syslogDataFormat).to("mock:syslogReceiver2");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 27 with DataFormat

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

the class NettyRfc5425LongMessageTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5425FrameDecoder());
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog listener on a random port.
            from(uri).unmarshal(syslogDataFormat).process(new Processor() {

                @Override
                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                }
            }).to("mock:syslogReceiver").marshal(syslogDataFormat).to("mock:syslogReceiver2");
            // Here we need to turn the request body into ByteBuf
            from("direct:start").convertBodyTo(ByteBuf.class).to(uri);
        }
    };
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Exchange(org.apache.camel.Exchange) Rfc5425FrameDecoder(org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) ByteBuf(io.netty.buffer.ByteBuf)

Example 28 with DataFormat

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

the class NettyRfc5425Test method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5425FrameDecoder());
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.setTracing(true);
            DataFormat syslogDataFormat = new SyslogDataFormat();
            // we setup a Syslog listener on a random port.
            from(uri).unmarshal(syslogDataFormat).process(new Processor() {

                @Override
                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                }
            }).to("mock:syslogReceiver").marshal(syslogDataFormat).to("mock:syslogReceiver2");
            from("direct:checkStructuredData").unmarshal(syslogDataFormat).process(new Processor() {

                @Override
                public void process(Exchange ex) {
                    Object body = ex.getIn().getBody();
                    assertTrue(body instanceof Rfc5424SyslogMessage);
                    assertEquals("[exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"]", ((Rfc5424SyslogMessage) body).getStructuredData());
                }
            }).to("mock:syslogReceiver");
        }
    };
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Exchange(org.apache.camel.Exchange) Rfc5425FrameDecoder(org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 29 with DataFormat

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

the class DataFormatTestCommand method executeTest.

@Override
public Boolean executeTest(ITestConfig config, String dataFormat) throws Exception {
    logger.info("Getting Camel dataFormat: {}", dataFormat);
    DataFormat df = context.resolveDataFormat(dataFormat);
    assertNotNull("Cannot get dataformat with name: " + dataFormat, df);
    logger.info("Found Camel dataformat: {} instance: {} with className: {}", dataFormat, df, df.getClass());
    return true;
}
Also used : DataFormat(org.apache.camel.spi.DataFormat)

Example 30 with DataFormat

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

the class HttpAsyncDslTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // START SNIPPET: e1
            // just a unit test but imaging using your own data format that does complex
            // and CPU heavy processing for decrypting the message
            DataFormat mySecureDataFormat = new StringDataFormat("iso-8859-1");
            // list on the JMS queue for new orders
            from("jms:queue:order").to("bean:validateOrder").to("mock:validate").threads(20).unmarshal(mySecureDataFormat).delay(500).to("bean:handleOrder").to("mock:order");
        // END SNIPPET: e1
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) StringDataFormat(org.apache.camel.impl.StringDataFormat) StringDataFormat(org.apache.camel.impl.StringDataFormat)

Aggregations

DataFormat (org.apache.camel.spi.DataFormat)45 RouteBuilder (org.apache.camel.builder.RouteBuilder)20 Exchange (org.apache.camel.Exchange)8 Processor (org.apache.camel.Processor)8 JaxbDataFormat (org.apache.camel.converter.jaxb.JaxbDataFormat)6 CamelContext (org.apache.camel.CamelContext)5 Test (org.junit.Test)5 JAXBContext (javax.xml.bind.JAXBContext)2 Rfc5425FrameDecoder (org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 QRY_A19 (ca.uhn.hl7v2.model.v24.message.QRY_A19)1 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Key (java.security.Key)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1