Reworked stockquote sample to code config

This commit is contained in:
Arjen Poutsma
2014-04-29 10:13:54 +02:00
parent 3e7e422ba8
commit 64b59b9dcc
10 changed files with 116 additions and 102 deletions

View File

@@ -1,3 +1,6 @@
ext.springWsVersion = '2.2.0.BUILD-SNAPSHOT'
ext.springVersion = '4.0.3.RELEASE'
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
@@ -5,6 +8,7 @@ subprojects {
repositories {
maven { url 'http://repo.spring.io/libs-release' }
maven { url 'http://repo.spring.io/libs-snapshot' }
}
dependencies {
@@ -12,8 +16,4 @@ subprojects {
testCompile("org.easymock:easymock:3.1")
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
}

View File

@@ -1,5 +1,3 @@
ext.springWsVersion = '2.1.4.RELEASE'
dependencies {
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
runtime("log4j:log4j:1.2.16")

View File

@@ -20,8 +20,7 @@ import java.io.IOException;
import java.net.URI;
import javax.xml.transform.Source;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.addressing.client.ActionCallback;
@@ -51,10 +50,12 @@ public class StockClient extends WebServiceGatewaySupport {
System.out.println();
}
public static void main(String[] args) throws IOException {
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", StockClient.class);
StockClient stockClient = (StockClient) applicationContext.getBean("stockClient");
public static void main(String[] args) throws Exception {
StockClient stockClient = new StockClient();
stockClient.setDefaultUri("http://localhost:8080/StockService");
stockClient.setRequest(new ClassPathResource("/org/springframework/ws/samples/stockquote/client/sws/quotesRequest.xml"));
stockClient.setAction(new URI("http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote"));
stockClient.quotes();
}

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="stockClient" class="org.springframework.ws.samples.stockquote.client.sws.StockClient">
<property name="defaultUri" value="http://localhost:8080/StockService"/>
<property name="request"
value="classpath:org/springframework/ws/samples/stockquote/client/sws/quotesRequest.xml"/>
<property name="action"
value="http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote"/>
</bean>
</beans>

View File

@@ -2,9 +2,6 @@ configurations {
jaxb
}
ext.springVersion = '3.2.4.RELEASE'
ext.springWsVersion = '2.1.4.RELEASE'
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"

View File

@@ -17,18 +17,32 @@
package org.springframework.ws.samples.stockquote;
import java.io.IOException;
import java.net.InetSocketAddress;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.sun.net.httpserver.HttpServer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.ws.samples.stockquote.ws.StockServiceConfiguration;
import org.springframework.ws.transport.http.WebServiceMessageReceiverHttpHandler;
import org.springframework.ws.transport.http.WsdlDefinitionHttpHandler;
public class Driver {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", Driver.class);
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
StockServiceConfiguration.class);
HttpServer httpServer = HttpServer.create(new InetSocketAddress(8080), -1);
httpServer.createContext("/StockService", applicationContext.getBean(
WebServiceMessageReceiverHttpHandler.class));
httpServer.createContext("/StockService.wsdl", applicationContext.getBean(
WsdlDefinitionHttpHandler.class));
httpServer.start();
System.out.println();
System.out.println("Press [Enter] to shut down...");
System.in.read();
applicationContext.close();
httpServer.stop(0);
}
}

View File

@@ -25,12 +25,13 @@ import org.springframework.ws.samples.stockquote.schema.StockQuote;
import org.springframework.ws.samples.stockquote.schema.StockQuoteRequest;
import org.springframework.ws.samples.stockquote.schema.StockQuoteResponse;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.soap.addressing.server.annotation.Action;
import org.springframework.ws.soap.addressing.server.annotation.Address;
@Endpoint
@Address("http://localhost:8080/StockService")
// optional
@Address("http://localhost:8080/StockService") // optional
public class StockService {
private DatatypeFactory datatypeFactory;
@@ -41,7 +42,8 @@ public class StockService {
@Action(value = "http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote",
output = "http://www.springframework.org/spring-ws/samples/stockquote/StockService/Quotes")
public StockQuoteResponse getStockQuotes(StockQuoteRequest request) {
@ResponsePayload
public StockQuoteResponse getStockQuotes(@RequestPayload StockQuoteRequest request) {
StockQuoteResponse response = new StockQuoteResponse();
XMLGregorianCalendar now = datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar());

View File

@@ -0,0 +1,81 @@
package org.springframework.ws.samples.stockquote.ws;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.server.EndpointAdapter;
import org.springframework.ws.server.EndpointInterceptor;
import org.springframework.ws.server.EndpointMapping;
import org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter;
import org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
import org.springframework.ws.soap.server.SoapMessageDispatcher;
import org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor;
import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
import org.springframework.ws.transport.http.WebServiceMessageReceiverHttpHandler;
import org.springframework.ws.transport.http.WsdlDefinitionHttpHandler;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
/**
* @author Arjen Poutsma
*/
@Configuration
@ComponentScan("org.springframework.ws.samples.stockquote.ws")
public class StockServiceConfiguration {
@Bean
public WebServiceMessageReceiverHttpHandler soapHandler() {
WebServiceMessageReceiverHttpHandler soapHandler = new WebServiceMessageReceiverHttpHandler();
soapHandler.setMessageFactory(messageFactory());
soapHandler.setMessageReceiver(messageReceiver());
return soapHandler;
}
@Bean
public SaajSoapMessageFactory messageFactory() {
return new SaajSoapMessageFactory();
}
@Bean
public SoapMessageDispatcher messageReceiver() {
SoapMessageDispatcher messageReceiver = new SoapMessageDispatcher();
messageReceiver.setEndpointAdapters(
Collections.<EndpointAdapter>singletonList(endpointAdapter()));
messageReceiver.setEndpointMappings(
Collections.<EndpointMapping>singletonList(endpointMapping()));
return messageReceiver;
}
@Bean
public DefaultMethodEndpointAdapter endpointAdapter() {
return new DefaultMethodEndpointAdapter();
}
@Bean
public AnnotationActionEndpointMapping endpointMapping() {
AnnotationActionEndpointMapping endpointMapping = new AnnotationActionEndpointMapping();
endpointMapping.setMessageSender(messageSender());
endpointMapping.setPreInterceptors(new EndpointInterceptor[] { new SoapEnvelopeLoggingInterceptor()});
return endpointMapping;
}
@Bean
public HttpUrlConnectionMessageSender messageSender() {
return new HttpUrlConnectionMessageSender();
}
@Bean
public WsdlDefinitionHttpHandler wsdlHandler() {
return new WsdlDefinitionHttpHandler(wsdlDefinition());
}
@Bean
public SimpleWsdl11Definition wsdlDefinition() {
return new SimpleWsdl11Definition(new ClassPathResource("/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl"));
}
}

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<import resource="ws/applicationContext-ws.xml"/>
<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean">
<property name="contexts">
<map>
<entry key="/StockService.wsdl" value-ref="wsdlHandler"/>
<entry key="/StockService" value-ref="soapHandler"/>
</map>
</property>
</bean>
<bean id="soapHandler" class="org.springframework.ws.transport.http.WebServiceMessageReceiverHttpHandler">
<property name="messageFactory" ref="messageFactory"/>
<property name="messageReceiver" ref="messageReceiver"/>
</bean>
<bean id="wsdlHandler" class="org.springframework.ws.transport.http.WsdlDefinitionHttpHandler">
<property name="definition" ref="wsdlDefinition"/>
</bean>
</beans>

View File

@@ -1,40 +0,0 @@
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="messageReceiver" class="org.springframework.ws.soap.server.SoapMessageDispatcher">
<property name="endpointAdapters">
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
</property>
<property name="endpointMappings" ref="endpointMapping"/>
</bean>
<bean id="endpointMapping" class="org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping">
<property name="messageSenders">
<bean class="org.springframework.ws.transport.http.HttpUrlConnectionMessageSender"/>
</property>
<property name="preInterceptors">
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor"/>
</property>
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="org.springframework.ws.samples.stockquote.schema"/>
</bean>
<bean id="wsdlDefinition" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<property name="wsdl" value="classpath:/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl"/>
</bean>
<bean class="org.springframework.ws.samples.stockquote.ws.StockService"/>
</beans>