2017-08-21 11 views
0

私はSpringの統合を使用してWebサービスを呼び出し、次にjsonの応答をFTP、webserviceにjsonペイロードが必要になるようにしたいと思います。要求、しかし私は次の例外を持っています。 SimpleWebServiceOutboundGatewayのデフォルトのハンドラがjson形式のペイロードをサポートしていないようですが、どうすればこれを克服し、JASONペイロードを正しく渡すことができますか?Springの統合ws:outbound-gatewayでJson Payloadを処理する方法

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 is not allowed in prolog. 
ERROR: 'Content is not allowed in prolog.' 

org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.handler.MessageHandlerChain#0$child#1.handler] 

    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:84) 
    at org.springframework.integration.handler.MessageHandlerChain$1.send(MessageHandlerChain.java:150) 
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:114) 
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:44) 
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:93) 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendMessage(AbstractReplyProducingMessageHandler.java:260) 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendReplyMessage(AbstractReplyProducingMessageHandler.java:241) 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.produceReply(AbstractReplyProducingMessageHandler.java:205) 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleResult(AbstractReplyProducingMessageHandler.java:199) 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:177) 
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) 
    at org.springframework.integration.handler.MessageHandlerChain.handleMessageInternal(MessageHandlerChain.java:131) 
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) 
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) 
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) 
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255) 
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:223) 
    at com.oocl.frm.dmtp.company.esteelauder.OutboundGatewayStaticPostParameterTest.test(OutboundGatewayStaticPostParameterTest.java:37) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 

マイSpring統合の設定:

<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> 

私のテストコード:

@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()); 

    } 

} 

と私の安らかなWebサービスコード

@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; 
    } 
} 

答えて

1

WS送信ゲートウェイは、SOAPのためですが、あなたはRESに電話しようとするT. HTTP送信ゲートウェイ

0

私の右の設定を使用するように考えてみましょう

<int:channel id="requestChannel"/> 
    <int:channel id="requestChannel2"/> 
    <int:channel id="replyChannel"/> 
    <int:channel id="xmlChannel"> 
     <int:queue/> 
    </int:channel> 


    <int:header-enricher input-channel="requestChannel" 
         output-channel="requestChannel2"> 
     <int:header name="Content-Type" value="application/json" overwrite="true"/> 
</int:header-enricher> 

    <http:outbound-gateway request-channel="requestChannel2" expected-response-type="java.lang.String" 
          reply-channel="replyChannel" 
          url="http://localhost:8080/postService/postwithparm" 
          http-method="POST" 
          extract-request-payload="true"> 
    </http:outbound-gateway> 

    <int:transformer ref="jsonToXmlTransformer" input-channel="replyChannel" output-channel="xmlChannel"/> 

私のテストコード:

@Test 
    public void test() throws IOException, InterruptedException { 
     PostParameters p = new PostParameters(); 
     p.setMd5("********"); 
     p.setUserName("io"); 
//  Message<String> message = MessageBuilder.withPayload(JSON_STR).build(); 
     Message message = MessageBuilder.withPayload(p).build(); 
     requestChannel.send(message); 

     Message<?> outMsg = (Message<?>) xmlChannel.receive(); 

     System.out.println(outMsg.getPayload()); 

    } 
関連する問題