Search in sources :

Example 16 with DataFormat

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

the class BarcodeDataFormatCamelTest method createRouteBuilder.

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

        @Override
        public void configure() {
            // QR-Code default
            DataFormat code1 = new BarcodeDataFormat();
            from("direct:code1").marshal(code1).to(FILE_ENDPOINT);
            // QR-Code with modified size
            DataFormat code2 = new BarcodeDataFormat(200, 200);
            from("direct:code2").marshal(code2).to(FILE_ENDPOINT);
            // QR-Code with JPEG type
            DataFormat code3 = new BarcodeDataFormat(BarcodeImageType.JPG);
            from("direct:code3").marshal(code3).to(FILE_ENDPOINT);
            // PDF-417 code with modified size and image type
            DataFormat code4 = new BarcodeDataFormat(200, 200, BarcodeImageType.JPG, BarcodeFormat.PDF_417);
            from("direct:code4").marshal(code4).to(FILE_ENDPOINT);
            // AZTEC with modified size and PNG type
            DataFormat code5 = new BarcodeDataFormat(200, 200, BarcodeImageType.PNG, BarcodeFormat.AZTEC);
            from("direct:code5").marshal(code5).to(FILE_ENDPOINT);
            // generic file read --->
            // 
            // read file and route it
            from(FILE_ENDPOINT + "?noop=true").multicast().to("direct:unmarshall", "mock:image");
            // get the message from code
            from("direct:unmarshall").unmarshal(// for unmarshalling, the instance doesn't matter
            code1).to("log:OUT").to("mock:out");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 17 with DataFormat

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

the class RestProducer method createBindingProcessor.

protected AsyncProcessor createBindingProcessor() throws Exception {
    // these options can be overridden per endpoint
    String mode = configuration.getBindingMode().name();
    if (bindingMode != null) {
        mode = bindingMode;
    }
    boolean skip = configuration.isSkipBindingOnErrorCode();
    if (skipBindingOnErrorCode != null) {
        skip = skipBindingOnErrorCode;
    }
    if (mode == null || "off".equals(mode)) {
        // binding mode is off
        return null;
    }
    // setup json data format
    String name = configuration.getJsonDataFormat();
    if (name != null) {
        // must only be a name, not refer to an existing instance
        Object instance = camelContext.getRegistry().lookupByName(name);
        if (instance != null) {
            throw new IllegalArgumentException("JsonDataFormat name: " + name + " must not be an existing bean instance from the registry");
        }
    } else {
        name = "json-jackson";
    }
    // this will create a new instance as the name was not already pre-created
    DataFormat json = camelContext.resolveDataFormat(name);
    DataFormat outJson = camelContext.resolveDataFormat(name);
    // is json binding required?
    if (mode.contains("json") && json == null) {
        throw new IllegalArgumentException("JSon DataFormat " + name + " not found.");
    }
    if (json != null) {
        Class<?> clazz = null;
        if (type != null) {
            String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
            clazz = camelContext.getClassResolver().resolveMandatoryClass(typeName);
        }
        if (clazz != null) {
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), json, "unmarshalType", clazz);
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), json, "useList", type.endsWith("[]"));
        }
        setAdditionalConfiguration(configuration, camelContext, json, "json.in.");
        Class<?> outClazz = null;
        if (outType != null) {
            String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
            outClazz = camelContext.getClassResolver().resolveMandatoryClass(typeName);
        }
        if (outClazz != null) {
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), outJson, "unmarshalType", outClazz);
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), outJson, "useList", outType.endsWith("[]"));
        }
        setAdditionalConfiguration(configuration, camelContext, outJson, "json.out.");
    }
    // setup xml data format
    name = configuration.getXmlDataFormat();
    if (name != null) {
        // must only be a name, not refer to an existing instance
        Object instance = camelContext.getRegistry().lookupByName(name);
        if (instance != null) {
            throw new IllegalArgumentException("XmlDataFormat name: " + name + " must not be an existing bean instance from the registry");
        }
    } else {
        name = "jaxb";
    }
    // this will create a new instance as the name was not already pre-created
    DataFormat jaxb = camelContext.resolveDataFormat(name);
    DataFormat outJaxb = camelContext.resolveDataFormat(name);
    // is xml binding required?
    if (mode.contains("xml") && jaxb == null) {
        throw new IllegalArgumentException("XML DataFormat " + name + " not found.");
    }
    if (jaxb != null) {
        Class<?> clazz = null;
        if (type != null) {
            String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
            clazz = camelContext.getClassResolver().resolveMandatoryClass(typeName);
        }
        if (clazz != null) {
            JAXBContext jc = JAXBContext.newInstance(clazz);
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), jaxb, "context", jc);
        }
        setAdditionalConfiguration(configuration, camelContext, jaxb, "xml.in.");
        Class<?> outClazz = null;
        if (outType != null) {
            String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
            outClazz = camelContext.getClassResolver().resolveMandatoryClass(typeName);
        }
        if (outClazz != null) {
            JAXBContext jc = JAXBContext.newInstance(outClazz);
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), outJaxb, "context", jc);
        } else if (clazz != null) {
            // fallback and use the context from the input
            JAXBContext jc = JAXBContext.newInstance(clazz);
            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), outJaxb, "context", jc);
        }
        setAdditionalConfiguration(configuration, camelContext, outJaxb, "xml.out.");
    }
    return new RestProducerBindingProcessor(producer, camelContext, json, jaxb, outJson, outJaxb, mode, skip, type, outType);
}
Also used : DataFormat(org.apache.camel.spi.DataFormat) JAXBContext(javax.xml.bind.JAXBContext)

Example 18 with DataFormat

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

the class HL7MLLPNettyCodecByteArrayRouteTest method createRouteBuilder.

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

        public void configure() throws Exception {
            // START SNIPPET: e1
            DataFormat hl7 = new HL7DataFormat();
            // we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder").unmarshal(hl7).choice().when(header("CamelHL7TriggerEvent").isEqualTo("A19")).bean("hl7service", "handleA19").to("mock:a19").when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01").bean("hl7service", "handleA01").to("mock:a19").otherwise().to("mock:unknown").end().marshal(hl7);
        // END SNIPPET: e1
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 19 with DataFormat

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

the class HL7NettyRouteTest method createRouteBuilder.

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

        public void configure() throws Exception {
            // START SNIPPET: e1
            DataFormat hl7 = new HL7DataFormat();
            // we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder").unmarshal(hl7).choice().when(header("CamelHL7TriggerEvent").isEqualTo("A19")).bean("hl7service", "handleA19").to("mock:a19").when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01").bean("hl7service", "handleA01").to("mock:a19").otherwise().to("mock:unknown").end().marshal(hl7);
        // END SNIPPET: e1
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

Example 20 with DataFormat

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

the class HL7RouteTest method createRouteBuilder.

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

        public void configure() throws Exception {
            // START SNIPPET: e1
            DataFormat hl7 = new HL7DataFormat();
            // we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec").unmarshal(hl7).choice().when(header("CamelHL7TriggerEvent").isEqualTo("A19")).bean("hl7service", "handleA19").to("mock:a19").when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01").bean("hl7service", "handleA01").to("mock:a19").otherwise().to("mock:unknown").end().marshal(hl7);
        // END SNIPPET: e1
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat)

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