Spring integration how to handle Json Payload in ws:outbound-gateway -


i want use spring integration call webservice , then put json response ftp, webservice need json payload, want use webservice outbound gateway fulfill request, got following exception; seems simplewebserviceoutboundgateway's default handler not support json format payload, how can overcome , pass jason payload correctly?

warning:  org.apache.xerces.parsers.saxparser: http://javax.xml.xmlconstants/property/accessexternaldtd warning:  org.apache.xerces.parsers.saxparser: http://www.oracle.com/xml/jaxp/properties/entityexpansionlimit [fatal error] :1:1: content not allowed in prolog. error:  'content not allowed in prolog.'  org.springframework.messaging.messagehandlingexception: error occurred in message handler [org.springframework.integration.handler.messagehandlerchain#0$child#1.handler]      @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:84)     @ org.springframework.integration.handler.messagehandlerchain$1.send(messagehandlerchain.java:150)     @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:114)     @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:44)     @ org.springframework.messaging.core.abstractmessagesendingtemplate.send(abstractmessagesendingtemplate.java:93)     @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.sendmessage(abstractreplyproducingmessagehandler.java:260)     @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.sendreplymessage(abstractreplyproducingmessagehandler.java:241)     @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.producereply(abstractreplyproducingmessagehandler.java:205)     @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.handleresult(abstractreplyproducingmessagehandler.java:199)     @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.handlemessageinternal(abstractreplyproducingmessagehandler.java:177)     @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:78)     @ org.springframework.integration.handler.messagehandlerchain.handlemessageinternal(messagehandlerchain.java:131)     @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:78)     @ org.springframework.integration.dispatcher.abstractdispatcher.tryoptimizeddispatch(abstractdispatcher.java:116)     @ org.springframework.integration.dispatcher.unicastingdispatcher.dodispatch(unicastingdispatcher.java:101)     @ org.springframework.integration.dispatcher.unicastingdispatcher.dispatch(unicastingdispatcher.java:97)     @ org.springframework.integration.channel.abstractsubscribablechannel.dosend(abstractsubscribablechannel.java:77)     @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:255)     @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:223)     @ com.oocl.frm.dmtp.company.esteelauder.outboundgatewaystaticpostparametertest.test(outboundgatewaystaticpostparametertest.java:37)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50)     @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12)     @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47)     @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) 

my spring integration configuration:

<int:channel id="requestchannel"/>     <int:channel id="xmlchannel">         <int:queue/>     </int:channel>      <int:chain input-channel="requestchannel" output-channel="xmlchannel">         <int:header-enricher>             <int:header name="contenttype" value="application/json"/>         </int:header-enricher>         <ws:outbound-gateway uri="http://localhost:8080/postservice/post" >         </ws:outbound-gateway>         <int:transformer ref="jsontoxmltransformer"/>     </int:chain> 

my test code:

@runwith(springjunit4classrunner.class) public class outboundgatewaystaticpostparametertest {     @autowired     messagechannel requestchannel;     @autowired     queuechannel xmlchannel;       private static string json_str= "{'username':'iosdeveloper','md5':'xxxxxxxxxxxxxxxxx' }";      @test     public  void test() throws ioexception, interruptedexception {         message<string> message = messagebuilder.withpayload(json_str).build();          requestchannel.send(message);          message<string> outmsg = (message<string>) xmlchannel.receive();          system.out.println(outmsg.getpayload());      }  } 

and restful webservice code

@path("/postservice") public class postservice {     @post     @path("post")     @consumes(mediatype.application_json)     @produces(mediatype.application_json)     public postmessage postmethod(postparameters postparameters) {         postmessage msg = new postmessage();         msg.setcode("200");         msg.setmessage("hello world!");         return msg;     } } 

ws outbound gateway soap, try call rest. consider use http outbound gateway


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -