SWS-496 - Added Tareq's Spring-WS MTOM client
This commit is contained in:
85
samples/mtom/client/spring-ws/build.xml
Normal file
85
samples/mtom/client/spring-ws/build.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project name="spring-ws-mtom-sample-sws-client" default="build" xmlns:artifact="urn:maven-artifact-ant">
|
||||
<property name="bin.dir" value="bin"/>
|
||||
<property name="src.dir" value="src"/>
|
||||
<property name="gen.dir" value="gen"/>
|
||||
<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" url="https://maven-repository.dev.java.net/nonav/repository"
|
||||
layout="legacy"/>
|
||||
|
||||
<artifact:dependencies pathId="generate.classpath">
|
||||
<remoteRepository refid="main"/>
|
||||
<remoteRepository refid="java.net"/>
|
||||
<dependency groupId="com.sun.xml.ws" artifactId="jaxws-tools" version="EA3"/>
|
||||
<dependency groupId="com.sun.xml.bind" artifactId="jaxb-xjc" version="2.1-EA2"/>
|
||||
</artifact:dependencies>
|
||||
|
||||
<artifact:dependencies pathId="compile.classpath">
|
||||
<remoteRepository refid="main"/>
|
||||
<remoteRepository refid="java.net"/>
|
||||
<dependency groupId="org.springframework" artifactId="spring-core" version="2.5.6"/>
|
||||
<dependency groupId="org.springframework.ws" artifactId="spring-ws-core" version="1.5.6"/>
|
||||
</artifact:dependencies>
|
||||
|
||||
<artifact:dependencies pathId="runtime.classpath">
|
||||
<remoteRepository refid="main"/>
|
||||
<remoteRepository refid="java.net"/>
|
||||
<dependency groupId="org.springframework.ws" artifactId="spring-ws-core" version="1.5.6"/>
|
||||
<dependency groupId="org.springframework.ws" artifactId="spring-oxm" version="1.5.6"/>
|
||||
<dependency groupId="org.springframework.ws" artifactId="spring-oxm-tiger" version="1.5.6"/>
|
||||
<dependency groupId="com.sun.xml.ws" artifactId="jaxws-rt" version="EA3"/>
|
||||
<dependency groupId="com.sun.xml.bind" artifactId="jaxb-impl" version="2.1-EA2"/>
|
||||
<dependency groupId="com.sun.xml.messaging.saaj" artifactId="saaj-impl" version="1.3"/>
|
||||
<dependency groupid="org.apache.ws.commons.axiom" artifactid="axiom-api" version="1.2.8"/>
|
||||
<dependency groupid="org.apache.ws.commons.axiom" artifactid="axiom-impl" version="1.2.8"/>
|
||||
</artifact:dependencies>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="generate" depends="init">
|
||||
<mkdir dir="${gen.dir}"/>
|
||||
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask" classpathref="generate.classpath"/>
|
||||
<xjc schema="../../src/main/webapp/WEB-INF/schema.xsd" destdir="${gen.dir}"
|
||||
package="org.springframework.ws.samples.mtom.client.sws"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="init,generate">
|
||||
<javac destdir="${bin.dir}" debug="true">
|
||||
<src path="${src.dir}"/>
|
||||
<src path="${gen.dir}"/>
|
||||
<classpath refid="compile.classpath"/>
|
||||
<classpath location="${bin.dir}"/>
|
||||
</javac>
|
||||
<copy todir="${bin.dir}">
|
||||
<fileset dir="${src.dir}">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${bin.dir}"/>
|
||||
<delete dir="${gen.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="run" depends="build">
|
||||
<java classname="org.springframework.ws.samples.mtom.client.sws.MtomClient" fork="true" failonerror="true">
|
||||
<jvmarg value="-Djava.awt.headless=true"/>
|
||||
<arg path="../spring-ws-logo.png"/>
|
||||
<classpath refid="compile.classpath"/>
|
||||
<classpath refid="runtime.classpath"/>
|
||||
<classpath location="${bin.dir}"/>
|
||||
</java>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.mtom.client.sws;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.io.File;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||
|
||||
/**
|
||||
* Simple client that demonstartes MTOM by invoking <code>StoreImage</code> and <code>LoadImage</code> using a
|
||||
* WebServiceTemplate.
|
||||
*
|
||||
* @author Tareq Abed Rabbo
|
||||
*/
|
||||
public class MtomClient extends WebServiceGatewaySupport {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("applicationContext.xml", MtomClient.class);
|
||||
MtomClient client = (MtomClient) applicationContext.getBean("mtomClient", MtomClient.class);
|
||||
|
||||
ObjectFactory objectFactory = new ObjectFactory();
|
||||
Image image = objectFactory.createImage();
|
||||
File file = new File(args[0]);
|
||||
image.setName(file.getName());
|
||||
image.setImage(Toolkit.getDefaultToolkit().getImage(args[0]));
|
||||
JAXBElement<Image> storeImageRequest = objectFactory.createStoreImageRequest(image);
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start("store");
|
||||
client.getWebServiceTemplate().marshalSendAndReceive(storeImageRequest);
|
||||
stopWatch.stop();
|
||||
JAXBElement<String> loadImageRequest = objectFactory.createLoadImageRequest(file.getName());
|
||||
|
||||
stopWatch.start("load");
|
||||
Object result = client.getWebServiceTemplate().marshalSendAndReceive(loadImageRequest);
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
catch (SoapFaultClientException ex) {
|
||||
System.err.format("SOAP Fault Code %1s%n", ex.getFaultCode());
|
||||
System.err.format("SOAP Fault String: %1s%n", ex.getFaultStringOrReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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.0.xsd">
|
||||
|
||||
<bean id="mtomClient" class="org.springframework.ws.samples.mtom.client.sws.MtomClient">
|
||||
<property name="defaultUri" value="http://localhost:8080/mtom/services"/>
|
||||
<property name="marshaller" ref="marshaller"/>
|
||||
<property name="unmarshaller" ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="contextPath" value="org.springframework.ws.samples.mtom.client.sws"/>
|
||||
<property name="mtomEnabled" value="true"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user