Added spring-ws client to stockquote example.

This commit is contained in:
Arjen Poutsma
2008-02-26 01:24:47 +00:00
parent edabca8a5b
commit b4ec5b80b5
8 changed files with 143 additions and 4 deletions

View File

@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<project name="spring-ws-stock-sample-spring-ws-client" default="build" xmlns:artifact="urn:maven-artifact-ant">
<property name="bin.dir" value="bin"/>
<property name="src.dir" value="src"/>
<target name="init">
<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:dependencies pathId="classpath">
<dependency groupId="org.springframework.ws" artifactId="spring-ws-core" version="1.5.0-rc1-SNAPSHOT"/>
<dependency groupId="com.sun.xml.messaging.saaj" artifactId="saaj-impl" version="1.3"/>
<dependency groupId="log4j" artifactId="log4j" version="1.2.13"/>
</artifact:dependencies>
</target>
<target name="build" depends="init">
<mkdir dir="${bin.dir}"/>
<javac srcdir="${src.dir}" destdir="${bin.dir}">
<classpath refid="classpath"/>
</javac>
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="run" depends="quotes"/>
<target name="quotes" depends="build">
<java classname="org.springframework.ws.samples.stockquote.client.sws.StockClient" fork="true"
failonerror="true">
<classpath refid="classpath"/>
<classpath location="${bin.dir}"/>
</java>
</target>
</project>

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,59 @@
/*
* Copyright 2007 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.sws;
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.Resource;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.addressing.client.ActionCallback;
import org.springframework.xml.transform.ResourceSource;
import org.springframework.xml.transform.StringResult;
public class StockClient extends WebServiceGatewaySupport {
private Resource request;
private URI action;
public void setRequest(Resource request) {
this.request = request;
}
public void setAction(URI action) {
this.action = action;
}
public void quotes() throws IOException {
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, new ActionCallback(action), result);
System.out.println(result);
}
public static void main(String[] args) throws IOException {
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", StockClient.class);
StockClient stockClient = (StockClient) applicationContext.getBean("stockClient");
stockClient.quotes();
}
}

View File

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

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<StockQuoteRequest xmlns="http://www.springframework.org/spring-ws/samples/stockquote">
<Symbol>FABRIKAM</Symbol>
<Symbol>CONTOSO</Symbol>
</StockQuoteRequest>

View File

@@ -17,17 +17,20 @@
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 javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
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;
import org.springframework.ws.soap.addressing.server.annotation.Address;
@Endpoint
@Address("http://localhost:8080/StockService")
// optional
public class StockService {
private DatatypeFactory datatypeFactory;
@@ -36,7 +39,8 @@ public class StockService {
datatypeFactory = DatatypeFactory.newInstance();
}
@Action("http://www.springframework.org/spring-ws/samples/stockquote/StockService/GetQuote")
@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) {
StockQuoteResponse response = new StockQuoteResponse();

View File

@@ -22,6 +22,9 @@
<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">

View File

@@ -49,7 +49,7 @@
<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"/>
wsaw:Action="http://www.springframework.org/spring-ws/samples/stockquote/StockService/Quotes"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockSoap11" type="tns:Stock">