Search in sources :

Example 31 with DataFormat

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

the class MinaDataFormatTest 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("mina2:udp://127.0.0.1:" + serverPort).unmarshal(syslogDataFormat).process(new Processor() {

                public void process(Exchange ex) {
                    assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
                }
            }).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 32 with DataFormat

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

the class NettyManyUDPMessagesTest 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);
                }
            }).to("mock:stop1").marshal(syslogDataFormat).to("mock:stop2");
        }
    };
}
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 33 with DataFormat

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

the class AbstractFeatureTest method testDataFormat.

protected void testDataFormat(String mainFeature, String dataFormat) throws Exception {
    LOG.info("Looking up CamelContext(myCamel) in OSGi Service Registry");
    installCamelFeature(mainFeature);
    CamelContext camelContext = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", SERVICE_TIMEOUT);
    assertNotNull("Cannot find CamelContext with name myCamel", camelContext);
    LOG.info("Getting Camel dataformat: {}", dataFormat);
    DataFormat df = camelContext.resolveDataFormat(dataFormat);
    assertNotNull("Cannot get dataformat with name: " + dataFormat, df);
    LOG.info("Found Camel dataformat: {} instance: {} with className: {}", dataFormat, df, df.getClass());
}
Also used : CamelContext(org.apache.camel.CamelContext) DataFormat(org.apache.camel.spi.DataFormat)

Example 34 with DataFormat

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

the class JmsJaxbTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("jms:queue:error").redeliveryDelay(0));
            onException(InvalidOrderException.class).maximumRedeliveries(0).handled(true).to("jms:queue:invalid");
            DataFormat jaxb = new JaxbDataFormat("org.apache.camel.itest.jms");
            from("jms:queue:in").unmarshal(jaxb).choice().when().method(JmsJaxbTest.class, "isWine").to("jms:queue:wine").otherwise().throwException(new InvalidOrderException("We only like wine")).end();
            from("jms:queue:wine").to("mock:wine");
            from("jms:queue:error").to("mock:error");
            from("jms:queue:invalid").to("mock:invalid");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) JaxbDataFormat(org.apache.camel.converter.jaxb.JaxbDataFormat) JaxbDataFormat(org.apache.camel.converter.jaxb.JaxbDataFormat)

Example 35 with DataFormat

use of org.apache.camel.spi.DataFormat in project quickstarts by jboss-switchyard.

the class CamelServiceRoute method configure.

/**
     * The Camel route is configured via this method.  The from endpoint is required to be a SwitchYard service.
     */
public void configure() {
    DataFormat hl7 = new HL7DataFormat();
    from("switchyard://HL7Route").unmarshal(hl7).process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            String body = exchange.getIn().getBody(String.class);
            PipeParser pipeParser = new PipeParser();
            try {
                // Parse the HL7 message 
                ca.uhn.hl7v2.model.Message message = pipeParser.parse(body);
                if (message instanceof QRY_A19) {
                    // Print out some details from the QRD
                    QRD qrd = (QRD) message.get("QRD");
                    System.out.println("Query Date/Time : " + qrd.getQueryDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Query Format Code : " + qrd.getQueryFormatCode().getValue());
                    System.out.println("Query Priority : " + qrd.getQueryPriority().getValue());
                    System.out.println("Query ID : " + qrd.getQueryID().getValue());
                    System.out.println("Deferred Response Type : " + qrd.getDeferredResponseType().getValue());
                    System.out.println("Deferred Response Date/Time : " + qrd.getDeferredResponseDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Quantity Limited Request : " + qrd.getQuantityLimitedRequest().getQuantity().getValue());
                    System.out.println("Query Results Level : " + qrd.getQueryResultsLevel().getValue());
                    qrd.getQueryID();
                }
            } catch (Exception e) {
                throw e;
            }
            SwitchYardMessage out = new SwitchYardMessage();
            out.setBody(body);
            exchange.setOut(out);
        }
    });
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Processor(org.apache.camel.Processor) PipeParser(ca.uhn.hl7v2.parser.PipeParser) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) Exchange(org.apache.camel.Exchange) DataFormat(org.apache.camel.spi.DataFormat) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) QRY_A19(ca.uhn.hl7v2.model.v24.message.QRY_A19)

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