From 42f24fe98ea03dffb6f4259f0baa22546508053e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Sun, 24 Feb 2008 03:28:46 +0000 Subject: [PATCH] Added Stockquote sample --- samples/stockquote/client/jax-ws/build.xml | 56 +++++++++++ samples/stockquote/client/jax-ws/readme.txt | 11 +++ .../samples/stockquote/client/jaxws/Main.java | 57 +++++++++++ samples/stockquote/pom.xml | 95 +++++++++++++++++++ samples/stockquote/readme.txt | 15 +++ .../ws/samples/stockquote/Driver.java | 34 +++++++ .../samples/stockquote/ws/StockService.java | 64 +++++++++++++ .../src/main/resources/log4j.properties | 7 ++ .../samples/stockquote/applicationContext.xml | 26 +++++ .../ws/samples/stockquote/stockquote.xsd | 42 ++++++++ .../stockquote/ws/applicationContext-ws.xml | 37 ++++++++ .../ws/samples/stockquote/ws/stockquote.wsdl | 73 ++++++++++++++ 12 files changed, 517 insertions(+) create mode 100644 samples/stockquote/client/jax-ws/build.xml create mode 100644 samples/stockquote/client/jax-ws/readme.txt create mode 100644 samples/stockquote/client/jax-ws/src/org/springframework/ws/samples/stockquote/client/jaxws/Main.java create mode 100644 samples/stockquote/pom.xml create mode 100644 samples/stockquote/readme.txt create mode 100644 samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/Driver.java create mode 100644 samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/ws/StockService.java create mode 100644 samples/stockquote/src/main/resources/log4j.properties create mode 100644 samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/applicationContext.xml create mode 100644 samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/stockquote.xsd create mode 100644 samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/applicationContext-ws.xml create mode 100644 samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl diff --git a/samples/stockquote/client/jax-ws/build.xml b/samples/stockquote/client/jax-ws/build.xml new file mode 100644 index 00000000..950d3686 --- /dev/null +++ b/samples/stockquote/client/jax-ws/build.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/stockquote/client/jax-ws/readme.txt b/samples/stockquote/client/jax-ws/readme.txt new file mode 100644 index 00000000..89a04c43 --- /dev/null +++ b/samples/stockquote/client/jax-ws/readme.txt @@ -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 + diff --git a/samples/stockquote/client/jax-ws/src/org/springframework/ws/samples/stockquote/client/jaxws/Main.java b/samples/stockquote/client/jax-ws/src/org/springframework/ws/samples/stockquote/client/jaxws/Main.java new file mode 100644 index 00000000..8931d2f1 --- /dev/null +++ b/samples/stockquote/client/jax-ws/src/org/springframework/ws/samples/stockquote/client/jaxws/Main.java @@ -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 StockQuote 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() + "%"); + } + } + +} diff --git a/samples/stockquote/pom.xml b/samples/stockquote/pom.xml new file mode 100644 index 00000000..0dcc9d17 --- /dev/null +++ b/samples/stockquote/pom.xml @@ -0,0 +1,95 @@ + + + spring-ws-samples + org.springframework.ws + 1.5.0-rc1-SNAPSHOT + + 4.0.0 + stockquote + jar + Spring WS Stock Quote Sample + A Spring-WS sample that shows usage of WS-Addressing and the HTTP Server built into JDK 1.6. + + + + maven-javadoc-plugin + + ${basedir}/../../src/main/javadoc/javadoc.css + + + + + + + java.net + Java.net Repository for Maven2 + http://download.java.net/maven/1/ + legacy + + + + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + + + generate-sources + + generate + + + + + org.springframework.ws.samples.stockquote.schema + + stockquote.wsdl + + src/main/resources/org/springframework/ws/samples/stockquote/ws + -wsdl + + + + org.codehaus.mojo + exec-maven-plugin + + + + java + + + + + org.springframework.ws.samples.stockquote.Driver + + + + + + + + + org.springframework.ws + spring-ws-core-tiger + + + org.springframework.ws + spring-ws-support + + + + org.easymock + easymock + test + 2.2 + + + \ No newline at end of file diff --git a/samples/stockquote/readme.txt b/samples/stockquote/readme.txt new file mode 100644 index 00000000..a3cd6474 --- /dev/null +++ b/samples/stockquote/readme.txt @@ -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". diff --git a/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/Driver.java b/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/Driver.java new file mode 100644 index 00000000..75bac39d --- /dev/null +++ b/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/Driver.java @@ -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(); + } + +} diff --git a/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/ws/StockService.java b/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/ws/StockService.java new file mode 100644 index 00000000..c9b4fcff --- /dev/null +++ b/samples/stockquote/src/main/java/org/springframework/ws/samples/stockquote/ws/StockService.java @@ -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; + } + +} diff --git a/samples/stockquote/src/main/resources/log4j.properties b/samples/stockquote/src/main/resources/log4j.properties new file mode 100644 index 00000000..0f73a758 --- /dev/null +++ b/samples/stockquote/src/main/resources/log4j.properties @@ -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 \ No newline at end of file diff --git a/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/applicationContext.xml b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/applicationContext.xml new file mode 100644 index 00000000..8f53e13c --- /dev/null +++ b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/applicationContext.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/stockquote.xsd b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/stockquote.xsd new file mode 100644 index 00000000..17bfb393 --- /dev/null +++ b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/stockquote.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/applicationContext-ws.xml b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/applicationContext-ws.xml new file mode 100644 index 00000000..c30daffb --- /dev/null +++ b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/applicationContext-ws.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl new file mode 100644 index 00000000..ede8be8e --- /dev/null +++ b/samples/stockquote/src/main/resources/org/springframework/ws/samples/stockquote/ws/stockquote.wsdl @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file