2015-03-18 4 views
0

Я новичок в Spring Integration и я уже triyng несколько примеров на сети, и я обнаружил, что очень полезно репо на GitHub:Spring интеграции файлов исходящий шлюз и WebService

spring-integration-samples

Для лучшего понимания я попробовал комбинировать некоторые примеры, но затем застрял, моя цель состояла в том, чтобы использовать пример ws-inbound-gateway с примером файла, чтобы создать файл с текстом запроса WS, используя файл outbound-gateway а затем отправить ответ WS.

Для этого я сделал на следующие модификации входящего-шлюза-config.xml из ws-inbound-gateway Например:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:int-ws="http://www.springframework.org/schema/integration/ws" 
    xmlns:int-file="http://www.springframework.org/schema/integration/file" 
    xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd 
     http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/integration/file 
     http://www.springframework.org/schema/integration/file/spring-integration-file.xsd"> 

    <int:channel id="input"/> 

    <int-ws:inbound-gateway id="ws-inbound-gateway" request-channel="input"/> 

    <int-file:outbound-gateway id="mover" request-channel="input" 
           reply-channel="output" 
           directory="file:${java.io.tmpdir}/spring-integration-samples/output" /> 

    <int:channel id="output"/> 

    <int:service-activator input-channel="output"> 
     <bean class="org.springframework.integration.samples.ws.SimpleEchoResponder"/> 
    </int:service-activator>   
</beans> 

В остальном все та же.

Unfortunally я получаю B Неправильно следующее исключение при попытке отправить запрос на WS:

org.springframework.ws.client.WebServiceTransportException: Erreur Interne de Servlet [500] 
    at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:695) 
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606) 
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) 
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:506) 
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:446) 
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:429) 
    at org.springframework.integration.samples.ws.InContainerTests.testWebServiceRequestAndResponse(InContainerTests.java:52) 

, а затем, когда я пытался entring ссылки в браузере я получил:

cause mère 

org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 75; cvc-complex-type.2.4.c : Le caractère générique concordant est strict, mais aucune déclaration ne peut être trouvée pour l'élément 'int-file:outbound-gateway'. 
    com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) 
    com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) 
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) 
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) 
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325) 
... 

I не знаю, если мне не хватает декларации в моем web.xml, или я получаю неправильное кодирование. Спасибо за помощь ^^

+0

Я получил его. Вместо использования исходящего шлюза я должен был использовать ** FileWritingMessageHandler ** в serviceActivator и предоставить преобразованную версию моего сообщения. – Iob

ответ

0

Использование трансформатора для преобразования сообщения DOM в сообщение String и отправки его активисту службы. например, так:

<int-ws:inbound-gateway id="ws-inbound-gateway" request-channel="input"/> 

    <int:channel id="input"/> 

    <int:transformer input-channel="input" output-channel="transform" > 
     <bean class="org.springframework.integration.samples.ws.SimpleTransformerResponder"/> 
    </int:transformer> 

    <int:channel id="transform"/> 

    <int:service-activator input-channel="transform" output-channel="next"> 
     <bean class="org.springframework.integration.file.FileWritingMessageHandler" > 
      <constructor-arg name="destinationDirectory" value="file:${java.io.tmpdir}/"/> 
     </bean> 
    </int:service-activator> 

    <int:channel id="next"/> 

    <int:service-activator input-channel="next"> 
     <bean class="org.springframework.integration.samples.ws.SimpleEchoResponder" /> 
    </int:service-activator> 

трансформатор фасоли:

public class SimpleTransformerResponder { 
    public String transform(DOMSource request) { 
     return request.getNode().getTextContent(); 
    } 
} 

и фасоль ответ

public class SimpleEchoResponder { 

    public Source issueResponseFor(File request) { 
     return new DomSourceFactory().createSource(
       "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">" + 
         request.getAbsoluteFile() + "</echoResponse>"); 
    } 

} 

результатом является файл с содержанием исходного сообщения, созданного, и ответ содержит путь созданного файла.

«Учимся трудным ^^»

Смежные вопросы