Camel Configuration (2)

Source: Internet
Author: User

function Introduction:

function I do not introduce more here.

Demand:

2 Instance requirements:

(1) Source Tcp,xml format data, converted to JSON data, sent to the specified HTTP address.

(2) Source Tcp,xml format data, converted to JSON data, sent to the specified HTTP address, waiting for HTTP to respond to JSON data, to convert the response JSON data into an XML format string response to the source TCP

1.xml configuration file, this configuration is simple.

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:camel=" http://camel.apache.org/schema/spring "xsi:schemalocation=" http://www. Springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd Http://camel . apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> <bean id=" Frombostransform "class=" Com.lakala.loan.exchange.listener.transform.FromBosTransform "/> <bean id=" Fromnettransform "class=" Com.lakala.loan.exchange.listener.transform.FromNetTransform "/> <camel: Camelcontext id= "Camel" trace= "false" xmlns= "http://camel.apache.org/schema/spring" ><!--The instance's Requirement: Listen for the port number if there is a message. The TCP transport XML string, converted to a JSON string, is sent to the corresponding HTTP--<route id= "Toloanbus" > <from uri= "mina2:tcp://127.0.0. 1:11113?textline=true&sync=false&timeout=200000&allowdefaultcodeC=false "/> <!--in the Bostonet method in the Frombostransform class, convert the received data to JSON data--<bean ref=" Frombost Ransform "method=" Bostonet "/> <!--HTTP interface format requirements for JSON data--<setheader headername=" content- Type "> <constant>application/json</constant> </setHeader> &L t;! --Send data to the known HTTP address--<to uri= "http://127.0.0.1:8080/usermanag/hello.do?httpClient.soTimeout=5000&h                ttpclient.connectionmanagertimeout=500000 "/> <to uri=" Mock:results "/> </route>         <!--The requirement for this instance: listen for the port number, TCP transmits XML string, convert the JSON string to the corresponding HTTP request, and then the processing is completed, return the JSON string side to the XML format, and respond back to the source TCP address --<route id= "Toloanbus1" > <from uri= "Mina2:tcp://127.0.0.1:11114?textline=true&syn c=true&timeout=200000 "/> <!--convert received data to JSON data--<bean ref=" Frombostransform "meth   od= "Bostonet"/>         <!--HTTP interface format requirements for JSON data--<setheader headername= "Content-type" > <co nstant>application/json</constant> </setHeader> <to ref= "Http://127.0.0.1:8080/use rmanag/hello.do?httpclient.sotimeout=5000&httpclient.connectionmanagertimeout=500000 "/> <to uri=" mock            : Results "/> <!--HTTP response back to JSON data--<setheader headername=" Content-type ">           The <!--response TCP format is XML, if not then not returned--<constant>application/xml;charset=utf-8</constant>  </setHeader> <transform> <!--gettraderesult methods in the Frombostransform class to convert JSON data to XML format strings --<method ref= "Frombostransform" method= "Gettraderesult"/> </transform> & Lt;/route></camel:camelcontext></beans>
2. Paste a <bean ref= "Frombostransform" method= "bostonet"/> instance, give the new contact camel An instance of receiving data conversion

public void Bostonet (Exchange Exchange, @Body string Body,            @Header (value = "Content-type") string contentType) throws Exception {    //body is the data transmitted by the receiving node        //The XML data is converted to a map, and the detailed code is not posted. Baidu search a lot of map Map=xmltomap.xml2map (body.substring (6));//private objectmapper mapper;//mapper.writevalueasstring (map) Convert map to JSON data, camel's own data conversion exchange.getout (). Setbody (mapper.writevalueasstring (map), string.class);}


Conclusion: This configuration is relatively simple, there is no message in the middle of what the middleware and so on. More straightforward,

Camel Configuration (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.