如何通过Spring Integration出站网关使用4个字符串参数涉及Web服务方法



我已经设置了网关和服务,但是Web方法不是包装的对象,而只是4个字符串。

jaxb提出了错误

" javax.xml.bind.marshalexception - 链接的例外:[com.sun.istack.internal.saxexception2:由于缺少@xmlrootelement注释而无法元使用" java.lang.string"作为元素]"

public interface WebMethodGateway {
    @Gateway
    @Payload("#args[0] + #args[1] + #args[2] + #args[3]")
    public Response invoke(String arg1, String arg2, String arg3, String arg4);
}

Integration.xml

<int-ws:outbound-gateway id="outboundGateway"
    request-channel="requestChannel" 
    reply-channel="responseChannel"
    uri="http://localhost:8080/Service?wsdl"
    message-sender="messageSender" 
    marshaller="marshaller"
    unmarshaller="marshaller"/>
<bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
    <property name="connectionTimeout" value="5000"/>
    <property name="readTimeout" value="10000"/>
</bean>

<int:channel id="requestChannel"/>
<int:channel id="responseChannel"/>
<oxm:jaxb2-marshaller id="marshaller" context-path="myProject.ws.bean" />
<int:gateway id="webMethodGateway" 
    default-request-channel="requestChannel"
    default-reply-channel="responseChannel"
    service-interface="myProject.ws.gateway.WebMethodGateway" />

首先,它不是 4 Strings,它是单个串联的字符串:

@Payload("#args[0] + #args[1] + #args[2] + #args[3]")

另一个问题。

<int-ws:outbound-gateway>用于Web服务,肥皂。因此XML。右JAXB为您生产XML,但它完全用于域实体,而不是简单的字符串。

您可以使用字符串payload绕过JAXB,但这确实必须是代表<soap:body>内容的XML。

最新更新