网站模板下载html,免费ftp服务器申请网站,周口在线网站建设,锦州哪家做网站介绍 在Spring Integration的支持下#xff0c;您的应用程序可以使用出站Web服务网关来调用Web服务。 调用由该网关处理#xff0c;因此您只需要担心构建请求消息和处理响应。 但是#xff0c;使用这种方法并不明显#xff0c;如何配置其他选项#xff0c;例如设置超时或操… 介绍 在Spring Integration的支持下您的应用程序可以使用出站Web服务网关来调用Web服务。 调用由该网关处理因此您只需要担心构建请求消息和处理响应。 但是使用这种方法并不明显如何配置其他选项例如设置超时或操作缓存。 本文将展示如何设置客户端超时并将其与网关集成。 本文分为以下几节 介绍。 Web服务调用概述。 配置消息发件人。 示例应用程序。 结论。 源代码可以在github上找到。 Web服务调用概述 Web服务出站网关将Web服务调用委托给Spring Web Services WebServiceTemplate 。 当消息到达出站网关时此模板使用消息发件人以创建新连接。 下图显示了该流程的概述 默认情况下Web服务模板将HttpUrlConnectionMessageSender设置为其消息发送者这是不支持配置选项的基本实现。 但是可以通过设置具有设置读取和连接超时能力的更高级的消息发送者来覆盖此行为。 我们将在下一部分中配置消息发送者。 配置消息发件人 我们将配置消息发件人到出站网关。 这样网关将使用提供的模板设置模板的消息发送者。 我们在示例中提供的实现是HttpComponentsMessageSender类该类也来自Spring Web Services项目。 该消息发件人允许我们定义以下超时 connectionTimeout 设置建立连接之前的超时。 readTimeout 设置基础HttpClient的套接字超时。 这是服务回复所需的时间。 组态 bean idmessageSender classorg.springframework.ws.transport.http.HttpComponentsMessageSenderproperty nameconnectionTimeout value${timeout.connection}/property namereadTimeout value${timeout.read}/
/bean 属性文件包含两个值它们都设置为两秒钟 timeout.connection 2000 timeout.read 2000 配置完成后我们将其添加到Web服务出站网关配置中 int-ws:outbound-gateway urihttp://localhost:8080/spring-ws-courses/courses marshallermarshaller unmarshallermarshaller request-channelrequestChannel message-sendermessageSender/ 要使用此消息发件人您将需要添加以下依赖项 dependencygroupIdorg.apache.httpcomponents/groupIdartifactIdhttpclient/artifactIdversion4.3.3/version
/dependency 就是这样 下一部分将显示示例应用程序以查看其工作方式。 样例应用 流程很简单 它包含一个向Web服务发送请求并接收响应的应用程序。 Web服务源代码可以在github上找到。 beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:inthttp://www.springframework.org/schema/integrationxmlns:int-wshttp://www.springframework.org/schema/integration/wsxmlns:oxmhttp://www.springframework.org/schema/oxmxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsdhttp://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsdhttp://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsdcontext:component-scan base-packagexpadro.spring.integration.ws/context:property-placeholder locationclasspath:props/service.properties/!-- System entry --int:gateway idsystemEntry default-request-channelrequestChannel service-interfacexpadro.spring.integration.ws.gateway.CourseService/!-- Web service invocation --int-ws:outbound-gateway urihttp://localhost:8080/spring-ws-courses/courses marshallermarshaller unmarshallermarshaller request-channelrequestChannel message-sendermessageSender/oxm:jaxb2-marshaller idmarshaller contextPathxpadro.spring.integration.ws.types /bean idmessageSender classorg.springframework.ws.transport.http.HttpComponentsMessageSenderproperty nameconnectionTimeout value${timeout.connection}/property namereadTimeout value${timeout.read}//bean/beans 网关包含我们将进入消息传递系统的方法 public interface CourseService {GatewayGetCourseResponse getCourse(GetCourseRequest request);
} 最后测试 ContextConfiguration(locations {/xpadro/spring/integration/ws/config/int-course-config.xml})
RunWith(SpringJUnit4ClassRunner.class)
public class TestIntegrationApp {Autowiredprivate CourseService service;Testpublic void invokeNormalOperation() {GetCourseRequest request new GetCourseRequest();request.setCourseId(BC-45);GetCourseResponse response service.getCourse(request);assertNotNull(response);assertEquals(Introduction to Java, response.getName());}Testpublic void invokeTimeoutOperation() {try {GetCourseRequest request new GetCourseRequest();request.setCourseId(DF-21);GetCourseResponse response service.getCourse(request);assertNull(response);} catch (WebServiceIOException e) {assertTrue(e.getCause() instanceof SocketTimeoutException);}}
}结论 我们已经学习了如何为Web服务出站网关设置其他选项以建立超时。 在下一篇文章中我将解释如何缓存此调用。 翻译自: https://www.javacodegeeks.com/2014/05/spring-integration-configure-web-service-client-timeout.html