Added Stockquote sample

This commit is contained in:
Arjen Poutsma
2008-02-24 03:28:46 +00:00
parent 8c555819ae
commit 42f24fe98e
12 changed files with 517 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?xml version="1.0"?>
<project name="spring-ws-stockquote-sample-jax-ws-client" default="build" xmlns:artifact="urn:maven-artifact-ant">
<property name="bin.dir" value="bin"/>
<property name="src.dir" value="src"/>
<property name="lib.dir" value="lib"/>
<target name="init">
<mkdir dir="${bin.dir}"/>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
<classpath>
<pathelement location="${basedir}/../../../maven-ant-tasks-2.0.7.jar"/>
</classpath>
</typedef>
<artifact:remoteRepository id="main" url="http://repo1.maven.org/maven2/"/>
<artifact:remoteRepository id="java.net.1" url="http://download.java.net/maven/1/"
layout="legacy"/>
<artifact:remoteRepository id="java.net.2" url="http://download.java.net/maven/2/"/>
<artifact:dependencies pathId="classpath">
<remoteRepository refid="main"/>
<remoteRepository refid="java.net.1"/>
<remoteRepository refid="java.net.2"/>
<dependency groupId="com.sun.xml.ws" artifactId="jaxws-rt" version="2.1.3"/>
<dependency groupId="com.sun.xml.ws" artifactId="jaxws-tools" version="2.1.3"/>
<dependency groupId="org.jvnet.staxex" artifactId="stax-ex" version="1.0"/>
</artifact:dependencies>
</target>
<target name="generate" depends="init">
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport" classpathref="classpath"/>
<wsimport wsdl="http://localhost:8080/StockService.wsdl" destdir="${bin.dir}"
package="org.springframework.ws.samples.stockquote.client.jaxws" xendorsed="true"
keep="true" sourcedestdir="gen"/>
</target>
<target name="build" depends="generate">
<javac srcdir="${src.dir}" destdir="${bin.dir}" debug="true">
<classpath refid="classpath"/>
<classpath location="${bin.dir}"/>
</javac>
</target>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="run" depends="build">
<java classname="org.springframework.ws.samples.stockquote.client.jaxws.Main" fork="true" failonerror="true">
<classpath refid="classpath"/>
<classpath location="${bin.dir}"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,11 @@
SPRING WEB SERVICES
This directory contains a Java client for the Airline Web Service that uses JAX-WS.
The client can be run from the provided ant file, by calling "ant run".
Note that the airline sample has to be running before invoking this target.
Client Sample table of contents
---------------------------------------------------
* src - The source files for the client
* build.xml - Ant build file with a 'build' and a 'run' target

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.stockquote.client.jaxws;
import java.net.URL;
import javax.xml.namespace.QName;
/**
* Simple client that calls the <code>StockQuote</code> operations using JAX-WS.
*
* @author Arjen Poutsma
*/
public class Main {
public static void main(String[] args) throws Exception {
StockService service;
if (args.length == 0) {
service = new StockService();
}
else {
QName serviceName = new QName("http://www.springframework.org/spring-ws/samples/stockquote", "StockSoap11");
service = new StockService(new URL(args[0]), serviceName);
}
Stock stock = service.getStockSoap11();
StockQuoteRequest request = new StockQuoteRequest();
request.getSymbol().add("FABRIKAM");
request.getSymbol().add("CONTOSO");
System.out.format("Requesting quotes for %s%n", request.getSymbol());
StockQuoteResponse response = stock.stockQuote(request);
System.out.format("Got %d results%n", response.getStockQuote().size());
for (StockQuote quote : response.getStockQuote()) {
System.out.println();
System.out.println("Symbol: " + quote.getSymbol());
System.out.println("\tName:\t\t\t" + quote.getName());
System.out.println("\tLast Price:\t\t" + quote.getLast());
System.out.println("\tPrevious Change:\t" + quote.getChange() + "%");
}
}
}

View File

