Java 类org.apache.camel.spi.DataFormat 实例源码

项目:Camel    文件:CryptoDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    DataFormat cryptoFormat = super.createDataFormat(routeContext);

    if (ObjectHelper.isNotEmpty(keyRef)) {
        Key key = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), keyRef, Key.class);
        setProperty(routeContext.getCamelContext(), cryptoFormat, "key", key);
    }
    if (ObjectHelper.isNotEmpty(algorithmParameterRef)) {
        AlgorithmParameterSpec spec = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(),
                algorithmParameterRef, AlgorithmParameterSpec.class);
        setProperty(routeContext.getCamelContext(), cryptoFormat, "AlgorithmParameterSpec", spec);
    }
    if (ObjectHelper.isNotEmpty(initVectorRef)) {
        byte[] iv = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), initVectorRef, byte[].class);
        setProperty(routeContext.getCamelContext(), cryptoFormat, "InitializationVector", iv);
    }
    return cryptoFormat;
}
项目:Camel    文件:BarcodeDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (width != null) {
        setProperty(camelContext, dataFormat, "width", width);
    }

    if (height != null) {
        setProperty(camelContext, dataFormat, "height", height);
    } 

    if (imageType != null) {
        setProperty(camelContext, dataFormat, "barcodeImageType", imageType);
    }

    if (barcodeFormat != null) {
        setProperty(camelContext, dataFormat, "barcodeFormat", barcodeFormat);
    }
}
项目:Camel    文件:NettyRfc5425LongMessageTest.java   
@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 channelbuffer
            from("direct:start").convertBodyTo(ChannelBuffer.class).to(uri);
        }
    };
}
项目:Camel    文件:MimeMultipartDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (getMultipartSubType() != null) {
        setProperty(camelContext, dataFormat, "multipartSubType", getMultipartSubType());
    }
    if (getMultipartWithoutAttachment() != null) {
        setProperty(camelContext, dataFormat, "multipartWithoutAttachment", getMultipartWithoutAttachment());
    }
    if (getHeadersInline() != null) {
        setProperty(camelContext, dataFormat, "headersInline", getHeadersInline());
    }
    if (getIncludeHeaders() != null) {
        setProperty(camelContext, dataFormat, "includeHeaders", getIncludeHeaders());
    }
    if (getBinaryContent() != null) {
        setProperty(camelContext, dataFormat, "binaryContent", getBinaryContent());
    }
}
项目:Camel    文件:XStreamDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (this.permissions != null) {
        setProperty(camelContext, dataFormat, "permissions", this.permissions);
    }
    if (encoding != null) {
        setProperty(camelContext, dataFormat, "encoding", encoding);
    }
    if (this.converters != null) {
        setProperty(camelContext, dataFormat, "converters", this.converters);
    }
    if (this.aliases != null) {
        setProperty(camelContext, dataFormat, "aliases", this.aliases);
    }
    if (this.omitFields != null) {
        setProperty(camelContext, dataFormat, "omitFields", this.omitFields);
    }
    if (this.implicitCollections != null) {
        setProperty(camelContext, dataFormat, "implicitCollections", this.implicitCollections);
    }
    if (this.mode != null) {
        setProperty(camelContext, dataFormat, "mode", mode);
    }
}
项目:Camel    文件:CastorDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (mappingFile != null) {
        setProperty(camelContext, dataFormat, "mappingFile", mappingFile);
    }
    // should be true by default
    boolean isValidation = getValidation() == null || getValidation();
    setProperty(camelContext, dataFormat, "validation", isValidation);

    if (encoding != null) {
        setProperty(camelContext, dataFormat, "encoding", encoding);
    }
    if (packages != null) {
        setProperty(camelContext, dataFormat, "packages", packages);
    }
    if (classes != null) {
        setProperty(camelContext, dataFormat, "classes", classes);
    }
}
项目:Camel    文件:BeanioDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    setProperty(camelContext, dataFormat, "mapping", mapping);
    setProperty(camelContext, dataFormat, "streamName", streamName);
    if (ignoreUnidentifiedRecords != null) {
        setProperty(camelContext, dataFormat, "ignoreUnidentifiedRecords", ignoreUnidentifiedRecords);
    }
    if (ignoreUnexpectedRecords != null) {
        setProperty(camelContext, dataFormat, "ignoreUnexpectedRecords", ignoreUnexpectedRecords);
    }
    if (ignoreInvalidRecords != null) {
        setProperty(camelContext, dataFormat, "ignoreInvalidRecords", ignoreInvalidRecords);
    }
    if (encoding != null) {
        setProperty(camelContext, dataFormat, "encoding", encoding);
    }
}
项目:Camel    文件:YAMLDataFormat.java   
protected void configureSnakeDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    Class<?> yamlUnmarshalType =  unmarshalType;
    if (yamlUnmarshalType == null && unmarshalTypeName != null) {
        try {
            yamlUnmarshalType = camelContext.getClassResolver().resolveMandatoryClass(unmarshalTypeName);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }

    setProperty(dataFormat, camelContext, "unmarshalType", yamlUnmarshalType);
    setProperty(dataFormat, camelContext, "classLoader", classLoader);
    setProperty(dataFormat, camelContext, "useApplicationContextClassLoader", useApplicationContextClassLoader);
    setProperty(dataFormat, camelContext, "prettyFlow", prettyFlow);

    setPropertyRef(dataFormat, camelContext, "constructor", constructor);
    setPropertyRef(dataFormat, camelContext, "representer", representer);
    setPropertyRef(dataFormat, camelContext, "dumperOptions", dumperOptions);
    setPropertyRef(dataFormat, camelContext, "resolver", resolver);
}
项目:Camel    文件:NettyManyUDPMessagesTest.java   
@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("netty: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");
        }
    };
}
项目:Camel    文件:DozerProducer.java   
/**
 * Find and configure an unmarshaller for the specified data format.
 */
