Использовать Spring Integration для отправки запроса веб-сервиса - PullRequest
0 голосов
/ 19 января 2019

Я хочу использовать интеграцию Spring для замены моего старого шлюза веб-сервиса.в старом шлюзе программа получает запрос и отправляет его по httpclient.вот отправляющая часть моего старого шлюза веб-сервиса

 DefaultHttpClient httpClient = null;
    Map<String,String> map = new HashMap<String,String>();
    httpClient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(dynamicUrl);
    String soapRequestData =dynamicXMLString;
    HttpEntity re = new StringEntity(soapRequestData, HTTP.UTF_8);
    httppost.setHeader("Content-Type","application/soap+xml; charset=utf-8");
    httppost.setEntity(re);
    try {
        HttpResponse response = httpClient.execute(httppost);
        if(response.getStatusLine().getStatusCode() == 200) {  
            String xmlString = EntityUtils.toString(response.getEntity());
            System.out.println("-------------------------");
            System.out.println(xmlString);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

Теперь я хочу использовать spring-интеграцию-http для замены части httpclient.Я использую int-http: inbound-gateway для получения запроса, использую активатор службы для обработки запроса и отправки по int-http: outbound-gatewy.входящий-шлюз:

    <int:channel id="inchannel"/>
<int:channel id="respReply"/>
<int-http:inbound-gateway request-channel="inchannel" path="**" supported-methods="POST,GET"
                          reply-channel="respReply">
    <int-http:cross-origin/>
</int-http:inbound-gateway>
<int:service-activator input-channel="receiveChannel" ref="serviceActivator" method="serviceActivator"
                       output-channel="respReply"></int:service-activator>

мой выходной шлюз интеграции spirng выглядит следующим образом:

    <int:channel id='reply.channel'>
    <int:queue capacity='10'/>
</int:channel>
<int:channel id='request.channel'/>


<int-http:outbound-gateway id="outbound.gateway"
                           request-channel="request.channel" url-expression="headers.fwdUrl"
                           http-method-expression="headers.reqMethod"
                           charset="UTF-8" reply-timeout="5000" reply-channel="reply.channel"
>

мой код Java в активаторе

 private GatewaySerive gatewaySerive;
public Message<?> serviceActivator(Message<String> msg){
    MessageChannel outRequestChannel = context.getBean("request.channel", MessageChannel.class);
    PollableChannel outReplyChannel = context.getBean("reply.channel", PollableChannel.class);
    gatewaySerive.getSendOutMsg(msg); // add headers.fwdUrl headers.reqMethod in msg head
    try{
        outRequestChannel.send(enhanceMsg);
    }catch (Exception e){
        e.printStackTrace();
        System.out.println(e.getMessage());
    }
    Message<?> replyMesg = outReplyChannel.receive();

, и я получаю исключениепри отправке запроса веб-службы:

org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI [http://xxx.asmx]; nested exception is org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error, failedMessage=GenericMessage [payload=60,63,120,109,108,32,118,101,114,115,105,111,xxxxxxxxxxx, headers={content-length=317, http_requestMethod=POST, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@348c0b2c, httpMethod=POST, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@348c0b2c, respUrl=http://xxx.asmx, host=localhost:8080, http_requestUrl=http://localhost:8080/httpGateway/ws/findPhonePlace, connection=Keep-Alive, id=7450b3a9-7432-8740-f5fa-0914dcbb1b81, contentType=application/soap+xml;charset=utf-8, accept-encoding=gzip,deflate, user-agent=Apache-HttpClient/4.5.6 (Java/1.8.0_131), timestamp=1547907719856}]

как я могу решить эту проблему?Я хочу отправить веб-сервис по Spring-интеграции-http

...