diff --git a/samples/mtom/client/jaxws/src/org/springframework/ws/samples/mtom/client/jaxws/Main.java b/samples/mtom/client/jaxws/src/org/springframework/ws/samples/mtom/client/jaxws/Main.java
index ea4e92dd..9e789ffd 100644
--- a/samples/mtom/client/jaxws/src/org/springframework/ws/samples/mtom/client/jaxws/Main.java
+++ b/samples/mtom/client/jaxws/src/org/springframework/ws/samples/mtom/client/jaxws/Main.java
@@ -18,12 +18,9 @@ package org.springframework.ws.samples.mtom.client.jaxws;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.net.MalformedURLException;
+import java.awt.image.RenderedImage;
+import java.awt.Toolkit;
import javax.activation.DataHandler;
-import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.SOAPFaultException;
@@ -42,13 +39,13 @@ public class Main {
ImageRepositoryService service = new ImageRepositoryService();
ImageRepository imageRepository = service.getImageRepositoryPort();
- SOAPBinding binding = (SOAPBinding)((BindingProvider)imageRepository).getBinding ();
- binding.setMTOMEnabled (true);
-
+ SOAPBinding binding = (SOAPBinding) ((BindingProvider) imageRepository).getBinding();
+ binding.setMTOMEnabled(true);
+
Image request = new Image();
File file = new File(args[0]);
request.setName(file.getName());
- request.setImage(new DataHandler(file.toURL()));
+ request.setImage(Toolkit.getDefaultToolkit().getImage(args[0]));
StopWatch stopWatch = new StopWatch();
stopWatch.start("store");
imageRepository.storeImage(request);
diff --git a/samples/mtom/pom.xml b/samples/mtom/pom.xml
index 01f5cdd3..5d02837a 100644
--- a/samples/mtom/pom.xml
+++ b/samples/mtom/pom.xml
@@ -55,6 +55,7 @@
org.springframework.ws
spring-oxm-tiger
+ runtime
diff --git a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java
index 2f9e9c34..3107214e 100644
--- a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java
+++ b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/ImageRepository.java
@@ -16,15 +16,14 @@
package org.springframework.ws.samples.mtom.service;
-import java.io.InputStream;
+import java.awt.Image;
import java.io.IOException;
-import java.io.OutputStream;
/** @author Arjen Poutsma */
public interface ImageRepository {
- void streamImage(String name, OutputStream os) throws IOException;
+ Image readImage(String name) throws IOException;
- void storeImage(String name, InputStream is) throws IOException;
+ void storeImage(String name, Image image) throws IOException;
}
diff --git a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java
index 4e9b30ca..07a96e1e 100644
--- a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java
+++ b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/service/StubImageRepository.java
@@ -16,34 +16,28 @@
package org.springframework.ws.samples.mtom.service;
+import java.awt.Image;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.springframework.util.FileCopyUtils;
/** @author Arjen Poutsma */
public class StubImageRepository implements ImageRepository {
private static final Log logger = LogFactory.getLog(StubImageRepository.class);
- private Map images = new HashMap();
+ private Map images = new HashMap();
- public void streamImage(String name, OutputStream os) throws IOException {
- if (images.containsKey(name)) {
- logger.info("Streaming image " + name);
- byte[] buf = images.get(name);
- FileCopyUtils.copy(buf, os);
- }
+ public Image readImage(String name) throws IOException {
+ logger.info("Streaming image " + name);
+ return images.get(name);
}
- public void storeImage(String name, InputStream is) throws IOException {
- byte[] buf = FileCopyUtils.copyToByteArray(is);
- logger.info("Storing image " + name + " with size: " + buf.length);
- images.put(name, buf);
+ public void storeImage(String name, Image image) throws IOException {
+ logger.info("Storing image " + name + " with [" + image.getHeight(null) + "," + image.getWidth(null) + "]");
+ images.put(name, image);
}
}
diff --git a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java
index 62341084..1f1c53fd 100644
--- a/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java
+++ b/samples/mtom/src/main/java/org/springframework/ws/samples/mtom/ws/ImageRepositoryEndpoint.java
@@ -16,15 +16,11 @@
package org.springframework.ws.samples.mtom.ws;
-import java.io.IOException;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import javax.activation.DataHandler;
-import javax.activation.DataSource;
import javax.xml.bind.JAXBElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.util.FileCopyUtils;
import org.springframework.util.Assert;
import org.springframework.ws.samples.mtom.schema.Image;
import org.springframework.ws.samples.mtom.schema.ObjectFactory;
@@ -49,19 +45,17 @@ public class ImageRepositoryEndpoint {
@PayloadRoot(localPart = "StoreImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
public void store(JAXBElement requestElement) throws IOException {
Image request = requestElement.getValue();
- imageRepository.storeImage(request.getName(), request.getImage().getInputStream());
+ imageRepository.storeImage(request.getName(), request.getImage());
}
@PayloadRoot(localPart = "LoadImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
public JAXBElement load(JAXBElement requestElement) throws IOException {
String name = requestElement.getValue();
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- imageRepository.streamImage(name, os);
- DataHandler dataHandler = new DataHandler(os.toByteArray(), "application/octet-stream");
Image response = new Image();
response.setName(name);
- response.setImage(dataHandler);
+ response.setImage(imageRepository.readImage(name));
return objectFactory.createLoadImageResponse(response);
}
+
}
diff --git a/samples/mtom/src/main/webapp/WEB-INF/schema.xsd b/samples/mtom/src/main/webapp/WEB-INF/schema.xsd
index 9582b45c..1af18f52 100644
--- a/samples/mtom/src/main/webapp/WEB-INF/schema.xsd
+++ b/samples/mtom/src/main/webapp/WEB-INF/schema.xsd
@@ -12,7 +12,7 @@
-
+