private synchronized UnmarshalProcessor resolveUnmarshaller(
        Exchange exchange, String dataFormatId) throws Exception {

    if (unmarshaller == null) {
        DataFormat dataFormat = DataFormatDefinition.getDataFormat(
                exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
        if (dataFormat == null) {
            throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId);
        }

        // Wrap the data format in a processor and start/configure it.  
        // Stop/shutdown is handled when the corresponding methods are 
        // called on this producer.
        unmarshaller = new UnmarshalProcessor(dataFormat);
        unmarshaller.setCamelContext(exchange.getContext());
        unmarshaller.start();
    }
    return unmarshaller;
}
项目:Camel    文件:BindyDataFormat.java   
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (classType == null && clazz == null) {
        throw new IllegalArgumentException("Either packages or classType must be specified");
    }

    if (type == BindyType.Csv) {
        setDataFormatName("bindy-csv");
    } else if (type == BindyType.Fixed) {
        setDataFormatName("bindy-fixed");
    } else {
        setDataFormatName("bindy-kvp");
    }

    if (clazz == null && classType != null) {
        try {
            clazz = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(classType);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
    return super.createDataFormat(routeContext);
}
项目:Camel    文件:MinaManyUDPMessagesTest.java   
@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:stop1").
                marshal(syslogDataFormat).to("mock:stop2");
        }
    };
}
项目:Camel    文件:DataFormatProvider.java   
private DataFormat getDataFormat(MediaType mt) {
    String type = JAXRSUtils.mediaTypeToString(mt);
    DataFormat format = formats.get(type);
    if (format != null) {
        return format;
    }
    int subtypeIndex = type.lastIndexOf('+');
    if (subtypeIndex != -1) {
        // example, application/json+v1, should still be handled by JSON
        // handler, etc
        format = formats.get(type.substring(0, subtypeIndex));
    }
    if (format == null && formats.containsKey(MediaType.WILDCARD)) {
        format = formats.get(MediaType.WILDCARD);
    }
    return format;
}
项目:Camel    文件:SoapJaxbDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (elementNameStrategy != null) {
        setProperty(camelContext, dataFormat, "elementNameStrategy", elementNameStrategy);
    }
    if (elementNameStrategyRef != null) {
        setProperty(camelContext, dataFormat, "elementNameStrategyRef", elementNameStrategyRef);
    }
    if (encoding != null) {
        setProperty(camelContext, dataFormat, "encoding", encoding);
    }
    if (version != null) {
        setProperty(camelContext, dataFormat, "version", version);
    }
    if (namespacePrefixRef != null) {
        setProperty(camelContext, dataFormat, "namespacePrefixRef", namespacePrefixRef);
    }
    if (schema != null) {
        setProperty(camelContext, dataFormat, "schema", schema);
    }
    setProperty(camelContext, dataFormat, "contextPath", contextPath);
}
项目:Camel    文件:DataFormatDefinition.java   
public DataFormat getDataFormat(RouteContext routeContext) {
    if (dataFormat == null) {
        Runnable propertyPlaceholdersChangeReverter = ProcessorDefinitionHelper.createPropertyPlaceholdersChangeReverter();

        // resolve properties before we create the data format
        try {
            ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), this);
        } catch (Exception e) {
            throw new IllegalArgumentException("Error resolving property placeholders on data format: " + this, e);
        }
        try {
            dataFormat = createDataFormat(routeContext);
            if (dataFormat != null) {
                configureDataFormat(dataFormat, routeContext.getCamelContext());
            } else {
                throw new IllegalArgumentException(
                        "Data format '" + (dataFormatName != null ? dataFormatName : "<null>") + "' could not be created. "
                                + "Ensure that the data format is valid and the associated Camel component is present on the classpath");
            }
        } finally {
            propertyPlaceholdersChangeReverter.run();
        }
    }
    return dataFormat;
}
项目:Camel    文件:RouteWithErrorHandlerTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0));

            onException(InvalidOrderException.class).maximumRedeliveries(0).handled(true)
                .to("mock:invalid");

            DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");

            from("direct:start")
                .unmarshal(jaxb)
                .choice()
                    .when().method(RouteWithErrorHandlerTest.class, "isWine").to("mock:wine")
                    .otherwise().throwException(new InvalidOrderException("We only like wine"))
                .end();
        }
    };
}
项目:Camel    文件:NettyDataFormatTest.java   
@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("netty: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");
        }
    };
}
项目:Camel    文件:DataFormatComponent.java   
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String name = ObjectHelper.before(remaining, ":");
    DataFormat df = getCamelContext().resolveDataFormat(name);
    if (df == null) {
        throw new IllegalArgumentException("Cannot find data format with name: " + name);
    }

    String operation = ObjectHelper.after(remaining, ":");
    if (!"marshal".equals(operation) && !"unmarshal".equals(operation)) {
        throw new IllegalArgumentException("Operation must be either marshal or unmarshal, was: " + operation);
    }

    // set reference properties first as they use # syntax that fools the regular properties setter
    EndpointHelper.setReferenceProperties(getCamelContext(), df, parameters);
    EndpointHelper.setProperties(getCamelContext(), df, parameters);

    DataFormatEndpoint endpoint = new DataFormatEndpoint(uri, this, df);
    endpoint.setOperation(operation);
    setProperties(endpoint, parameters);
    return endpoint;
}
项目:Camel    文件:OsgiDataFormatResolver.java   
protected DataFormat getDataFormat(String name, CamelContext context) {
    LOG.trace("Finding DataFormat: {}", name);
    try {
        ServiceReference<?>[] refs = bundleContext.getServiceReferences(DataFormatResolver.class.getName(), "(dataformat=" + name + ")");
        if (refs != null) {
            for (ServiceReference<?> ref : refs) {
                Object service = bundleContext.getService(ref);
                if (DataFormatResolver.class.isAssignableFrom(service.getClass())) {
                    DataFormatResolver resolver = (DataFormatResolver) service;
                    return resolver.resolveDataFormat(name, context);
                }
            }
        }
        return null;
    } catch (InvalidSyntaxException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
项目:Camel    文件:MinaDataFormatTest.java   
@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");
        }
    };
}
项目:Camel    文件:OsgiDataFormatResolver.java   
public DataFormat resolveDataFormat(String name, CamelContext context) {
    // lookup in registry first
    Object bean = null;
    try {
        bean = context.getRegistry().lookupByName(name);
        if (bean != null) {
            LOG.debug("Found language: {} in registry: {}", name, bean);
        }
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Ignored error looking up bean: " + name + ". Error: " + e);
        }
    }
    if (bean instanceof DataFormat) {
        return (DataFormat) bean;
    }
    return getDataFormat(name, context);
}
项目:Camel    文件:CryptoDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    Boolean answer = ObjectHelper.toBoolean(shouldAppendHMAC);
    if (answer != null && !answer) {
        setProperty(camelContext, dataFormat, "shouldAppendHMAC", Boolean.FALSE);
    } else {
        setProperty(camelContext, dataFormat, "shouldAppendHMAC", Boolean.TRUE);
    }
    answer = ObjectHelper.toBoolean(inline);
    if (answer != null && answer) {
        setProperty(camelContext, dataFormat, "shouldInlineInitializationVector", Boolean.TRUE);
    } else {
        setProperty(camelContext, dataFormat, "shouldInlineInitializationVector", Boolean.FALSE);
    }
    if (algorithm != null) {
        setProperty(camelContext, dataFormat, "algorithm", algorithm);
    }
    if (cryptoProvider != null) {
        setProperty(camelContext, dataFormat, "cryptoProvider", cryptoProvider);
    }
    if (macAlgorithm != null) {
        setProperty(camelContext, dataFormat, "macAlgorithm", macAlgorithm);
    }
    if (buffersize != null) {
        setProperty(camelContext, dataFormat, "buffersize", buffersize);
    }
}
项目:Camel    文件:ZipDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (compressionLevel == null) {
        return new org.apache.camel.impl.ZipDataFormat(Deflater.DEFAULT_COMPRESSION);
    } else {
        return new org.apache.camel.impl.ZipDataFormat(compressionLevel);
    }
}
项目:Camel    文件:Base64DataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (getLineLength() != null) {
        setProperty(camelContext, dataFormat, "lineLength", getLineLength());
    }
    if (getUrlSafe() != null) {
        setProperty(camelContext, dataFormat, "urlSafe", getUrlSafe());
    }
    if (getLineSeparator() != null) {
        // line separator must be a byte[]
        byte[] bytes = getLineSeparator().getBytes();
        setProperty(camelContext, dataFormat, "lineSeparator", bytes);
    }
}
项目:Camel    文件:BlueprintDataFormatResolver.java   
@Override
public DataFormat resolveDataFormat(String name, CamelContext context) {
    try {
        Object bean = context.getRegistry().lookupByName(".camelBlueprint.dataformatResolver." + name);
        if (bean instanceof DataFormatResolver) {
            LOG.debug("Found dataformat resolver: {} in registry: {}", name, bean);
            return ((DataFormatResolver) bean).resolveDataFormat(name, context);
        }
    } catch (Exception e) {
        LOG.trace("Ignored error looking up bean: " + name + " due: " + e.getMessage(), e);
    }
    return super.resolveDataFormat(name, context);
}
项目:Camel    文件:UniVocityTsvDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    super.configureDataFormat(dataFormat, camelContext);

    if (escapeChar != null) {
        setProperty(camelContext, dataFormat, "escapeChar", singleCharOf("escapeChar", escapeChar));
    }
}
项目:Camel    文件:ProtobufDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (this.instanceClass != null) {
        setProperty(camelContext, dataFormat, "instanceClass", instanceClass);
    }
    if (this.defaultInstance != null) {
        setProperty(camelContext, dataFormat, "defaultInstance", defaultInstance);
    }
}
项目:Camel    文件:XStreamDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if ("json".equals(this.driver)) {
        setProperty(routeContext.getCamelContext(), this, "dataFormatName", "json-xstream");
    }
    DataFormat answer = super.createDataFormat(routeContext);
    // need to lookup the reference for the xstreamDriver
    if (ObjectHelper.isNotEmpty(driverRef)) {
        setProperty(routeContext.getCamelContext(), answer, "xstreamDriver", CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), driverRef));
    }
    return answer;
}
项目:Camel    文件:BoonDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (unmarshalType == null && unmarshalTypeName != null) {
        try {
            unmarshalType = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(unmarshalTypeName);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
    return super.createDataFormat(routeContext);
}
项目:Camel    文件:JaxbConcurrentDataFormatTest.java   
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");

            from("direct:start").
                    marshal(jaxb).
                    to("direct:marshalled");

            from("direct:marshalled").
                    unmarshal(jaxb).
                    to("mock:result");
        }
    };
}
项目:Camel    文件:TidyMarkupDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (dataObjectType == null && dataObjectTypeName != null) {
        try {
            dataObjectType = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(dataObjectTypeName);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }

    return super.createDataFormat(routeContext);
}
项目:Camel    文件:JibxDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (unmarshallClass == null && unmarshallTypeName != null) {
        try {
            unmarshallClass = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(unmarshallTypeName);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }

    return super.createDataFormat(routeContext);
}
项目:Camel    文件:AbstractFeatureTest.java   
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());
}
项目:Camel    文件:HL7NettyRouteTest.java   
@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")
                // we use the HL7 data format to unmarshal from HL7 stream to the HAPI Message model
                // this ensures that the camel message has been enriched with hl7 specific headers to
                // make the routing much easier (see below)
                .unmarshal(hl7)
                // using choice as the content base router
                .choice()
                    // where we choose that A19 queries invoke the handleA19 method on our hl7service bean
                    .when(header("CamelHL7TriggerEvent").isEqualTo("A19"))
                        .bean("hl7service", "handleA19")
                        .to("mock:a19")
                    // and A01 should invoke the handleA01 method on our hl7service bean
                    .when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01")
                        .bean("hl7service", "handleA01")
                        .to("mock:a19")
                    // other types should go to mock:unknown
                    .otherwise()
                        .to("mock:unknown")
                // end choice block
                .end()
                // marshal response back
                .marshal(hl7);
            // END SNIPPET: e1
        }
    };
}
项目:Camel    文件:CsvTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // START SNIPPET: e1
            // setup beanio data format using the mapping file, loaded from the classpath
            DataFormat format = new BeanIODataFormat(
                    "org/apache/camel/dataformat/beanio/csv/mappings.xml",
                    "stream1");

            // a route which uses the bean io data format to format a CSV data
            // to java objects
            from("direct:unmarshal")
                    .unmarshal(format)
                            // and then split the message body so we get a message for each row
                    .split(body())
                    .to("mock:beanio-unmarshal");

            // convert list of java objects back to flat format
            from("direct:marshal")
                    .marshal(format)
                    .to("mock:beanio-marshal");
            // END SNIPPET: e1
        }
    };
}
项目:Camel    文件:YAMLDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    if (library == YAMLLibrary.SnakeYAML) {
        setProperty(routeContext.getCamelContext(), this, "dataFormatName", "yaml-snakeyaml");
    }

    return super.createDataFormat(routeContext);
}
项目:Camel    文件:HL7DataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (getParser() != null) {
        setProperty(camelContext, dataFormat, "parser", getParser());
    }
    setProperty(camelContext, dataFormat, "validate", isValidate());
}
项目:Camel    文件:FlatpackDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    DataFormat flatpack = super.createDataFormat(routeContext);

    if (ObjectHelper.isNotEmpty(parserFactoryRef)) {
        Object parserFactory = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), parserFactoryRef);
        setProperty(routeContext.getCamelContext(), flatpack, "parserFactory", parserFactory);
    }

    return flatpack;
}
项目:Camel    文件:FlatpackDataFormat.java   
@Override
protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
    if (ObjectHelper.isNotEmpty(definition)) {
        setProperty(camelContext, dataFormat, "definition", definition);
    }
    if (fixed != null) {
        setProperty(camelContext, dataFormat, "fixed", fixed);
    }
    if (ignoreFirstRecord != null) {
        setProperty(camelContext, dataFormat, "ignoreFirstRecord", ignoreFirstRecord);
    }
    if (ObjectHelper.isNotEmpty(textQualifier)) {
        if (textQualifier.length() > 1) {
            throw new IllegalArgumentException("Text qualifier must be one character long!");
        }
        setProperty(camelContext, dataFormat, "textQualifier", textQualifier.charAt(0));
    }
    if (ObjectHelper.isNotEmpty(delimiter)) {
        if (delimiter.length() > 1) {
            throw new IllegalArgumentException("Delimiter must be one character long!");
        }
        setProperty(camelContext, dataFormat, "delimiter", delimiter.charAt(0));
    }
    if (allowShortLines != null) {
        setProperty(camelContext, dataFormat, "allowShortLines", allowShortLines);
    }
    if (ignoreExtraColumns != null) {
        setProperty(camelContext, dataFormat, "ignoreExtraColumns", ignoreExtraColumns);
    }
}
项目:Camel    文件:HL7MLLPNettyCodecByteArrayRouteTest.java   
@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")
                // we use the HL7 data format to unmarshal from HL7 stream to the HAPI Message model
                // this ensures that the camel message has been enriched with hl7 specific headers to
                // make the routing much easier (see below)
                .unmarshal(hl7)
                // using choice as the content base router
                .choice()
                    // where we choose that A19 queries invoke the handleA19 method on our hl7service bean
                    .when(header("CamelHL7TriggerEvent").isEqualTo("A19"))
                        .bean("hl7service", "handleA19")
                        .to("mock:a19")
                    // and A01 should invoke the handleA01 method on our hl7service bean
                    .when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01")
                        .bean("hl7service", "handleA01")
                        .to("mock:a19")
                    // other types should go to mock:unknown
                    .otherwise()
                        .to("mock:unknown")
                // end choice block
                .end()
                // marshal response back
                .marshal(hl7);
            // END SNIPPET: e1
        }
    };
}