How to set up XML marshalling for a TCP server in Spring integration? -


i want use spring integration create simple tcp server communicates using xml messages. trying use tcpinboundgateway appropriate marshalling set on input , output channels below.

@bean tcpnetserverconnectionfactory cf () {      tcpnetserverconnectionfactory tcf = new tcpnetserverconnectionfactory(7017);     tcf.setserializer(new bytearraylfserializer());     return tcf; }  @bean tcpinboundgateway tcpgate() {     tcpinboundgateway gateway = new tcpinboundgateway();     gateway.setconnectionfactory(cf());     gateway.setrequestchannel(requestchannel());     gateway.setreplychannel(replychannel());     return gateway; }  @bean public messagechannel requestchannel() {     return new directchannel(); }  @bean public messagechannel replychannel() {     return new directchannel(); }    @bean  jaxb2marshaller marshaller() {     final jaxb2marshaller marshaller = new jaxb2marshaller();     marshaller.setpackagestoscan("uk.ac.man.jb.emerlin.emms.corrcontrol.messages");     return marshaller; }   @bean @org.springframework.integration.annotation.transformer(inputchannel="requestchannel", outputchannel="requestchannel") public transformer unmarshallingtransformer() {     final unmarshallingtransformer unmarshallingtransformer = new unmarshallingtransformer(marshaller());      unmarshallingtransformer.setsourcefactory(msourcefactory());     return  unmarshallingtransformer; }  @bean @org.springframework.integration.annotation.transformer(inputchannel="replychannel", outputchannel="replychannel") public transformer marshallingtransformer() throws parserconfigurationexception {     final marshallingtransformer marshallingtransformer = new marshallingtransformer(marshaller());     marshallingtransformer.setresulttype(abstractxmltransformer.string_result);     return  marshallingtransformer; }  @bean public sourcefactory msourcefactory() {     return new sourcefactory() {          @override         public source createsource(object payload) {             source source = null;             if (payload instanceof string) {                 source = new streamsource(new stringreader((string) payload));             }             else if (payload instanceof byte[]) {                 source = new streamsource(new stringreader(new string((byte[])payload)));             }             if (source == null) {                 throw new messagingexception("failed create source payload type [" +                         payload.getclass().getname() + "]");             }             return source;          }     };  }    //fixme  @messageendpoint public static class correlatoremcontrol {      @serviceactivator(inputchannel = "requestchannel" , outputchannel="replychannel")     public correlatorresponse service(@payload correlatorrequest in) {         logger.info("command {}", in.getcommand().getname());          return new correlatorresponse();     } } 

my problem although incoming message unmarshalled cannot seem marshalling of response appropriate form - e.g. string response channel pass on - in following trace.

14:20:37.277 [pool-3-thread-2] info  u.a.m.j.e.e.c.d.correlatorendpoint - command silly 14:20:37.277 [pool-3-thread-2] debug o.s.b.f.s.defaultlistablebeanfactory - returning cached instance of singleton bean 'replychannel' 14:20:37.277 [pool-3-thread-2] debug o.s.i.t.messagetransforminghandler - correlatorendpoint.marshallingtransformer.transformer.handler received message: genericmessage [payload=uk.ac.man.jb.emerlin.emms.corrcontrol.messages.correlatorresponse@74056889, headers={timestamp=1429881637277, id=d745c519-ddd3-a92c-260f-22e91fdcc5d1, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_tcp_remoteport=55208, ip_address=0:0:0:0:0:0:0:1, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.292 [pool-3-thread-2] debug o.s.b.f.s.defaultlistablebeanfactory - returning cached instance of singleton bean 'replychannel' 14:20:37.292 [pool-3-thread-2] debug o.s.i.handler.bridgehandler - org.springframework.integration.handler.bridgehandler@304044a3 received message: genericmessage [payload=<?xml version="1.0" encoding="utf-8" standalone="yes"?><emcc:correlatorresponse xmlns:emcc="http://jb.man.ac.uk/schema/emerlincorrelator" xmlns:eop="http://jb.man.ac.uk/schema/eop"><errorstatus>false</errorstatus></emcc:correlatorresponse>, headers={timestamp=1429881637292, id=20e4eaf1-f6d0-de23-c14b-1dde7df5939d, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_address=0:0:0:0:0:0:0:1, ip_tcp_remoteport=55208, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.293 [pool-3-thread-2] debug o.s.i.channel.directchannel - postsend (sent=true) on channel 'replychannel', message: genericmessage [payload=<?xml version="1.0" encoding="utf-8" standalone="yes"?><emcc:correlatorresponse xmlns:emcc="http://jb.man.ac.uk/schema/emerlincorrelator" xmlns:eop="http://jb.man.ac.uk/schema/eop"><errorstatus>false</errorstatus></emcc:correlatorresponse>, headers={timestamp=1429881637292, id=20e4eaf1-f6d0-de23-c14b-1dde7df5939d, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_address=0:0:0:0:0:0:0:1, ip_tcp_remoteport=55208, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.293 [pool-3-thread-2] debug o.s.i.channel.directchannel - postsend (sent=true) on channel 'replychannel', message: genericmessage [payload=uk.ac.man.jb.emerlin.emms.corrcontrol.messages.correlatorresponse@74056889, headers={timestamp=1429881637277, id=d745c519-ddd3-a92c-260f-22e91fdcc5d1, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_tcp_remoteport=55208, ip_address=0:0:0:0:0:0:0:1, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.293 [pool-3-thread-2] debug o.s.i.channel.directchannel - postsend (sent=true) on channel 'requestchannel', message: genericmessage [payload=uk.ac.man.jb.emerlin.emms.corrcontrol.messages.correlatorrequest@44391778, headers={timestamp=1429881637275, id=862128b7-9754-124b-e6a2-407f87d0407c, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_address=0:0:0:0:0:0:0:1, ip_tcp_remoteport=55208, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.293 [pool-3-thread-2] debug o.s.i.channel.directchannel - postsend (sent=true) on channel 'requestchannel', message: genericmessage [payload=byte[254], headers={timestamp=1429881637257, id=963a80b6-ac0f-35db-51d1-a52593f9b78c, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_tcp_remoteport=55208, ip_address=0:0:0:0:0:0:0:1, replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@110ed52e, ip_hostname=localhost, ip_connectionid=localhost:55208:7017:8d710c70-ed34-4b3a-bdb6-d3ae9ce7142c}] 14:20:37.294 [pool-3-thread-2] debug o.s.i.i.t.s.bytearraycrlfserializer - available read:0 14:20:37.293 o.s.i.ip.tcp.tcpinboundgateway - failed send reply org.springframework.messaging.messagehandlingexception: when using byte array serializer, socket mapper expects either byte array or string payload, received: class org.springframework.xml.transform.stringresult 

how can configure transformer produce appropriate output - stringresult not seem interpreted properly?

by default, marshalling transformer produces javax.xml.transform.result object; transformer has optional resulttransformer taken second constructor argument.

configure use resulttostringtransformer convert result string.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -