import de.spring.webservices.auto.ExampleRequest;
import de.spring.webservices.auto.ExampleResponse;
import de.spring.webservices.auto.ObjectFactory;
-import de.spring.webservices.porttypes.PortType;
+import de.spring.webservices.operations.Operations;
/**
* Example of business class
*
*/
-public class BusinessExample implements PortType.RequestResponse<ExampleResponse, ExampleRequest> {
+public class BusinessExample implements Operations.RequestResponse<ExampleResponse, ExampleRequest> {
@Override
public ExampleResponse requestResponse(final ExampleRequest request) {
package de.spring.webservices.client;
-import org.springframework.oxm.jaxb.Jaxb2Marshaller;
-import org.springframework.ws.client.core.WebServiceTemplate;
-import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
-
+import localhost._8888.spring_ws.example.ExampleRequest;
import localhost._8888.spring_ws.example.ExampleResponse;
import localhost._8888.spring_ws.example.Examples;
import localhost._8888.spring_ws.example.ExamplesService;
-import localhost._8888.spring_ws.example.ExampleRequest;
+import localhost._8888.spring_ws.example.ObjectFactory;
+import org.springframework.ws.client.core.WebServiceTemplate;
+
+/**
+ * Someone could write code like this one in order to send and receive
+ * information from our Web Services.
+ *
+ */
public class ExampleClient {
private WebServiceTemplate webServiceTemplate;
private String Uri;
-
- public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
+
+ public void setWebServiceTemplate(
+ final WebServiceTemplate webServiceTemplate) {
this.webServiceTemplate = webServiceTemplate;
}
-
- public void setDefaultUri(String defaultUri) {
+
+ public void setDefaultUri(final String defaultUri) {
this.Uri = defaultUri;
}
-
+
public void sendAndReceive() {
- //Examples exampleService = new ExamplesService().getExamplesSoap11();
- ExampleRequest exampleRequest = new ExampleRequest();
- exampleRequest.setData("I am John Smith.");
- //exampleService.example(exampleRequest);
-
-
+ final Examples exampleService = new ExamplesService().getExamplesSoap11();
+ final ExampleRequest exampleRequest = new ObjectFactory().createExampleRequest();
+ exampleRequest.setData("SCARLETT. IT IS CANON.");
+
+ //There are two options O.o:
+
+ //1. Through Java:
+ ExampleResponse exampleResponse = exampleService.example(exampleRequest);
+ System.out.println(exampleResponse.getData());
+
+ //2. Using Spring:
this.webServiceTemplate.setDefaultUri(this.Uri);
- ExampleResponse exampleResponse =
- (ExampleResponse) this.webServiceTemplate.marshalSendAndReceive(exampleRequest);
-
+ exampleResponse = (ExampleResponse)
+ this.webServiceTemplate.marshalSendAndReceive(exampleRequest);
+
System.out.println(exampleResponse.getData());
}
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- ExampleClient prueba = new ExampleClient();
- SaajSoapMessageFactory joer = new SaajSoapMessageFactory();
- joer.afterPropertiesSet();
- WebServiceTemplate laleche = new WebServiceTemplate(joer);
- laleche.afterPropertiesSet();
- laleche.setMarshaller(new Jaxb2Marshaller());
-
- prueba.setDefaultUri("http://localhost:8888/spring-ws/example");
- prueba.setWebServiceTemplate(laleche);
- prueba.sendAndReceive();
- }
}
--- /dev/null
+package de.spring.webservices.client;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * This class is used just like a nice example about how to write and run client
+ * code which will send data to and from the Web Services.
+ *
+ */
+public class Test {
+ public ApplicationContext context;
+
+ /**
+ * @param args
+ */
+ public static void main(final String[] args) {
+ final Test test = new Test();
+
+ test.context = new ClassPathXmlApplicationContext(
+ "client-spring-configuration.xml");
+
+ final ExampleClient example = (ExampleClient) test.context.getBean("exampleClient");
+
+ example.sendAndReceive();
+ }
+}
import de.spring.webservices.auto.ExampleRequest;
import de.spring.webservices.auto.ExampleResponse;
-import de.spring.webservices.porttypes.PortType;
+import de.spring.webservices.operations.Operations;
@Endpoint
public class ExampleEndPoint {
private static final String NAMESPACE_URI = "http://localhost:8888/spring-ws/example";
- private PortType.RequestResponse<ExampleResponse, ExampleRequest> example;
-
+ private Operations.RequestResponse<ExampleResponse, ExampleRequest> example;
+
public ExampleEndPoint() {}
- /*Este codigo debe ser escrito por los usuarios :(*/
- /*Los usuarios debe hacer lo siguiente en este proyecto:
- * 1. Crearse sus propios xsds
- * 2. Auto generar los objetos Request/Response asociados con sus xsds
- * 3. Crear los tests de integracion
- * 4. Generar este código y el setter para inyectar con Spring en este código
- * la clase que implementa el interfaz WebService. Esta clase será implementada en un proyecto
- * de negocio.
- *
- * Los usuarios deben hacer lo siguiente en sus proyectos:
- * 1. Implementar la clase del interfaz WebService
- * 2. Generar bean con dicha clase en su proyecto
- * 3. Inyectar ese bean en el bean de esta clase (lo dicho en puntos 4 y 5)
- * LOS USUARIOS TIENEN QUE HACER DEMASIADAS COSAS????? */
+
@PayloadRoot(localPart = "ExampleRequest", namespace = NAMESPACE_URI)
@ResponsePayload
public ExampleResponse order(
@RequestPayload final ExampleRequest requestObject,
@RequestPayload final Element element,
final MessageContext messageContext) {
-
- return example.requestResponse(requestObject);
+
+ return example.requestResponse(requestObject);
}
-
+
/** Setter required by Spring **/
public void setExample(
- PortType.RequestResponse<ExampleResponse, ExampleRequest> example) {
+ final Operations.RequestResponse<ExampleResponse, ExampleRequest> example) {
this.example = example;
}
}
--- /dev/null
+package de.spring.webservices.operations;
+
+/**
+ * <p>
+ * Operations: WSDL v1.1 and v2.0
+ * </p>
+ * See: <a href="http://www.w3.org/TR/wsdl#_porttypes">http://www.w3.org/TR/wsdl#_porttypes</a><br>
+ * See: <a href="http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns">
+ * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns</a>
+ *
+ */
+public interface Operations {
+
+ /**
+ * <p>
+ * Request-response operation WSDL v1.1
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/wsdl#_request-response">http://www.w3.org
+ * /TR/wsdl#_request-response</a>
+ *
+ * @param <T>
+ * Describes {@link Response}
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public static interface RequestResponse<T extends Response, E extends Request> {
+ T requestResponse(E request);
+ }
+
+ /**
+ * <p>
+ * One-way operation WSDL v1.1
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/wsdl#_one-way">http://www.w3.org/TR/wsdl
+ * #_one-way</a>
+ *
+ * @param <T>
+ * Describes {@link Response}
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public interface OneWay<E extends Request> {
+ void oneWay(E request);
+ }
+
+ /**
+ * <p>
+ * Notification operation WSDL v1.1
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/wsdl#_notification">http://www.w3.org/TR
+ * /wsdl#_notification</a>
+ *
+ * @param <T>
+ * Describes {@link Response}
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public interface Notification<T extends Response> {
+ T notification();
+ }
+
+ /**
+ * <p>
+ * In-Only message exchange pattern WSDL 2.0
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns">
+ * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns</a>
+ *
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public interface InOnly<E extends Request> {
+ void inOnly(E request);
+ }
+
+ /**
+ * <p>
+ * Robust In-Only message exchange pattern WSDL 2.0
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns">
+ * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns</a>
+ *
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public interface RobustInOnly<E extends Request> {
+ void robustInOnly(E request);
+ }
+
+ /**
+ * <p>
+ * In-Out message exchange pattern WSDL 2.0
+ * </p>
+ * See: <a
+ * href="http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns">
+ * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns</a>
+ *
+ * @param <T>
+ * Describes {@link Response}
+ * @param <E>
+ * Describes {@link Request}
+ */
+ public interface InOut<T extends Response, E extends Request> {
+ T inOut(E request);
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.spring.webservices.operations;
+
+public interface Request {
+
+}
--- /dev/null
+package de.spring.webservices.operations;
+
+public interface Response {
+
+}
+++ /dev/null
-package de.spring.webservices.porttypes;
-
-/**
- * <p>
- * WSDL 1.1 Port Types
- * </p>
- * <p>
- * WSDL 2.0 is different, so this interface just works with 1.1. Indeed I should
- * not implement this interface because of the differences between 2.0 and 1.1 but I
- * am doing it because I want to improve my skills related to Java Generics.
- * </p>
- * See: <a
- * href="http://www.w3.org/TR/wsdl#_porttypes">http://www.w3.org/TR/wsdl#
- * _porttypes</a>
- *
- */
-public interface PortType<E extends Request, T extends Response> {
-
- /**
- * <p>
- * Request-response operation
- * </p>
- * See: <a
- * href="http://www.w3.org/TR/wsdl#_request-response">http://www.w3.org
- * /TR/wsdl#_request-response</a>
- *
- * @param <T>
- * Describes {@link Response}
- * @param <E>
- * Describes {@link Request}
- */
- public interface RequestResponse<T, E> {
- T requestResponse(E request);
- }
-
- /**
- * <p>
- * One-way operation
- * </p>
- * See: <a
- * href="http://www.w3.org/TR/wsdl#_one-way">http://www.w3.org/TR/wsdl
- * #_one-way</a>
- *
- * @param <T>
- * Describes {@link Response}
- * @param <E>
- * Describes {@link Request}
- */
- public interface OneWay<E> {
- void oneWay(E request);
- }
-
- /**
- * <p>
- * Notification operation
- * </p>
- * See: <a
- * href="http://www.w3.org/TR/wsdl#_notification">http://www.w3.org/TR
- * /wsdl#_notification</a>
- *
- * @param <T>
- * Describes {@link Response}
- * @param <E>
- * Describes {@link Request}
- */
- public interface Notification<T> {
- T notification();
- }
-}
+++ /dev/null
-package de.spring.webservices.porttypes;
-
-public interface Request {
-
-}
+++ /dev/null
-package de.spring.webservices.porttypes;
-
-public interface Response {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:sws="http://www.springframework.org/schema/web-services"
+ xmlns:oxm="http://www.springframework.org/schema/oxm"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/web-services
+ http://www.springframework.org/schema/web-services/web-services-2.0.xsd
+ http://www.springframework.org/schema/oxm
+ http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">
+
+ <!--
+ This file is an example about how someone should write code in order to send and
+ receive data from the Web Services.
+ -->
+
+ <context:component-scan base-package="de.spring.webservices"/>
+
+ <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
+
+
+ <oxm:jaxb2-marshaller id="marshaller" contextPath="localhost._8888.spring_ws.example"/>
+
+ <!-- ¿Este validador funciona teniendo inheritance en el xsd? (inheritances es una cosa especial
+ del JAXB2 que estoy usando para generar las clases desde el xsd)
+ El marshal lo estoy haciendo con JAXB2 (lo que no sé es que JAXB2 está realmente usando
+ pues me parece que hay varios en el classpath) y funciona, así que supongo que el
+ validador también :/
+ Lo que realmente tampoco sé es si hay alguna relación entre los validadores y JAXB2 :/
+ -->
+ <bean id="payloadValidatingInterceptor"
+ class="org.springframework.ws.client.support.interceptor.PayloadValidatingInterceptor">
+ <property name="schema" value="classpath:xsd/examples.xsd"/>
+ <property name="validateRequest" value="true"/>
+ <property name="validateResponse" value="true"/>
+ </bean>
+
+ <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
+ <constructor-arg ref="messageFactory"/>
+ <property name="marshaller" ref="marshaller" />
+ <property name="unmarshaller" ref="marshaller" />
+ <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
+ <property name="interceptors">
+ <list>
+ <ref bean="payloadValidatingInterceptor" />
+ </list>
+ </property>
+ </bean>
+
+ <bean id="exampleClient" class="de.spring.webservices.client.ExampleClient">
+ <property name="webServiceTemplate" ref="webServiceTemplate"/>
+ <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
+ </bean>
+
+</beans>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="de.spring.webservices"/>
+ <!--
+ Aqui se podría especificar un unmarshaller (para la request) o un
+ marshaller (para la response) especifico. Por ejemplo Castor.
+
+ Por la anotacion que uso para el EndPoint y porque tengo JAXB2 en el
+ classpath, creo que Spring lo que está haciendo es el equivalente ha si se
+ escribiera lo siguiente:
+
+ <oxm:jaxb2-marshaller id="marshaller" contextPath="de.spring.webservices.auto"/>
+
+ <sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller"/>
+ -->
<sws:annotation-driven/>
<sws:dynamic-wsdl id="example"
</bean>
</sws:interceptors>
+ <!--
+ ¿Este validador funciona teniendo inheritance en el xsd? (inheritances es una cosa especial
+ del JAXB2 que estoy usando para generar las clases desde el xsd)
+ Parece que el unmarshal (que supongo que se hace con el JAXB2 que está en el classpath
+ debido al tipo de Endpoint que estoy usando, que por cierto no sé cual JAXB2 está cogiendo realmente)
+ funciona, así que supongo el validador tambien :/
+ Lo que realmente tampoco sé es si hay alguna relación entre los validadores y JAXB2 :/
+ -->
<bean id="validatingInterceptor"
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="schema" value="classpath:xsd/examples.xsd"/>
<property name="example" ref="exampleBusiness" />
</bean>
-
- <!-- CLIENT -->
- <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
-
- <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
- <constructor-arg ref="messageFactory"/>
- <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
- </bean>
-
- <bean id="exampleClient" class="de.spring.webservices.client.ExampleClient">
- <property name="webServiceTemplate" ref="webServiceTemplate"/>
- <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
- </bean>
-
</beans>
<xs:complexType>
<xs:annotation>
<xs:appinfo>
- <inheritance:implements>de.spring.webservices.porttypes.Request</inheritance:implements>
+ <inheritance:implements>de.spring.webservices.operations.Request</inheritance:implements>
</xs:appinfo>
</xs:annotation>
<xs:all>
<xs:complexType>
<xs:annotation>
<xs:appinfo>
- <inheritance:implements>de.spring.webservices.porttypes.Response</inheritance:implements>
+ <inheritance:implements>de.spring.webservices.operations.Response</inheritance:implements>
</xs:appinfo>
</xs:annotation>
<xs:all>
<xs:complexType>
<xs:annotation>
<xs:appinfo>
- <inheritance:implements>de.spring.webservices.porttypes.Request</inheritance:implements>
+ <inheritance:implements>de.spring.webservices.operations.Request</inheritance:implements>
</xs:appinfo>
</xs:annotation>
<xs:all>
<xs:complexType>
<xs:annotation>
<xs:appinfo>
- <inheritance:implements>de.spring.webservices.porttypes.Response</inheritance:implements>
+ <inheritance:implements>de.spring.webservices.operations.Response</inheritance:implements>
</xs:appinfo>
</xs:annotation>
<xs:all>
+++ /dev/null
-package de.spring.webservices.tests;
-
-import static org.springframework.ws.test.server.RequestCreators.withPayload;
-import static org.springframework.ws.test.server.ResponseMatchers.payload;
-
-import javax.xml.transform.Source;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.ws.test.server.MockWebServiceClient;
-import org.springframework.xml.transform.StringSource;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration("/spring-configuration.xml")
-public class ExampleEndPointIntegrationTest {
-
- @Autowired
- private ApplicationContext applicationContext;
-
- private MockWebServiceClient mockClient;
-
- @Before
- public void createClient() {
- mockClient = MockWebServiceClient.createClient(applicationContext);
- }
-
- @Test
- public void exampleEndpoint() throws Exception {
- final Source requestPayload = new StringSource(
- "<ExampleRequest xmlns='http://localhost:8888/spring-ws/example'>" +
- "<data>SCARLETT</data>" +
- "</ExampleRequest>");
- final Source responsePayload = new StringSource(
- "<ns2:ExampleResponse xmlns:ns2='http://localhost:8888/spring-ws/example'>" +
- "<ns2:data>SNAKE EYES AND SCARLETT</ns2:data>" +
- "</ns2:ExampleResponse>");
- mockClient.sendRequest(withPayload(requestPayload)).andExpect(
- payload(responsePayload));
- }
-}
--- /dev/null
+package de.spring.webservices.tests.client;
+
+import static org.springframework.ws.test.client.RequestMatchers.payload;
+import static org.springframework.ws.test.client.ResponseCreators.withPayload;
+
+import javax.xml.transform.Source;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.ws.test.client.MockWebServiceServer;
+import org.springframework.xml.transform.StringSource;
+
+import de.spring.webservices.client.ExampleClient;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/client-spring-configuration.xml")
+public class ExampleClientIntegrationTest {
+
+ @Autowired
+ private ExampleClient client;
+
+ private MockWebServiceServer mockServer;
+
+ @Before
+ public void createServer() throws Exception {
+ // mockServer = MockWebServiceServer.createServer(client);
+ }
+
+ @Test
+ public void customerClient() throws Exception {
+ final Source requestPayload = new StringSource(
+ "<ExampleRequest xmlns='http://localhost:8888/spring-ws/example'>"
+ + "<data>SCARLETT. IT IS CANON.</data>"
+ + "</ExampleRequest>");
+ final Source responsePayload = new StringSource(
+ "<ns2:ExampleResponse xmlns:ns2='http://localhost:8888/spring-ws/example'>"
+ + "<ns2:data>SNAKE EYES AND SCARLETT. IT IS CANON.</ns2:data>"
+ + "</ns2:ExampleResponse>");
+ mockServer.expect(payload(requestPayload)).andRespond(
+ withPayload(responsePayload));
+
+ mockServer.verify();
+ }
+}
--- /dev/null
+package de.spring.webservices.tests.server;
+
+import static org.springframework.ws.test.server.RequestCreators.withPayload;
+import static org.springframework.ws.test.server.ResponseMatchers.payload;
+
+import javax.xml.transform.Source;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.ws.test.server.MockWebServiceClient;
+import org.springframework.xml.transform.StringSource;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/spring-configuration.xml")
+public class ExampleEndPointIntegrationTest {
+
+ @Autowired
+ private ApplicationContext applicationContext;
+
+ private MockWebServiceClient mockClient;
+
+ @Before
+ public void createClient() {
+ mockClient = MockWebServiceClient.createClient(applicationContext);
+ }
+
+ @Test
+ public void exampleEndpoint() throws Exception {
+ final Source requestPayload = new StringSource(
+ "<ExampleRequest xmlns='http://localhost:8888/spring-ws/example'>" +
+ "<data>SCARLETT</data>" +
+ "</ExampleRequest>");
+ final Source responsePayload = new StringSource(
+ "<ns2:ExampleResponse xmlns:ns2='http://localhost:8888/spring-ws/example'>" +
+ "<ns2:data>SNAKE EYES AND SCARLETT</ns2:data>" +
+ "</ns2:ExampleResponse>");
+ mockClient.sendRequest(withPayload(requestPayload)).andExpect(
+ payload(responsePayload));
+ }
+}