This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
<artifactId>spring-oxm-tiger</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- JEE Mapping dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, byte[]> images = new HashMap<String, byte[]>();
|
||||
private Map<String, Image> images = new HashMap<String, Image>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Image> 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<Image> load(JAXBElement<String> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<complexType name="Image">
|
||||
<sequence>
|
||||
<element name="name" type="string"/>
|
||||
<element name="image" type="base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
|
||||
<element name="image" type="base64Binary" xmime:expectedContentTypes="image/png"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user