Added MTOM sample
This commit is contained in:
14
mtom/README.md
Normal file
14
mtom/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# MTOM Sample
|
||||
|
||||
This sample shows how to use marshal and unmarshal MTOM attachments using JAXB2.
|
||||
|
||||
## Build and deploy
|
||||
|
||||
See the main [README](../README.md) for build instructions.
|
||||
|
||||
## License
|
||||
|
||||
[Spring Web Services] is released under version 2.0 of the [Apache License].
|
||||
|
||||
[Spring Web Services]: http://projects.spring.io/spring-ws
|
||||
[Apache License]: http://www.apache.org/licenses/LICENSE-2.0
|
||||
19
mtom/build.gradle
Normal file
19
mtom/build.gradle
Normal file
@@ -0,0 +1,19 @@
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
|
||||
repositories {
|
||||
maven { url 'http://repo.spring.io/libs-release' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.10")
|
||||
testCompile("org.easymock:easymock:3.1")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.8'
|
||||
}
|
||||
6
mtom/client/jax-ws/.gitignore
vendored
Normal file
6
mtom/client/jax-ws/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
target
|
||||
*.iml
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
39
mtom/client/jax-ws/build.gradle
Normal file
39
mtom/client/jax-ws/build.gradle
Normal file
@@ -0,0 +1,39 @@
|
||||
configurations {
|
||||
wsimport
|
||||
}
|
||||
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
|
||||
task wsImport {
|
||||
ext.outputDir = "${buildDir}/classes/wsimport"
|
||||
ext.wsdl = "${projectDir}/mtom.wsdl"
|
||||
|
||||
inputs.files wsdl
|
||||
outputs.dir outputDir
|
||||
|
||||
doLast() {
|
||||
project.ant {
|
||||
taskdef name: "wsimport", classname: "com.sun.tools.ws.ant.WsImport",
|
||||
classpath: configurations.wsimport.asPath
|
||||
mkdir(dir: outputDir)
|
||||
|
||||
wsimport(destdir: outputDir, wsdl: wsdl,
|
||||
package: "org.springframework.ws.samples.mtom.client.jaxws") {
|
||||
produces(dir: outputDir, includes: "**/*.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile(files(wsImport.outputDir).builtBy(wsImport))
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
wsimport "com.sun.xml.ws:jaxws-tools:2.1.7"
|
||||
}
|
||||
|
||||
task runClient(dependsOn: 'classes', type:JavaExec) {
|
||||
main = "org.springframework.ws.samples.mtom.client.jaxws.Main"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
systemProperty("java.awt.headless", "true")
|
||||
}
|
||||
73
mtom/client/jax-ws/mtom.wsdl
Normal file
73
mtom/client/jax-ws/mtom.wsdl
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:sch="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/samples/mtom">
|
||||
<wsdl:types>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
|
||||
elementFormDefault="qualified" targetNamespace="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/mtom">
|
||||
|
||||
<element name="StoreImageRequest" type="tns:Image"/>
|
||||
|
||||
<element name="LoadImageRequest" type="string"/>
|
||||
|
||||
<element name="LoadImageResponse" type="tns:Image"/>
|
||||
|
||||
<complexType name="Image">
|
||||
<sequence>
|
||||
<element name="name" type="string"/>
|
||||
<element name="image" type="base64Binary" xmime:expectedContentTypes="image/png"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
</schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="StoreImageRequest">
|
||||
<wsdl:part element="tns:StoreImageRequest" name="StoreImageRequest">
|
||||
</wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="LoadImageResponse">
|
||||
<wsdl:part element="tns:LoadImageResponse" name="LoadImageResponse">
|
||||
</wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="LoadImageRequest">
|
||||
<wsdl:part element="tns:LoadImageRequest" name="LoadImageRequest">
|
||||
</wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="ImageRepository">
|
||||
<wsdl:operation name="StoreImage">
|
||||
<wsdl:input message="tns:StoreImageRequest" name="StoreImageRequest">
|
||||
</wsdl:input>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="LoadImage">
|
||||
<wsdl:input message="tns:LoadImageRequest" name="LoadImageRequest">
|
||||
</wsdl:input>
|
||||
<wsdl:output message="tns:LoadImageResponse" name="LoadImageResponse">
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="ImageRepositorySoap11" type="tns:ImageRepository">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="StoreImage">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="StoreImageRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="LoadImage">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="LoadImageRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="LoadImageResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="ImageRepositoryService">
|
||||
<wsdl:port binding="tns:ImageRepositorySoap11" name="ImageRepositorySoap11">
|
||||
<soap:address location="http://localhost:8080/mtom-server/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.mtom.client.jaxws;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.awt.Toolkit;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import javax.xml.ws.soap.SOAPFaultException;
|
||||
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Simple client that calls the <code>GetFlights</code> and <code>BookFlight</code> operations using JAX-WS.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
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(fileName);
|
||||
if (!file.exists()) {
|
||||
System.err.println("File [" + fileName + "] does not exist");
|
||||
System.exit(-1);
|
||||
}
|
||||
request.setName(file.getName());
|
||||
request.setImage(Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath()));
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start("store");
|
||||
imageRepository.storeImage(request);
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("load");
|
||||
Image response = imageRepository.loadImage(file.getName());
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
catch (SOAPFaultException ex) {
|
||||
System.err.format("SOAP Fault Code %1s%n", ex.getFault().getFaultCodeAsQName());
|
||||
System.err.format("SOAP Fault String: %1s%n", ex.getFault().getFaultString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
BIN
mtom/client/spring-ws-logo.png
Normal file
BIN
mtom/client/spring-ws-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
6
mtom/client/spring-ws/.gitignore
vendored
Normal file
6
mtom/client/spring-ws/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
target
|
||||
*.iml
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
59
mtom/client/spring-ws/build.gradle
Normal file
59
mtom/client/spring-ws/build.gradle
Normal file
@@ -0,0 +1,59 @@
|
||||
configurations {
|
||||
jaxb
|
||||
}
|
||||
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
|
||||
task genJaxb {
|
||||
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
|
||||
ext.classesDir = "${buildDir}/classes/jaxb"
|
||||
ext.schema = "${projectDir}/../../server/src/main/webapp/WEB-INF/schema.xsd"
|
||||
|
||||
inputs.files schema
|
||||
outputs.dir classesDir
|
||||
|
||||
doLast() {
|
||||
project.ant {
|
||||
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
|
||||
classpath: configurations.jaxb.asPath
|
||||
mkdir(dir: sourcesDir)
|
||||
mkdir(dir: classesDir)
|
||||
|
||||
xjc(destdir: sourcesDir, schema: schema,
|
||||
package: "org.springframework.ws.samples.mtom.client.sws") {
|
||||
produces(dir: sourcesDir, includes: "**/*.java")
|
||||
}
|
||||
|
||||
javac(destdir: classesDir, source: 1.6, target: 1.6, debug: true,
|
||||
debugLevel: "lines,vars,source",
|
||||
classpath: configurations.jaxb.asPath) {
|
||||
src(path: sourcesDir)
|
||||
include(name: "**/*.java")
|
||||
include(name: "*.java")
|
||||
}
|
||||
|
||||
copy(todir: classesDir) {
|
||||
fileset(dir: sourcesDir, erroronmissingdir: false) {
|
||||
exclude(name: "**/*.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile("org.apache.ws.commons.axiom:axiom-api:1.2.14")
|
||||
compile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
runtime("org.apache.ws.commons.axiom:axiom-impl:1.2.14")
|
||||
|
||||
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
|
||||
}
|
||||
|
||||
task runClient(dependsOn: 'classes', type:JavaExec) {
|
||||
main = "org.springframework.ws.samples.mtom.client.sws.Driver"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
systemProperty("java.awt.headless", "true")
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
import org.apache.axiom.om.OMOutputFormat;
|
||||
import org.apache.axiom.om.OMText;
|
||||
import org.apache.axiom.soap.SOAPBody;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.client.core.WebServiceMessageCallback;
|
||||
import org.springframework.ws.client.core.WebServiceMessageExtractor;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessage;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
|
||||
import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||
|
||||
/**
|
||||
* Simple client that demonstartes MTOM by invoking <code>StoreImage</code> and <code>LoadImage</code> using a
|
||||
* WebServiceTemplate and Axiom.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class AxiomMtomClient extends WebServiceGatewaySupport {
|
||||
|
||||
private StopWatch stopWatch = new StopWatch(ClassUtils.getShortName(getClass()));
|
||||
|
||||
public AxiomMtomClient(AxiomSoapMessageFactory messageFactory) {
|
||||
super(messageFactory);
|
||||
}
|
||||
|
||||
public void doIt(String path) {
|
||||
try {
|
||||
store(path);
|
||||
load(path);
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void store(final String path) {
|
||||
stopWatch.start("store");
|
||||
getWebServiceTemplate().sendAndReceive(new WebServiceMessageCallback() {
|
||||
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
|
||||
AxiomSoapMessage soapMessage = (AxiomSoapMessage) message;
|
||||
SOAPMessage axiomMessage = soapMessage.getAxiomMessage();
|
||||
SOAPFactory factory = (SOAPFactory) axiomMessage.getOMFactory();
|
||||
SOAPBody body = axiomMessage.getSOAPEnvelope().getBody();
|
||||
|
||||
OMNamespace ns =
|
||||
factory.createOMNamespace("http://www.springframework.org/spring-ws/samples/mtom", "tns");
|
||||
|
||||
OMElement storeImageRequestElement = factory.createOMElement("StoreImageRequest", ns);
|
||||
body.addChild(storeImageRequestElement);
|
||||
OMElement nameElement = factory.createOMElement("name", ns);
|
||||
storeImageRequestElement.addChild(nameElement);
|
||||
nameElement.setText(StringUtils.getFilename(path));
|
||||
OMElement imageElement = factory.createOMElement("image", ns);
|
||||
storeImageRequestElement.addChild(imageElement);
|
||||
DataSource dataSource = new FileDataSource(path);
|
||||
DataHandler dataHandler = new DataHandler(dataSource);
|
||||
OMText text = factory.createOMText(dataHandler, true);
|
||||
imageElement.addChild(text);
|
||||
|
||||
OMOutputFormat outputFormat = new OMOutputFormat();
|
||||
outputFormat.setSOAP11(true);
|
||||
outputFormat.setDoOptimize(true);
|
||||
soapMessage.setOutputFormat(outputFormat);
|
||||
}
|
||||
}, new WebServiceMessageExtractor() {
|
||||
public Object extractData(WebServiceMessage message) throws IOException, TransformerException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
stopWatch.stop();
|
||||
}
|
||||
|
||||
private void load(final String path) {
|
||||
final StringBuilder name = new StringBuilder();
|
||||
stopWatch.start("load");
|
||||
java.awt.Image image = (java.awt.Image) getWebServiceTemplate().sendAndReceive(new WebServiceMessageCallback() {
|
||||
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
|
||||
SOAPMessage axiomMessage = ((AxiomSoapMessage) message).getAxiomMessage();
|
||||
SOAPFactory factory = (SOAPFactory) axiomMessage.getOMFactory();
|
||||
SOAPBody body = axiomMessage.getSOAPEnvelope().getBody();
|
||||
|
||||
OMNamespace ns =
|
||||
factory.createOMNamespace("http://www.springframework.org/spring-ws/samples/mtom", "tns");
|
||||
|
||||
OMElement loadImageRequestElement = factory.createOMElement("LoadImageRequest", ns);
|
||||
loadImageRequestElement.setText(StringUtils.getFilename(path));
|
||||
body.addChild(loadImageRequestElement);
|
||||
}
|
||||
}, new WebServiceMessageExtractor() {
|
||||
public Object extractData(WebServiceMessage message) throws IOException, TransformerException {
|
||||
SOAPMessage axiomMessage = ((AxiomSoapMessage) message).getAxiomMessage();
|
||||
SOAPBody body = axiomMessage.getSOAPEnvelope().getBody();
|
||||
OMElement loadImageResponseElement = (OMElement) body.getChildElements().next();
|
||||
Assert.isTrue("LoadImageResponse".equals(loadImageResponseElement.getLocalName()));
|
||||
Iterator childElements = loadImageResponseElement.getChildElements();
|
||||
OMElement nameElement = (OMElement) childElements.next();
|
||||
Assert.isTrue("name".equals(nameElement.getLocalName()));
|
||||
name.append(nameElement.getText());
|
||||
OMElement imageElement = (OMElement) childElements.next();
|
||||
Assert.isTrue("image".equals(imageElement.getLocalName()));
|
||||
OMText text = (OMText) imageElement.getFirstOMChild();
|
||||
|
||||
DataHandler dataHandler = (DataHandler) text.getDataHandler();
|
||||
return ImageIO.read(dataHandler.getInputStream());
|
||||
}
|
||||
});
|
||||
stopWatch.stop();
|
||||
logger.info("Received image " + name + " [" + image.getWidth(null) + "x" + image.getHeight(null) + "]");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Driver {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String fileName = "../spring-ws-logo.png";
|
||||
if (args.length > 0) {
|
||||
fileName = args[0];
|
||||
}
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("applicationContext.xml", Driver.class);
|
||||
|
||||
SaajMtomClient saajClient = applicationContext.getBean("saajClient", SaajMtomClient.class);
|
||||
saajClient.doIt(fileName);
|
||||
|
||||
AxiomMtomClient axiomClient = applicationContext.getBean("axiomClient", AxiomMtomClient.class);
|
||||
axiomClient.doIt(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 javax.xml.bind.JAXBElement;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
/**
|
||||
* Simple client that demonstartes MTOM by invoking <code>StoreImage</code> and <code>LoadImage</code> using a
|
||||
* WebServiceTemplate and SAAJ.
|
||||
*
|
||||
* @author Tareq Abed Rabbo
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class SaajMtomClient extends WebServiceGatewaySupport {
|
||||
|
||||
private ObjectFactory objectFactory = new ObjectFactory();
|
||||
|
||||
private StopWatch stopWatch = new StopWatch(ClassUtils.getShortName(getClass()));
|
||||
|
||||
public SaajMtomClient(SaajSoapMessageFactory messageFactory) {
|
||||
super(messageFactory);
|
||||
}
|
||||
|
||||
public void doIt(String path) {
|
||||
try {
|
||||
store(path);
|
||||
load(path);
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void store(String path) {
|
||||
Image image = objectFactory.createImage();
|
||||
image.setName(StringUtils.getFilename(path));
|
||||
image.setImage(Toolkit.getDefaultToolkit().getImage(path));
|
||||
JAXBElement<Image> storeImageRequest = objectFactory.createStoreImageRequest(image);
|
||||
stopWatch.start("store");
|
||||
getWebServiceTemplate().marshalSendAndReceive(storeImageRequest);
|
||||
stopWatch.stop();
|
||||
}
|
||||
|
||||
private void load(String path) {
|
||||
JAXBElement<String> loadImageRequest = objectFactory.createLoadImageRequest(StringUtils.getFilename(path));
|
||||
|
||||
stopWatch.start("load");
|
||||
JAXBElement<Image> loadImageResponse =
|
||||
(JAXBElement<Image>) getWebServiceTemplate().marshalSendAndReceive(loadImageRequest);
|
||||
stopWatch.stop();
|
||||
Image image = loadImageResponse.getValue();
|
||||
logger.info("Received image " + image.getName() + " [" + image.getImage().getWidth(null) + "x" +
|
||||
image.getImage().getHeight(null) + "]");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
log4j.rootLogger=WARN, stdout
|
||||
log4j.logger.org.springframework.ws.samples=INFO
|
||||
|
||||
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
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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="client" abstract="true">
|
||||
<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">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
|
||||
</constructor-arg>
|
||||
<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>
|
||||
|
||||
<bean id="axiomClient" class="org.springframework.ws.samples.mtom.client.sws.AxiomMtomClient" parent="client">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
6
mtom/server/.gitignore
vendored
Normal file
6
mtom/server/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
target
|
||||
*.iml
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
78
mtom/server/build.gradle
Normal file
78
mtom/server/build.gradle
Normal file
@@ -0,0 +1,78 @@
|
||||
configurations {
|
||||
jaxb
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.9'
|
||||
}
|
||||
}
|
||||
|
||||
ext.springVersion = '3.2.4.RELEASE'
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
ext.tomcatVersion = '7.0.42'
|
||||
|
||||
|
||||
apply plugin: 'war'
|
||||
apply plugin: 'tomcat'
|
||||
|
||||
task genJaxb {
|
||||
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
|
||||
ext.classesDir = "${buildDir}/classes/jaxb"
|
||||
ext.schema = "${projectDir}/src/main/webapp/WEB-INF/schema.xsd"
|
||||
|
||||
inputs.files schema
|
||||
outputs.dir classesDir
|
||||
|
||||
doLast() {
|
||||
project.ant {
|
||||
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
|
||||
classpath: configurations.jaxb.asPath
|
||||
mkdir(dir: sourcesDir)
|
||||
mkdir(dir: classesDir)
|
||||
|
||||
xjc(destdir: sourcesDir, schema: schema,
|
||||
package: "org.springframework.ws.samples.mtom.schema") {
|
||||
produces(dir: sourcesDir, includes: "**/*.java")
|
||||
}
|
||||
|
||||
javac(destdir: classesDir, source: 1.6, target: 1.6, debug: true,
|
||||
debugLevel: "lines,vars,source",
|
||||
classpath: configurations.jaxb.asPath) {
|
||||
src(path: sourcesDir)
|
||||
include(name: "**/*.java")
|
||||
include(name: "*.java")
|
||||
}
|
||||
|
||||
copy(todir: classesDir) {
|
||||
fileset(dir: sourcesDir, erroronmissingdir: false) {
|
||||
exclude(name: "**/*.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tomcatRun {
|
||||
contextPath = 'mtom-server'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
|
||||
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
|
||||
|
||||
tomcat("org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
|
||||
"org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion")
|
||||
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion") {
|
||||
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.mtom.service;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public interface ImageRepository {
|
||||
|
||||
Image readImage(String name) throws IOException;
|
||||
|
||||
void storeImage(String name, Image image) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public class StubImageRepository implements ImageRepository {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StubImageRepository.class);
|
||||
|
||||
private Map<String, Image> images = new HashMap<String, Image>();
|
||||
|
||||
public Image readImage(String name) throws IOException {
|
||||
logger.info("Loading image " + name);
|
||||
return images.get(name);
|
||||
}
|
||||
|
||||
public void storeImage(String name, Image image) throws IOException {
|
||||
logger.info("Storing image " + name + " [" + image.getWidth(null) + "x" + image.getHeight(null) + "]");
|
||||
images.put(name, image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.ws;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.samples.mtom.schema.Image;
|
||||
import org.springframework.ws.samples.mtom.schema.ObjectFactory;
|
||||
import org.springframework.ws.samples.mtom.service.ImageRepository;
|
||||
import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
|
||||
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
@Endpoint
|
||||
public class ImageRepositoryEndpoint {
|
||||
|
||||
private ImageRepository imageRepository;
|
||||
|
||||
private ObjectFactory objectFactory;
|
||||
|
||||
public ImageRepositoryEndpoint(ImageRepository imageRepository) {
|
||||
Assert.notNull(imageRepository, "'imageRepository' must not be null");
|
||||
this.imageRepository = imageRepository;
|
||||
this.objectFactory = new ObjectFactory();
|
||||
}
|
||||
|
||||
@PayloadRoot(localPart = "StoreImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
|
||||
@ResponsePayload
|
||||
public void store(@RequestPayload JAXBElement<Image> requestElement) throws IOException {
|
||||
Image request = requestElement.getValue();
|
||||
imageRepository.storeImage(request.getName(), request.getImage());
|
||||
}
|
||||
|
||||
@PayloadRoot(localPart = "LoadImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
|
||||
@ResponsePayload
|
||||
public JAXBElement<Image> load(@RequestPayload JAXBElement<String> requestElement) throws IOException {
|
||||
String name = requestElement.getValue();
|
||||
Image response = new Image();
|
||||
response.setName(name);
|
||||
response.setImage(imageRepository.readImage(name));
|
||||
return objectFactory.createLoadImageResponse(response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
8
mtom/server/src/main/resources/log4j.properties
Normal file
8
mtom/server/src/main/resources/log4j.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
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
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
|
||||
19
mtom/server/src/main/webapp/WEB-INF/schema.xsd
Normal file
19
mtom/server/src/main/webapp/WEB-INF/schema.xsd
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified">
|
||||
|
||||
<element name="StoreImageRequest" type="tns:Image"/>
|
||||
|
||||
<element name="LoadImageRequest" type="string"/>
|
||||
|
||||
<element name="LoadImageResponse" type="tns:Image"/>
|
||||
|
||||
<complexType name="Image">
|
||||
<sequence>
|
||||
<element name="name" type="string"/>
|
||||
<element name="image" type="base64Binary" xmime:expectedContentTypes="image/png"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
</schema>
|
||||
37
mtom/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml
Normal file
37
mtom/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml
Normal 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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<bean id="imageRepository" class="org.springframework.ws.samples.mtom.service.StubImageRepository"/>
|
||||
|
||||
<bean class="org.springframework.ws.samples.mtom.ws.ImageRepositoryEndpoint">
|
||||
<constructor-arg ref="imageRepository"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
|
||||
|
||||
<bean class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
|
||||
<property name="methodArgumentResolvers" ref="methodProcessor"/>
|
||||
<property name="methodReturnValueHandlers" ref="methodProcessor"/>
|
||||
</bean>
|
||||
|
||||
<bean id="methodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
|
||||
<constructor-arg ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="contextPath" value="org.springframework.ws.samples.mtom.schema"/>
|
||||
<property name="mtomEnabled" value="true"/>
|
||||
</bean>
|
||||
|
||||
<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-server/"/>
|
||||
</bean>
|
||||
|
||||
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
|
||||
<property name="xsd" value="/WEB-INF/schema.xsd"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
34
mtom/server/src/main/webapp/WEB-INF/web.xml
Normal file
34
mtom/server/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
||||
version="2.4">
|
||||
|
||||
<display-name>MyCompany HR Holiday Service</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
2
mtom/settings.gradle
Normal file
2
mtom/settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
include "server", "client:jax-ws", "client:spring-ws"
|
||||
Reference in New Issue
Block a user