diff --git a/mtom/README.md b/mtom/README.md new file mode 100644 index 0000000..2d6699c --- /dev/null +++ b/mtom/README.md @@ -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 \ No newline at end of file diff --git a/mtom/build.gradle b/mtom/build.gradle new file mode 100644 index 0000000..5736641 --- /dev/null +++ b/mtom/build.gradle @@ -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' +} diff --git a/mtom/client/jax-ws/.gitignore b/mtom/client/jax-ws/.gitignore new file mode 100644 index 0000000..2739940 --- /dev/null +++ b/mtom/client/jax-ws/.gitignore @@ -0,0 +1,6 @@ +target +*.iml +.classpath +.project +.settings + diff --git a/mtom/client/jax-ws/build.gradle b/mtom/client/jax-ws/build.gradle new file mode 100644 index 0000000..5d7bf51 --- /dev/null +++ b/mtom/client/jax-ws/build.gradle @@ -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") +} \ No newline at end of file diff --git a/mtom/client/jax-ws/mtom.wsdl b/mtom/client/jax-ws/mtom.wsdl new file mode 100644 index 0000000..0a6e0ba --- /dev/null +++ b/mtom/client/jax-ws/mtom.wsdl @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mtom/client/jax-ws/src/main/java/org/springframework/ws/samples/mtom/client/jaxws/Main.java b/mtom/client/jax-ws/src/main/java/org/springframework/ws/samples/mtom/client/jaxws/Main.java new file mode 100644 index 0000000..85ebca1 --- /dev/null +++ b/mtom/client/jax-ws/src/main/java/org/springframework/ws/samples/mtom/client/jaxws/Main.java @@ -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 GetFlights and BookFlight 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()); + } + + } + + +} diff --git a/mtom/client/spring-ws-logo.png b/mtom/client/spring-ws-logo.png new file mode 100644 index 0000000..2bdbd1a Binary files /dev/null and b/mtom/client/spring-ws-logo.png differ diff --git a/mtom/client/spring-ws/.gitignore b/mtom/client/spring-ws/.gitignore new file mode 100644 index 0000000..2739940 --- /dev/null +++ b/mtom/client/spring-ws/.gitignore @@ -0,0 +1,6 @@ +target +*.iml +.classpath +.project +.settings + diff --git a/mtom/client/spring-ws/build.gradle b/mtom/client/spring-ws/build.gradle new file mode 100644 index 0000000..8e8dd9b --- /dev/null +++ b/mtom/client/spring-ws/build.gradle @@ -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") +} \ No newline at end of file diff --git a/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/AxiomMtomClient.java b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/AxiomMtomClient.java new file mode 100644 index 0000000..a6ec661 --- /dev/null +++ b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/AxiomMtomClient.java @@ -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 StoreImage and LoadImage 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) + "]"); + } + + +} diff --git a/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/Driver.java b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/Driver.java new file mode 100644 index 0000000..2f7c556 --- /dev/null +++ b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/Driver.java @@ -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); + } + +} diff --git a/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/SaajMtomClient.java b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/SaajMtomClient.java new file mode 100644 index 0000000..de78e43 --- /dev/null +++ b/mtom/client/spring-ws/src/main/java/org/springframework/ws/samples/mtom/client/sws/SaajMtomClient.java @@ -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 StoreImage and LoadImage 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 storeImageRequest = objectFactory.createStoreImageRequest(image); + stopWatch.start("store"); + getWebServiceTemplate().marshalSendAndReceive(storeImageRequest); + stopWatch.stop(); + } + + private void load(String path) { + JAXBElement loadImageRequest = objectFactory.createLoadImageRequest(StringUtils.getFilename(path)); + + stopWatch.start("load"); + JAXBElement loadImageResponse = + (JAXBElement) getWebServiceTemplate().marshalSendAndReceive(loadImageRequest); + stopWatch.stop(); + Image image = loadImageResponse.getValue(); + logger.info("Received image " + image.getName() + " [" + image.getImage().getWidth(null) + "x" + + image.getImage().getHeight(null) + "]"); + + } + +} diff --git a/mtom/client/spring-ws/src/main/resources/log4j.properties b/mtom/client/spring-ws/src/main/resources/log4j.properties new file mode 100644 index 0000000..ecbc6e2 --- /dev/null +++ b/mtom/client/spring-ws/src/main/resources/log4j.properties @@ -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 diff --git a/mtom/client/spring-ws/src/main/resources/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml b/mtom/client/spring-ws/src/main/resources/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml new file mode 100644 index 0000000..52d6395 --- /dev/null +++ b/mtom/client/spring-ws/src/main/resources/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mtom/server/.gitignore b/mtom/server/.gitignore new file mode 100644 index 0000000..2739940 --- /dev/null +++ b/mtom/server/.gitignore @@ -0,0 +1,6 @@ +target +*.iml +.classpath +.project +.settings + diff --git a/mtom/server/build.gradle b/mtom/server/build.gradle new file mode 100644 index 0000000..b932ee3 --- /dev/null +++ b/mtom/server/build.gradle @@ -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' + } +} \ No newline at end of file diff --git a/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java new file mode 100644 index 0000000..3107214 --- /dev/null +++ b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java @@ -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; + +} diff --git a/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java new file mode 100644 index 0000000..163a228 --- /dev/null +++ b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java @@ -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 images = new HashMap(); + + 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); + } +} diff --git a/mtom/server/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java new file mode 100644 index 0000000..bacba4c --- /dev/null +++ b/mtom/server/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java @@ -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 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 load(@RequestPayload JAXBElement requestElement) throws IOException { + String name = requestElement.getValue(); + Image response = new Image(); + response.setName(name); + response.setImage(imageRepository.readImage(name)); + return objectFactory.createLoadImageResponse(response); + } + + +} diff --git a/mtom/server/src/main/resources/log4j.properties b/mtom/server/src/main/resources/log4j.properties new file mode 100644 index 0000000..5bb7c90 --- /dev/null +++ b/mtom/server/src/main/resources/log4j.properties @@ -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 diff --git a/mtom/server/src/main/webapp/WEB-INF/schema.xsd b/mtom/server/src/main/webapp/WEB-INF/schema.xsd new file mode 100644 index 0000000..1af18f5 --- /dev/null +++ b/mtom/server/src/main/webapp/WEB-INF/schema.xsd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mtom/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml b/mtom/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml new file mode 100644 index 0000000..58e0614 --- /dev/null +++ b/mtom/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mtom/server/src/main/webapp/WEB-INF/web.xml b/mtom/server/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..68288e8 --- /dev/null +++ b/mtom/server/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + + + MyCompany HR Holiday Service + + + spring-ws + org.springframework.ws.transport.http.MessageDispatcherServlet + + + + spring-ws + /* + + + diff --git a/mtom/settings.gradle b/mtom/settings.gradle new file mode 100644 index 0000000..b3428de --- /dev/null +++ b/mtom/settings.gradle @@ -0,0 +1,2 @@ + +include "server", "client:jax-ws", "client:spring-ws"