() {
62 | @Override
63 | public Integer doInJms(Session session, QueueBrowser browser) throws JMSException {
64 | Enumeration> messages = browser.getEnumeration();
65 | int total = 0;
66 | while (messages.hasMoreElements()) {
67 | messages.nextElement();
68 | total++;
69 | }
70 |
71 | return total;
72 | }
73 | });
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/webservices/README.md:
--------------------------------------------------------------------------------
1 | # WEB SERVICES
2 | Spring Integration Web Services support
3 | #### Version 3
4 | Examples using Spring Integration 3 release:
5 |
6 | * [spring-ws] - Shows how to implement a web service with the Spring-WS module. The example starts with a sample XML document and uses it to generate the contract. This project uses JAXB2 to generate the Java objects.
7 | * Blog post: http://xpadro.com/2013/09/creating-contract-first-web-services_30.html
8 |
9 | * [ws-retry-adv] - Allows to retry a web service operation using RequestHandlerRetryAdvice. The project spring-ws from this same repository needs to be deployed on the server to test a succesful invocation. Otherwise, it will keep retrying invocations until it reaches a max retries limit. If the limit is reached, it will store the request to a mongoDB database (a mongod instance needs to be running).
10 | * Blog post: http://xpadro.com/2013/12/retry-web-service-operations-with.html
11 |
12 | * [ws-retry] - A custom version of the int-ws-retry-adv project without the support of Spring Retry. This application uses a cron trigger with an inbound adapter to accomplish the same functionality.
13 |
14 | * [ws-timeout] - Example of how to configure a timeout for invoking a web service through a web service outbound gateway. The web service's source code can be found at https://github.com/xpadro/spring-samples/tree/master/spring-ws-courses
15 | * Blog post: http://xpadro.com/2014/04/spring-integration-configure-web.html
16 |
17 |
18 |
19 | [spring-ws]: https://github.com/xpadro/spring-integration/tree/master/webservices/spring-ws
20 | [ws-retry-adv]: https://github.com/xpadro/spring-integration/tree/master/webservices/ws-retry-adv
21 | [ws-retry]: https://github.com/xpadro/spring-integration/tree/master/webservices/ws-retry
22 | [ws-timeout]: https://github.com/xpadro/spring-integration/tree/master/webservices/ws-timeout
23 |
--------------------------------------------------------------------------------
/webservices/spring-ws/generate-classes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/webservices/spring-ws/generate-schema.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/webservices/spring-ws/lib/trang.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xpadro/spring-integration/1e7743f1308b793123a8b7cd2171c20277e3a22f/webservices/spring-ws/lib/trang.jar
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/OrderEndpoint.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Date;
5 | import java.util.GregorianCalendar;
6 |
7 | import javax.xml.datatype.DatatypeConfigurationException;
8 | import javax.xml.datatype.DatatypeFactory;
9 | import javax.xml.datatype.XMLGregorianCalendar;
10 |
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.ws.server.endpoint.annotation.Endpoint;
13 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
14 | import org.springframework.ws.server.endpoint.annotation.RequestPayload;
15 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
16 |
17 | import xpadro.spring.ws.exception.OrderFormatDateException;
18 | import xpadro.spring.ws.model.OrderConfirmation;
19 | import xpadro.spring.ws.service.OrderService;
20 | import xpadro.spring.ws.types.ClientDataRequest;
21 | import xpadro.spring.ws.types.ClientDataResponse;
22 |
23 | @Endpoint
24 | public class OrderEndpoint {
25 |
26 | @Autowired
27 | private OrderService orderService;
28 |
29 | @PayloadRoot(localPart="clientDataRequest", namespace="http://www.xpadro.spring.samples.com/orders")
30 | public @ResponsePayload ClientDataResponse order(@RequestPayload ClientDataRequest orderData) {
31 | OrderConfirmation confirmation =
32 | orderService.order(orderData.getClientId(), orderData.getProductId(), orderData.getQuantity().intValue());
33 |
34 | ClientDataResponse response = new ClientDataResponse();
35 | response.setConfirmationId(confirmation.getConfirmationId());
36 | BigDecimal amount = new BigDecimal(Float.toString(confirmation.getAmount()));
37 | response.setAmount(amount);
38 | response.setOrderDate(convertDate(confirmation.getOrderDate()));
39 |
40 | return response;
41 | }
42 |
43 | private XMLGregorianCalendar convertDate(Date serviceDate) {
44 | GregorianCalendar calendar = new GregorianCalendar();
45 | calendar.setTime(serviceDate);
46 | try {
47 | return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
48 | } catch (DatatypeConfigurationException e) {
49 | throw new OrderFormatDateException();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/exception/ClientNotFoundException.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.exception;
2 |
3 |
4 | public class ClientNotFoundException extends RuntimeException {
5 | private static final long serialVersionUID = 1L;
6 |
7 | public ClientNotFoundException(String message) {
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/exception/OrderFormatDateException.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.exception;
2 |
3 |
4 | public class OrderFormatDateException extends RuntimeException {
5 | private static final long serialVersionUID = 1L;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/model/OrderConfirmation.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.model;
2 |
3 | import java.util.Date;
4 |
5 | public class OrderConfirmation {
6 |
7 | private String confirmationId;
8 | private float amount;
9 | private Date orderDate;
10 |
11 |
12 | public String getConfirmationId() {
13 | return confirmationId;
14 | }
15 |
16 | public void setConfirmationId(String confirmationId) {
17 | this.confirmationId = confirmationId;
18 | }
19 |
20 | public float getAmount() {
21 | return amount;
22 | }
23 |
24 | public void setAmount(float amount) {
25 | this.amount = amount;
26 | }
27 |
28 | public Date getOrderDate() {
29 | return orderDate;
30 | }
31 |
32 | public void setOrderDate(Date orderDate) {
33 | this.orderDate = orderDate;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/service/OrderService.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.service;
2 |
3 | import xpadro.spring.ws.model.OrderConfirmation;
4 |
5 | public interface OrderService {
6 |
7 | public OrderConfirmation order(String clientId, String productId, int quantity);
8 | }
9 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/service/impl/StubOrderService.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.service.impl;
2 |
3 | import java.util.Calendar;
4 |
5 | import org.springframework.stereotype.Service;
6 |
7 | import xpadro.spring.ws.exception.ClientNotFoundException;
8 | import xpadro.spring.ws.model.OrderConfirmation;
9 | import xpadro.spring.ws.service.OrderService;
10 |
11 | @Service
12 | public class StubOrderService implements OrderService {
13 | private static final String VALID_CLIENT_ID = "123";
14 |
15 | @Override
16 | public OrderConfirmation order(String clientId, String productId, int quantity) {
17 | if (!VALID_CLIENT_ID.equals(clientId)) {
18 | throw new ClientNotFoundException("Client ["+clientId+"] not found");
19 | }
20 |
21 | OrderConfirmation response = new OrderConfirmation();
22 | response.setAmount(55.99f);
23 | response.setConfirmationId("GHKG34L");
24 | Calendar cal = Calendar.getInstance();
25 | cal.set(2013, 9, 26);
26 | response.setOrderDate(cal.getTime());
27 |
28 | return response;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/types/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 |
9 | package xpadro.spring.ws.types;
10 |
11 | import javax.xml.bind.annotation.XmlRegistry;
12 |
13 |
14 | /**
15 | * This object contains factory methods for each
16 | * Java content interface and Java element interface
17 | * generated in the xpadro.spring.ws.types package.
18 | * An ObjectFactory allows you to programatically
19 | * construct new instances of the Java representation
20 | * for XML content. The Java representation of XML
21 | * content can consist of schema derived interfaces
22 | * and classes representing the binding of schema
23 | * type definitions, element declarations and model
24 | * groups. Factory methods for each of these are
25 | * provided in this class.
26 | *
27 | */
28 | @XmlRegistry
29 | public class ObjectFactory {
30 |
31 |
32 | /**
33 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: xpadro.spring.ws.types
34 | *
35 | */
36 | public ObjectFactory() {
37 | }
38 |
39 | /**
40 | * Create an instance of {@link ClientDataRequest }
41 | *
42 | */
43 | public ClientDataRequest createClientDataRequest() {
44 | return new ClientDataRequest();
45 | }
46 |
47 | /**
48 | * Create an instance of {@link ClientDataResponse }
49 | *
50 | */
51 | public ClientDataResponse createClientDataResponse() {
52 | return new ClientDataResponse();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/java/xpadro/spring/ws/types/package-info.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.xpadro.spring.samples.com/orders")
9 | package xpadro.spring.ws.types;
10 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/resources/xpadro/spring/ws/config/root-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/resources/xpadro/spring/ws/config/servlet-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/schemas/samples/client-request.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/schemas/samples/client-response.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/schemas/xsd/client-request.xsd:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/schemas/xsd/client-response.xsd:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/schemas/xsd/client-service.xsd:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 | contextConfigLocation
9 | classpath:xpadro/spring/ws/config/root-config.xml
10 |
11 |
12 |
13 | org.springframework.web.context.ContextLoaderListener
14 |
15 |
16 |
17 | orders
18 | org.springframework.ws.transport.http.MessageDispatcherServlet
19 |
20 | contextConfigLocation
21 | classpath:xpadro/spring/ws/config/servlet-config.xml
22 |
23 | 1
24 |
25 |
26 |
27 | orders
28 | /orders/*
29 |
30 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/test/java/xpadro/spring/ws/test/TestClient.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.ws.test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.math.BigDecimal;
7 | import java.math.BigInteger;
8 |
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.test.context.ContextConfiguration;
13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 | import org.springframework.ws.client.core.WebServiceTemplate;
15 |
16 | import xpadro.spring.ws.types.ClientDataRequest;
17 | import xpadro.spring.ws.types.ClientDataResponse;
18 |
19 | @ContextConfiguration("classpath:xpadro/spring/ws/test/config/client-config.xml")
20 | @RunWith(SpringJUnit4ClassRunner.class)
21 | public class TestClient {
22 | @Autowired
23 | WebServiceTemplate wsTemplate;
24 |
25 | @Test
26 | public void invokeOrderService() throws Exception {
27 | ClientDataRequest request = new ClientDataRequest();
28 | request.setClientId("123");
29 | request.setProductId("XA-55");
30 | request.setQuantity(new BigInteger("5", 10));
31 |
32 | ClientDataResponse response = (ClientDataResponse) wsTemplate.marshalSendAndReceive(request);
33 |
34 | assertNotNull(response);
35 | assertEquals(new BigDecimal("55.99"), response.getAmount());
36 | assertEquals("GHKG34L", response.getConfirmationId());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/test/resources/xpadro/spring/ws/test/config/client-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/webservices/spring-ws/src/test/resources/xpadro/spring/ws/test/config/test-server-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/xpadro/spring/integration/activator/ClientServiceActivator.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.activator;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.integration.Message;
6 | import org.springframework.integration.MessagingException;
7 | import org.springframework.stereotype.Component;
8 |
9 | import xpadro.spring.integration.types.ClientDataResponse;
10 |
11 | @Component("clientServiceActivator")
12 | public class ClientServiceActivator {
13 | private Logger logger = LoggerFactory.getLogger(this.getClass());
14 |
15 |
16 | /**
17 | * Receives the result from a succesful service invocation. Flow finishes here.
18 | * @param msg
19 | */
20 | public void handleServiceResult(Message> msg) {
21 | logger.info("Service result received: {}", ((ClientDataResponse) msg.getPayload()).getConfirmationId());
22 | }
23 |
24 | /**
25 | * The service invocation won't succeed. Logs the failed request to the DB and finishes the flow.
26 | * @param exception
27 | */
28 | public Message> handleFailedInvocation(MessagingException exception) {
29 | logger.info("Failed to receive response. Request stored to DB...");
30 | return exception.getFailedMessage();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/xpadro/spring/integration/gateway/ClientService.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.gateway;
2 |
3 | import xpadro.spring.integration.types.ClientDataRequest;
4 |
5 | public interface ClientService {
6 |
7 | /**
8 | * Entry to the messaging system. All invocations to this method will be intercepted and sent to the SI "system entry" gateway
9 | *
10 | * @param request
11 | */
12 | public void invoke(ClientDataRequest request);
13 | }
14 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/xpadro/spring/integration/interceptor/ServiceClientInterceptor.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.interceptor;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.ws.client.WebServiceClientException;
7 | import org.springframework.ws.client.support.interceptor.ClientInterceptor;
8 | import org.springframework.ws.context.MessageContext;
9 |
10 | @Component("clientInterceptor")
11 | public class ServiceClientInterceptor implements ClientInterceptor {
12 | private Logger logger = LoggerFactory.getLogger(this.getClass());
13 |
14 | @Override
15 | public boolean handleFault(MessageContext context) throws WebServiceClientException {
16 | logger.info("handle fault");
17 | return true;
18 | }
19 |
20 | @Override
21 | public boolean handleRequest(MessageContext context) throws WebServiceClientException {
22 | logger.info("invoking service...");
23 |
24 | return true;
25 | }
26 |
27 | @Override
28 | public boolean handleResponse(MessageContext context) throws WebServiceClientException {
29 | logger.info("returning from service...");
30 |
31 | return true;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/xpadro/spring/integration/types/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 |
9 | package xpadro.spring.integration.types;
10 |
11 | import javax.xml.bind.annotation.XmlRegistry;
12 |
13 |
14 | /**
15 | * This object contains factory methods for each
16 | * Java content interface and Java element interface
17 | * generated in the xpadro.spring.ws.types package.
18 | *
An ObjectFactory allows you to programatically
19 | * construct new instances of the Java representation
20 | * for XML content. The Java representation of XML
21 | * content can consist of schema derived interfaces
22 | * and classes representing the binding of schema
23 | * type definitions, element declarations and model
24 | * groups. Factory methods for each of these are
25 | * provided in this class.
26 | *
27 | */
28 | @XmlRegistry
29 | public class ObjectFactory {
30 |
31 |
32 | /**
33 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: xpadro.spring.ws.types
34 | *
35 | */
36 | public ObjectFactory() {
37 | }
38 |
39 | /**
40 | * Create an instance of {@link ClientDataRequest }
41 | *
42 | */
43 | public ClientDataRequest createClientDataRequest() {
44 | return new ClientDataRequest();
45 | }
46 |
47 | /**
48 | * Create an instance of {@link ClientDataResponse }
49 | *
50 | */
51 | public ClientDataResponse createClientDataResponse() {
52 | return new ClientDataResponse();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/main/java/xpadro/spring/integration/types/package-info.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.xpadro.spring.samples.com/orders")
9 | package xpadro.spring.integration.types;
10 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/test/java/xpadro/spring/integration/TestInvocation.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration;
2 |
3 | import java.math.BigInteger;
4 | import java.util.concurrent.ExecutionException;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 | import xpadro.spring.integration.gateway.ClientService;
15 | import xpadro.spring.integration.types.ClientDataRequest;
16 |
17 | @ContextConfiguration({"classpath:xpadro/spring/integration/config/int-config.xml",
18 | "classpath:xpadro/spring/integration/config/mongodb-config.xml"})
19 | @RunWith(SpringJUnit4ClassRunner.class)
20 | public class TestInvocation {
21 | private Logger logger = LoggerFactory.getLogger(this.getClass());
22 |
23 | @Autowired
24 | private ClientService service;
25 |
26 | @Test
27 | public void testInvocation() throws InterruptedException, ExecutionException {
28 | logger.info("Initiating service request...");
29 |
30 | ClientDataRequest request = new ClientDataRequest();
31 | request.setClientId("123");
32 | request.setProductId("XA-55");
33 | request.setQuantity(new BigInteger("5"));
34 |
35 | service.invoke(request);
36 | logger.info("Doing other stuff...");
37 |
38 | Thread.sleep(60000);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/webservices/ws-retry-adv/src/test/resources/xpadro/spring/integration/config/mongodb-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/data/RequestData.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.data;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import xpadro.spring.integration.types.ClientDataRequest;
6 |
7 | /**
8 | * Stores the request that will be retrieved by the service activator when retrying the service invocation
9 | *
10 | */
11 | @Component("requestData")
12 | public class RequestData {
13 |
14 | private ClientDataRequest request;
15 |
16 | public ClientDataRequest getRequest() {
17 | return request;
18 | }
19 |
20 | public void setRequest(ClientDataRequest request) {
21 | this.request = request;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/gateway/ClientService.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.gateway;
2 |
3 | import xpadro.spring.integration.types.ClientDataRequest;
4 |
5 | public interface ClientService {
6 |
7 | /**
8 | * Entry to the messaging system. All invocations to this method will be intercepted and sent to the SI "system entry" gateway
9 | *
10 | * @param request
11 | */
12 | public void invoke(ClientDataRequest request);
13 | }
14 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/router/ServiceResultRouter.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.router;
2 |
3 | import java.util.concurrent.locks.ReentrantLock;
4 |
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.integration.Message;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component("resultRouter")
11 | public class ServiceResultRouter {
12 | private final ReentrantLock lock = new ReentrantLock();
13 |
14 | private Logger logger = LoggerFactory.getLogger(this.getClass());
15 |
16 | private int maxRetries = 3;
17 | private int currentRetries;
18 |
19 | private static final String FAIL_CHANNEL = "failedChannel";
20 | private static final String RETRY_CHANNEL = "retryChannel";
21 |
22 |
23 | /**
24 | * The service invocation failed. If maxRetries aren't reached, it will send the request to the retry channel. Otherwise, it will send the failed request
25 | * to the failed channel in order to log the request and finish the flow.
26 | * @param msg
27 | * @return
28 | */
29 | public String handleServiceError(Message> msg) {
30 | lock.lock();
31 | try {
32 | logger.info("Handling service failure");
33 | if (maxRetries > 0) {
34 | currentRetries++;
35 | if (currentRetries > maxRetries) {
36 | logger.info("Max retries [{}] reached", maxRetries);
37 | return FAIL_CHANNEL;
38 | }
39 | }
40 |
41 | logger.info("Retry number {} of {}", currentRetries, maxRetries);
42 | return RETRY_CHANNEL;
43 | } finally {
44 | lock.unlock();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/trigger/ServiceRetryTrigger.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.trigger;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.scheduling.Trigger;
6 | import org.springframework.scheduling.TriggerContext;
7 |
8 | public class ServiceRetryTrigger implements Trigger {
9 | private long rate;
10 |
11 |
12 | public long getRate() {
13 | return rate;
14 | }
15 |
16 | public void setRate(long rate) {
17 | this.rate = rate;
18 | }
19 |
20 |
21 | @Override
22 | public Date nextExecutionTime(TriggerContext triggerContext) {
23 | if (triggerContext.lastScheduledExecutionTime() == null) {
24 | return new Date(System.currentTimeMillis());
25 | }
26 |
27 | return new Date(triggerContext.lastScheduledExecutionTime().getTime() + getRate());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/types/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 |
9 | package xpadro.spring.integration.types;
10 |
11 | import javax.xml.bind.annotation.XmlRegistry;
12 |
13 |
14 | /**
15 | * This object contains factory methods for each
16 | * Java content interface and Java element interface
17 | * generated in the xpadro.spring.ws.types package.
18 | *
An ObjectFactory allows you to programatically
19 | * construct new instances of the Java representation
20 | * for XML content. The Java representation of XML
21 | * content can consist of schema derived interfaces
22 | * and classes representing the binding of schema
23 | * type definitions, element declarations and model
24 | * groups. Factory methods for each of these are
25 | * provided in this class.
26 | *
27 | */
28 | @XmlRegistry
29 | public class ObjectFactory {
30 |
31 |
32 | /**
33 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: xpadro.spring.ws.types
34 | *
35 | */
36 | public ObjectFactory() {
37 | }
38 |
39 | /**
40 | * Create an instance of {@link ClientDataRequest }
41 | *
42 | */
43 | public ClientDataRequest createClientDataRequest() {
44 | return new ClientDataRequest();
45 | }
46 |
47 | /**
48 | * Create an instance of {@link ClientDataResponse }
49 | *
50 | */
51 | public ClientDataResponse createClientDataResponse() {
52 | return new ClientDataResponse();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/main/java/xpadro/spring/integration/types/package-info.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2013.09.27 at 09:59:06 PM CEST
6 | //
7 |
8 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.xpadro.spring.samples.com/orders")
9 | package xpadro.spring.integration.types;
10 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/test/java/xpadro/spring/integration/TestInvocation.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration;
2 |
3 | import java.math.BigInteger;
4 | import java.util.concurrent.ExecutionException;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 | import xpadro.spring.integration.data.RequestData;
15 | import xpadro.spring.integration.gateway.ClientService;
16 | import xpadro.spring.integration.types.ClientDataRequest;
17 |
18 | @ContextConfiguration({"classpath:xpadro/spring/integration/config/int-config.xml",
19 | "classpath:xpadro/spring/integration/config/mongodb-config.xml"})
20 | @RunWith(SpringJUnit4ClassRunner.class)
21 | public class TestInvocation {
22 | private Logger logger = LoggerFactory.getLogger(this.getClass());
23 |
24 | @Autowired
25 | private ClientService service;
26 |
27 | @Autowired
28 | private RequestData requestData;
29 |
30 |
31 | @Test
32 | public void testInvocation() throws InterruptedException, ExecutionException {
33 | logger.info("Initiating service request...");
34 |
35 | ClientDataRequest request = new ClientDataRequest();
36 | request.setClientId("123");
37 | request.setProductId("XA-55");
38 | request.setQuantity(new BigInteger("5"));
39 | requestData.setRequest(request);
40 |
41 | service.invoke(request);
42 | logger.info("Doing other stuff...");
43 |
44 | Thread.sleep(60000);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/webservices/ws-retry/src/test/resources/xpadro/spring/integration/config/mongodb-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/java/xpadro/spring/integration/ws/gateway/CourseService.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.ws.gateway;
2 |
3 | import org.springframework.integration.annotation.Gateway;
4 |
5 | import xpadro.spring.integration.ws.types.GetCourseRequest;
6 | import xpadro.spring.integration.ws.types.GetCourseResponse;
7 |
8 | public interface CourseService {
9 |
10 | @Gateway
11 | GetCourseResponse getCourse(GetCourseRequest request);
12 | }
13 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/java/xpadro/spring/integration/ws/types/GetCourseListRequest.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2014.04.24 at 04:39:37 PM CEST
6 | //
7 |
8 |
9 | package xpadro.spring.integration.ws.types;
10 |
11 | import javax.xml.bind.annotation.XmlAccessType;
12 | import javax.xml.bind.annotation.XmlAccessorType;
13 | import javax.xml.bind.annotation.XmlRootElement;
14 | import javax.xml.bind.annotation.XmlType;
15 |
16 |
17 | /**
18 | *
Java class for anonymous complex type.
19 | *
20 | *
The following schema fragment specifies the expected content contained within this class.
21 | *
22 | *
23 | * <complexType>
24 | * <complexContent>
25 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26 | * </restriction>
27 | * </complexContent>
28 | * </complexType>
29 | *
30 | *
31 | *
32 | */
33 | @XmlAccessorType(XmlAccessType.FIELD)
34 | @XmlType(name = "")
35 | @XmlRootElement(name = "getCourseListRequest")
36 | public class GetCourseListRequest {
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/java/xpadro/spring/integration/ws/types/GetCourseRequest.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2014.04.24 at 04:39:37 PM CEST
6 | //
7 |
8 |
9 | package xpadro.spring.integration.ws.types;
10 |
11 | import javax.xml.bind.annotation.XmlAccessType;
12 | import javax.xml.bind.annotation.XmlAccessorType;
13 | import javax.xml.bind.annotation.XmlAttribute;
14 | import javax.xml.bind.annotation.XmlRootElement;
15 | import javax.xml.bind.annotation.XmlType;
16 |
17 |
18 | /**
19 | * Java class for anonymous complex type.
20 | *
21 | *
The following schema fragment specifies the expected content contained within this class.
22 | *
23 | *
24 | * <complexType>
25 | * <complexContent>
26 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
27 | * <attribute name="courseId" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
28 | * </restriction>
29 | * </complexContent>
30 | * </complexType>
31 | *
32 | *
33 | *
34 | */
35 | @XmlAccessorType(XmlAccessType.FIELD)
36 | @XmlType(name = "")
37 | @XmlRootElement(name = "getCourseRequest")
38 | public class GetCourseRequest {
39 |
40 | @XmlAttribute(name = "courseId", required = true)
41 | protected String courseId;
42 |
43 | /**
44 | * Gets the value of the courseId property.
45 | *
46 | * @return
47 | * possible object is
48 | * {@link String }
49 | *
50 | */
51 | public String getCourseId() {
52 | return courseId;
53 | }
54 |
55 | /**
56 | * Sets the value of the courseId property.
57 | *
58 | * @param value
59 | * allowed object is
60 | * {@link String }
61 | *
62 | */
63 | public void setCourseId(String value) {
64 | this.courseId = value;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/java/xpadro/spring/integration/ws/types/package-info.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2014.04.24 at 04:39:37 PM CEST
6 | //
7 |
8 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.xpadro.spring.samples.com/courses", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
9 | package xpadro.spring.integration.ws.types;
10 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/resources/props/service.properties:
--------------------------------------------------------------------------------
1 | timeout.connection=2000
2 | timeout.read=2000
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/main/resources/xpadro/spring/integration/ws/config/int-course-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/webservices/ws-timeout/src/test/java/xpadro/spring/integration/ws/test/TestIntegrationApp.java:
--------------------------------------------------------------------------------
1 | package xpadro.spring.integration.ws.test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 | import static org.junit.Assert.assertNull;
6 | import static org.junit.Assert.assertTrue;
7 |
8 | import java.net.SocketTimeoutException;
9 |
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 | import org.springframework.ws.client.WebServiceIOException;
16 |
17 | import xpadro.spring.integration.ws.gateway.CourseService;
18 | import xpadro.spring.integration.ws.types.GetCourseRequest;
19 | import xpadro.spring.integration.ws.types.GetCourseResponse;
20 |
21 | @ContextConfiguration(locations = {"/xpadro/spring/integration/ws/config/int-course-config.xml"})
22 | @RunWith(SpringJUnit4ClassRunner.class)
23 | public class TestIntegrationApp {
24 |
25 | @Autowired
26 | private CourseService service;
27 |
28 | @Test
29 | public void invokeNormalOperation() {
30 | GetCourseRequest request = new GetCourseRequest();
31 | request.setCourseId("BC-45");
32 |
33 | GetCourseResponse response = service.getCourse(request);
34 | assertNotNull(response);
35 | assertEquals("Introduction to Java", response.getName());
36 | }
37 |
38 | @Test
39 | public void invokeTimeoutOperation() {
40 | try {
41 | GetCourseRequest request = new GetCourseRequest();
42 | request.setCourseId("DF-21");
43 |
44 | GetCourseResponse response = service.getCourse(request);
45 | assertNull(response);
46 | } catch (WebServiceIOException e) {
47 | assertTrue(e.getCause() instanceof SocketTimeoutException);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------