@@ -0,0 +1,95 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>spring-ws-samples</artifactId>
<groupId>org.springframework.ws</groupId>
<version>1.5.0-rc1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>stockquote</artifactId>
<packaging>jar</packaging>
<name>Spring WS Stock Quote Sample</name>
<description>A Spring-WS sample that shows usage of WS-Addressing and the HTTP Server built into JDK 1.6.</description>
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<stylesheetfile>${basedir}/../../src/main/javadoc/javadoc.css</stylesheetfile>
</configuration>
</plugin>
</plugins>
</reporting>
<pluginRepositories>
<pluginRepository>
<id>java.net</id>
<name>Java.net Repository for Maven2</name>
<url>http://download.java.net/maven/1/</url>
<layout>legacy</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>org.springframework.ws.samples.stockquote.schema</generatePackage>
<includeSchemas>
<includeSchema>stockquote.wsdl</includeSchema>
</includeSchemas>
<schemaDirectory>src/main/resources/org/springframework/ws/samples/stockquote/ws</schemaDirectory>
<args>-wsdl</args>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.springframework.ws.samples.stockquote.Driver</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Spring-WS dependencies -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core-tiger</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-support</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
<version>2.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,15 @@
=====================================================
== Spring Web Service Stock Quote sample application ==
=====================================================
1. INTRODUCTION
This sample shows a Stock Quote service. Incoming messages are routed via
WS-Addressing, and SOAP message content is handled using JAXB2. Additionally,
this sample uses the HTTP server built into Java 6.
2. RUNNING
This sample contains a main() method in the Driver class. To start it, simply
run "mvn install exec:java".

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.stockquote;
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Driver {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", Driver.class);
System.out.println();
System.out.println("Press [Enter] to shut down...");
System.in.read();
applicationContext.close();
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.stockquote.ws;
import java.util.GregorianCalendar;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.DatatypeConfigurationException;
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.soap.addressing.server.annotation.Action;
@Endpoint
public class StockService {
private DatatypeFactory datatypeFactory;
public StockService() throws DatatypeConfigurationException {
datatypeFactory = DatatypeFactory.newInstance();
}
@Action("http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote")
public StockQuoteResponse getStockQuotes(StockQuoteRequest request) {
StockQuoteResponse response = new StockQuoteResponse();
XMLGregorianCalendar now = datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar());
for (String symbol : request.getSymbol()) {
StockQuote quote = new StockQuote();
quote.setSymbol(symbol);
quote.setDate(now);
if ("FABRIKAM".equals(symbol)) {
quote.setName("Fabrikam, Inc.");
quote.setLast(120.00);
quote.setChange(5.5);
}
else {
quote.setName("Contoso Corp.");
quote.setLast(50.07);
quote.setChange(1.15);
}
response.getStockQuote().add(quote);
}
return response;
}
}

View File

@@ -0,0 +1,7 @@
log4j.rootLogger=WARN, stdout
log4j.logger.org.springframework.ws=DEBUG
log4j.logger.org.springframework.xml=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

View File

@@ -0,0 +1,26 @@
<?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

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://www.springframework.org/spring-ws/samples/stockquote"
xmlns:tns="http://www.springframework.org/spring-ws/samples/stockquote">
<xsd:element name="StockQuoteRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="Symbol" type="tns:StockSymbol"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="StockQuoteResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="StockQuote" type="tns:StockQuote"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="StockSymbol">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z]+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="StockQuote">
<xsd:sequence>
<xsd:element minOccurs="0" name="Symbol" type="tns:StockSymbol"/>
<xsd:element minOccurs="1" name="Last" type="xsd:double"/>
<xsd:element minOccurs="1" name="Date" type="xsd:dateTime"/>
<xsd:element minOccurs="1" name="Change" type="xsd:double"/>
<xsd:element minOccurs="1" name="Open" type="xsd:double"/>
<xsd:element minOccurs="1" name="High" type="xsd:double"/>
<xsd:element minOccurs="1" name="Low" type="xsd:double"/>
<xsd:element minOccurs="1" name="Volume" type="xsd:long"/>
<xsd:element minOccurs="1" name="MarketCap" type="xsd:long"/>
<xsd:element minOccurs="1" name="PreviousClose" type="xsd:double"/>
<xsd:element minOccurs="1" name="PreviousChange" type="xsd:double"/>
<xsd:element minOccurs="1" name="Low52Week" type="xsd:double"/>
<xsd:element minOccurs="1" name="High52Week" type="xsd:double"/>
<xsd:element minOccurs="0" name="Name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,37 @@
<?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>
</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>

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:tns="http://www.springframework.org/spring-ws/samples/stockquote"
targetNamespace="http://www.springframework.org/spring-ws/samples/stockquote">
<wsdl:types>
<xsd:schema xmlns:tns="http://www.springframework.org/spring-ws/samples/stockquote"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://www.springframework.org/spring-ws/samples/stockquote">
<xsd:element name="StockQuoteRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Symbol" type="tns:StockSymbol"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="StockQuoteResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="StockQuote" type="tns:StockQuote"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="StockSymbol">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z]+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="StockQuote">
<xsd:sequence>
<xsd:element minOccurs="0" name="Symbol" type="tns:StockSymbol"/>
<xsd:element minOccurs="1" name="Last" type="xsd:double"/>
<xsd:element minOccurs="1" name="Date" type="xsd:dateTime"/>
<xsd:element minOccurs="1" name="Change" type="xsd:double"/>
<xsd:element minOccurs="0" name="Name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="StockQuoteRequest">
<wsdl:part element="tns:StockQuoteRequest" name="StockQuoteRequest"/>
</wsdl:message>
<wsdl:message name="StockQuoteResponse">
<wsdl:part element="tns:StockQuoteResponse" name="StockQuoteResponse"/>
</wsdl:message>
<wsdl:portType name="Stock">
<wsdl:operation name="StockQuote">
<wsdl:input message="tns:StockQuoteRequest" name="StockQuoteRequest"
wsaw:Action="http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote"/>
<wsdl:output message="tns:StockQuoteResponse" name="StockQuoteResponse"
wsaw:Action="http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuoteResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockSoap11" type="tns:Stock">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsaw:UsingAddressing wsdl:required="true"/>
<wsdl:operation name="StockQuote">
<soap:operation soapAction=""/>
<wsdl:input name="StockQuoteRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="StockQuoteResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockService">
<wsdl:port binding="tns:StockSoap11" name="StockSoap11">
<soap:address location="http://localhost:8080/StockService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>