From fe63e180024d4249db36ec4376ab1f6721d91b07 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 15 May 2009 09:54:06 +0000 Subject: [PATCH] SWS-496 - Added Tareq's Spring-WS MTOM client --- samples/mtom/client/spring-ws/build.xml | 85 +++++++++++++++++++ .../samples/mtom/client/sws/MtomClient.java | 65 ++++++++++++++ .../mtom/client/sws/applicationContext.xml | 16 ++++ 3 files changed, 166 insertions(+) create mode 100644 samples/mtom/client/spring-ws/build.xml create mode 100644 samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/MtomClient.java create mode 100644 samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml diff --git a/samples/mtom/client/spring-ws/build.xml b/samples/mtom/client/spring-ws/build.xml new file mode 100644 index 00000000..df451513 --- /dev/null +++ b/samples/mtom/client/spring-ws/build.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/MtomClient.java b/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/MtomClient.java new file mode 100644 index 00000000..c79a953e --- /dev/null +++ b/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/MtomClient.java @@ -0,0 +1,65 @@ +/* + * 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 java.io.File; +import javax.xml.bind.JAXBElement; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.util.StopWatch; +import org.springframework.ws.client.core.support.WebServiceGatewaySupport; +import org.springframework.ws.soap.client.SoapFaultClientException; + +/** + * Simple client that demonstartes MTOM by invoking StoreImage and LoadImage using a + * WebServiceTemplate. + * + * @author Tareq Abed Rabbo + */ +public class MtomClient extends WebServiceGatewaySupport { + + public static void main(String[] args) { + try { + ApplicationContext applicationContext = + new ClassPathXmlApplicationContext("applicationContext.xml", MtomClient.class); + MtomClient client = (MtomClient) applicationContext.getBean("mtomClient", MtomClient.class); + + ObjectFactory objectFactory = new ObjectFactory(); + Image image = objectFactory.createImage(); + File file = new File(args[0]); + image.setName(file.getName()); + image.setImage(Toolkit.getDefaultToolkit().getImage(args[0])); + JAXBElement storeImageRequest = objectFactory.createStoreImageRequest(image); + StopWatch stopWatch = new StopWatch(); + stopWatch.start("store"); + client.getWebServiceTemplate().marshalSendAndReceive(storeImageRequest); + stopWatch.stop(); + JAXBElement loadImageRequest = objectFactory.createLoadImageRequest(file.getName()); + + stopWatch.start("load"); + Object result = client.getWebServiceTemplate().marshalSendAndReceive(loadImageRequest); + stopWatch.stop(); + 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()); + } + } +} diff --git a/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml b/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml new file mode 100644 index 00000000..cb472847 --- /dev/null +++ b/samples/mtom/client/spring-ws/src/org/springframework/ws/samples/mtom/client/sws/applicationContext.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + +