gpt4 book ai didi

spring-ws - 将 spring-ws 实现转换为 spring-integration-ws 实现

转载 作者:行者123 更新时间:2023-12-02 05:05:56 31 4
gpt4 key购买 nike

我有一个使用 spring-ws 的 web 服务(服务器端)的实现。我想更改我的代码以使用 spring-integration-ws(ws:入站网关和 channel )。我已经尝试过示例,但仍然不确定是否可以转换我的实现。简而言之,我正在使用 @Endpoint、@PayloadRoot、PayloadRootAnnotationMethodEndpointMapping 和 JMS(作为传输)。请在下面找到我的实现:

端点类 (MyEndpoint.java):

@Endpoint
public class MyEndpoint {
@PayloadRoot(localPart="getUserRequest", namespace="http://play.zahid.springint/Jibx")
public GetUserResponse getUserResponse(GetUserRequest request){
log.info("Start getUserResponse " + request);
GetUserResponse response = new GetUserResponse();

User user = new User();
user.setFirstName(request.getFirstName());
user.setLastName(request.getFirstName() + " Last");
response.setUser(user);

log.info("End getUserResponse " + response);
return response;
}

@PayloadRoot(localPart="sayHiUserRequest", namespace="http://play.zahid.springint/Jibx")
public SayHiResponse sayHiUserResponse(SayHiUserRequest request){
log.info("Start sayHiUserResponse " + request);
SayHiUserResponse response = new SayHiUserResponse();

response.setResponse("Hi " + request.getFirstName() + " " + request.getLastName());

log.info("End sayHiUserResponse " + response);
return response;
}
}

spring xml文件(applicationContext.xml):

<bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="mqCachedConnectionFactory" />
<property name="destination" ref="defaultDestination" />
<property name="messageListener">
<bean class="org.springframework.ws.transport.jms.WebServiceMessageListener">
<property name="messageFactory" ref="messageFactory"/>
<property name="messageReceiver" ref="messageReceiver" />
</bean>
</property>
<property name="concurrentConsumers" value="1" />
<property name="acceptMessagesWhileStopping" value="false" />
<property name="recoveryInterval" value="10000" />
<property name="cacheLevelName" value="CACHE_CONSUMER" />
</bean>

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />

<bean id="messageReceiver" class="org.springframework.ws.soap.server.SoapMessageDispatcher">
<property name="endpointAdapters">
<list>
<bean id="endpointAdapter" class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<constructor-arg ref="marshaller" />
</bean>
</list>
</property>
</bean>

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />

为了简单起见,我删除了不必要的代码和 xml 配置。

是否可以保持我的端点类 (MyEndpoint.java) 不变并使用 spring-integration-ws 支持(ws:inbound-gateway 和 channel )?

如果您需要更多信息,请告诉我。

谢谢

最佳答案

Is there anyway to keep my endpoint class (MyEndpoint.java) as it is and use spring-integration-ws support (ws:inbound-gateway and channel)?

是的,你可以。

我将尝试针对您的情况解释一个简单的 integration-ws 实现:

applicationContext.xml:

<bean id="endpointMappings"
class="org.springframework.beans.factory.config.ListFactoryBean"
lazy-init="true">
<property name="sourceList">
<list>
<ref bean="uriEndpointMapping"/>
</list>
</property>
</bean>

<bean id="uriEndpointMapping"
class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping"
p:defaultEndpoint-ref="ws-inbound-gateway">
<property name="mappings">
<props>
<prop key="${yourEndPointUrl}">ws-inbound-gateway</prop>
</props>
</property>
</bean>

<int-ws:inbound-gateway id="ws-inbound-gateway"
request-channel="ws-request-channel"
reply-channel="ws-response-channel"
error-channel="ws-error-channel"
marshaller="marshaller"
unmarshaller="marshaller"/>

<int:channel id="ws-request-channel"/>
<int:channel id="ws-response-channel"/>
<int:channel id="ws-error-channel"/>

<int:chain input-channel="ws-request-channel" output-channel="ws-response-channel">
<int:service-activator ref="yourBean" method="getUserResponse"/>
</int:chain>

这里有几点。你需要定义一个bean,MyEndpoint类型,我这里命名为yourBean
yourEndPointUrl 定义了 getUserResponse 方法的终点 URL。
我在一个链中定义了service-activator,你可以在这个链中添加日志记录或其他东西来丰富你的处理机制。
您还需要一个路由器,用于将请求路由到 bean 的不同方法。

关于spring-ws - 将 spring-ws 实现转换为 spring-integration-ws 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11776062/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com