Updated MTOM sample to use maven

This commit is contained in:
Arjen Poutsma
2010-02-26 10:17:05 +00:00
parent 767861d727
commit 3082124ffe
27 changed files with 185 additions and 340 deletions

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>mtom-client</artifactId>
<groupId>org.springframework.ws</groupId>
<version>2.0.0-M1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mtom-jax-ws-client</artifactId>
<packaging>jar</packaging>
<name>Spring WS MTOM Sample - JAX-WS Client</name>
<profiles>
<profile>
<id>jdk15</id>
<activation>
<jdk>!1.6</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://localhost:8080/mtom-server/mtom.wsdl</wsdlUrl>
</wsdlUrls>
<packageName>org.springframework.ws.samples.mtom.client.jaxws</packageName>
</configuration>
</execution>
</executions>
</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.mtom.client.jaxws.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -37,15 +37,24 @@ public class Main {
public static void main(String[] args) throws IOException {
try {
String fileName = "../spring-ws-logo.png";
if (args.length > 0) {
fileName = args[0];
}
ImageRepositoryService service = new ImageRepositoryService();
ImageRepository imageRepository = service.getImageRepositorySoap11();
SOAPBinding binding = (SOAPBinding) ((BindingProvider) imageRepository).getBinding();
binding.setMTOMEnabled(true);
Image request = new Image();
File file = new File(args[0]);
File file = new File(fileName);
if (!file.exists()) {
System.err.println("File [" + fileName + "] does not exist");
System.exit(-1);
}
request.setName(file.getName());
request.setImage(Toolkit.getDefaultToolkit().getImage(args[0]));
request.setImage(Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath()));
StopWatch stopWatch = new StopWatch();
stopWatch.start("store");
imageRepository.storeImage(request);

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>mtom</artifactId>
<groupId>org.springframework.ws</groupId>
<version>2.0.0-M1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mtom-client</artifactId>
<packaging>pom</packaging>
<name>Spring WS MTOM Sample - Clients</name>
<modules>
<module>jax-ws</module>
<module>spring-ws</module>
</modules>
</project>

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>mtom-client</artifactId>
<groupId>org.springframework.ws</groupId>
<version>2.0.0-M1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mtom-spring-ws-client</artifactId>
<packaging>jar</packaging>
<name>Spring WS MTOM Sample - Spring-WS Client</name>
<profiles>
<profile>
<id>jdk15</id>
<activation>
<jdk>!1.6</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/../../server/src/main/webapp/WEB-INF/</schemaDirectory>
<packageName>org.springframework.ws.samples.mtom.client.sws</packageName>
</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.mtom.client.sws.Driver</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -22,20 +22,18 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Driver {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java " + Driver.class.getName() + " filePath");
System.exit(-1);
String fileName = "../spring-ws-logo.png";
if (args.length > 0) {
fileName = args[0];
}
String filePath = args[0];
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", Driver.class);
SaajMtomClient saajClient = (SaajMtomClient) applicationContext.getBean("saajClient", SaajMtomClient.class);
saajClient.doIt(filePath);
SaajMtomClient saajClient = applicationContext.getBean("saajClient", SaajMtomClient.class);
saajClient.doIt(fileName);
AxiomMtomClient axiomClient =
(AxiomMtomClient) applicationContext.getBean("axiomClient", AxiomMtomClient.class);
axiomClient.doIt(filePath);
AxiomMtomClient axiomClient = applicationContext.getBean("axiomClient", AxiomMtomClient.class);
axiomClient.doIt(fileName);
}
}

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="client" abstract="true">
<property name="defaultUri" value="http://localhost:8080/mtom/services"/>
<property name="defaultUri" value="http://localhost:8080/mtom-server/services"/>
</bean>
<bean id="saajClient" class="org.springframework.ws.samples.mtom.client.sws.SaajMtomClient" parent="client">

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SoapMtomBinding" closeTimeout="00:01:00" sendTimeout="00:10:00">
<mtomMessageEncoding messageVersion="Soap11" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/mtom/" binding="customBinding"
bindingConfiguration="SoapMtomBinding" contract="Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository"
name="ImageRepositoryPort" />
</client>
</system.serviceModel>
</configuration>

View File

@@ -1,5 +0,0 @@
@echo off
set WCF_PATH="%WINDIR%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation"
svcutil /noLogo /out:src\ImageRepositoryService.cs -namespace:http://www.springframework.org/spring-ws/samples/mtom,Spring.Ws.Samples.Mtom.Client.Wcf /noConfig http://localhost:8080/mtom/mtom.wsdl
csc /noLogo /out:bin\image.exe /reference:%WCF_PATH%\System.ServiceModel.dll src\Main.cs src\ImageRepositoryService.cs
copy src\*.config bin\

View File

@@ -1,13 +0,0 @@
SPRING WEB SERVICES
This directory contains a .NET 3.0 client for the MTOM Sample that uses
Windows Communication Foundation (WCF). The client can be run with the
given run.bat batch file, or rebuilt by calling build.bat.
Client Sample table of contents
---------------------------------------------------
* bin - The executable files for the client: image.exe
* src - The source files for the client
* build.bat - .NET build batch file
* run.bat - runs image.exe

View File

@@ -1,2 +0,0 @@
@echo off
bin\image ..\spring-ws-logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -1,192 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/mtom")]
public partial class Image
{
private string nameField;
private byte[] imageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary", Order=1)]
public byte[] image
{
get
{
return this.imageField;
}
set
{
this.imageField = value;
}
}
}
namespace Spring.Ws.Samples.Mtom.Client.Wcf
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.springframework.org/spring-ws/samples/mtom", ConfigurationName="Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository")]
public interface ImageRepository
{
// CODEGEN: Generating message contract since the operation LoadImage is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageResponse LoadImage(Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageRequest request);
// CODEGEN: Generating message contract since the operation StoreImage is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
void StoreImage(Spring.Ws.Samples.Mtom.Client.Wcf.StoreImageRequest request);
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class LoadImageRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Name="LoadImageRequest", Namespace="http://www.springframework.org/spring-ws/samples/mtom", Order=0)]
public string LoadImageRequest1;
public LoadImageRequest()
{
}
public LoadImageRequest(string LoadImageRequest1)
{
this.LoadImageRequest1 = LoadImageRequest1;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class LoadImageResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Name="LoadImageResponse", Namespace="http://www.springframework.org/spring-ws/samples/mtom", Order=0)]
public Image LoadImageResponse1;
public LoadImageResponse()
{
}
public LoadImageResponse(Image LoadImageResponse1)
{
this.LoadImageResponse1 = LoadImageResponse1;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class StoreImageRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Name="StoreImageRequest", Namespace="http://www.springframework.org/spring-ws/samples/mtom", Order=0)]
public Image StoreImageRequest1;
public StoreImageRequest()
{
}
public StoreImageRequest(Image StoreImageRequest1)
{
this.StoreImageRequest1 = StoreImageRequest1;
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface ImageRepositoryChannel : Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class ImageRepositoryClient : System.ServiceModel.ClientBase<Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository>, Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository
{
public ImageRepositoryClient()
{
}
public ImageRepositoryClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public ImageRepositoryClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public ImageRepositoryClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public ImageRepositoryClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageResponse Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository.LoadImage(Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageRequest request)
{
return base.Channel.LoadImage(request);
}
public Image LoadImage(string LoadImageRequest1)
{
Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageRequest inValue = new Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageRequest();
inValue.LoadImageRequest1 = LoadImageRequest1;
Spring.Ws.Samples.Mtom.Client.Wcf.LoadImageResponse retVal = ((Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository)(this)).LoadImage(inValue);
return retVal.LoadImageResponse1;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
void Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository.StoreImage(Spring.Ws.Samples.Mtom.Client.Wcf.StoreImageRequest request)
{
base.Channel.StoreImage(request);
}
public void StoreImage(Image StoreImageRequest1)
{
Spring.Ws.Samples.Mtom.Client.Wcf.StoreImageRequest inValue = new Spring.Ws.Samples.Mtom.Client.Wcf.StoreImageRequest();
inValue.StoreImageRequest1 = StoreImageRequest1;
((Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository)(this)).StoreImage(inValue);
}
}
}

View File

@@ -1,55 +0,0 @@
using System;
using System.IO;
using System.ServiceModel;
namespace Spring.Ws.Samples.Mtom.Client.Wcf {
public class Client {
public static void Main(string[] args) {
if (args.Length == 0) {
Console.Error.WriteLine("Usage: image.exe [filename]");
return;
}
ImageRepositoryClient wcfClient = new ImageRepositoryClient();
try {
Image image = new Image();
FileInfo file = new FileInfo(args[0]);
image.name = file.Name;
byte[] buf = new byte[file.Length];
using (FileStream stream = file.OpenRead())
{
stream.Read(buf, 0, buf.Length);
}
image.image = buf;
DateTime start = DateTime.Now;
wcfClient.StoreImage(image);
TimeSpan interval = DateTime.Now - start;
Console.WriteLine("StoreImage took: {0,4:N0} ms.", interval.TotalMilliseconds);
start = DateTime.Now;
image = wcfClient.LoadImage(file.Name);
interval = DateTime.Now - start;
Console.WriteLine("LoadImage took: {0,4:N0} ms.", interval.TotalMilliseconds);
wcfClient.Close();
} catch (TimeoutException ex) {
Console.Error.WriteLine("The service operation timed out. " + ex.Message);
wcfClient.Abort();
} catch (FaultException ex) {
Console.Error.WriteLine("SOAP Fault Code {0}", ex.Code);
Console.Error.WriteLine("SOAP Fault Reason: {0}", ex.Reason);
wcfClient.Abort();
} catch (CommunicationException ex) {
Console.WriteLine(ex.GetType());
Console.Error.WriteLine("There was a communication problem. " + ex.Message);
Console.Error.WriteLine(ex.StackTrace);
wcfClient.Abort();
} catch (Exception ex) {
Console.Error.WriteLine("Unknown exception. " + ex.Message);
Console.Error.WriteLine(ex.StackTrace);
wcfClient.Abort();
}
}
}
}

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SoapMtomBinding" closeTimeout="00:01:00" sendTimeout="00:10:00">
<mtomMessageEncoding messageVersion="Soap11" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/mtom/" binding="customBinding"
bindingConfiguration="SoapMtomBinding" contract="Spring.Ws.Samples.Mtom.Client.Wcf.ImageRepository"
name="ImageRepositoryPort" />
</client>
</system.serviceModel>
</configuration>

View File

@@ -2,15 +2,15 @@
<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>
<artifactId>mtom</artifactId>
<groupId>org.springframework.ws</groupId>
<version>2.0.0-M1-SNAPSHOT</version>
<relativePath>../samples/pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mtom</artifactId>
<artifactId>mtom-server</artifactId>
<packaging>war</packaging>
<name>Spring WS MTOM Example</name>
<name>Spring WS MTOM Sample - Server</name>
<description>This sample shows how to use MTOM and JAXB2.</description>
<pluginRepositories>
<pluginRepository>
@@ -20,16 +20,6 @@
<layout>legacy</layout>
</pluginRepository>
</pluginRepositories>
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<stylesheetfile>${basedir}/../../src/main/javadoc/javadoc.css</stylesheetfile>
</configuration>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>jdk15</id>
@@ -42,7 +32,6 @@
<artifactId>jaxb-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
<version>2.1</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
@@ -57,7 +46,6 @@
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -69,14 +57,6 @@
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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>

View File

@@ -1,4 +1,6 @@
log4j.rootLogger=WARN, stdout
log4j.logger.org.springframework.ws=DEBUG
log4j.logger.org.springframework.xml=DEBUG
log4j.logger.org.springframework.ws.samples=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

View File

@@ -22,7 +22,7 @@
<bean id="mtom" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schema" ref="schema"/>
<property name="portTypeName" value="ImageRepository"/>
<property name="locationUri" value="http://localhost:8080/mtom/"/>
<property name="locationUri" value="http://localhost:8080/mtom-server/"/>
</bean>