You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by th...@apache.org on 2006/10/28 12:52:54 UTC

svn commit: r468676 - in /webservices/axis2/branches/java/1_1/modules/samples/mtom: ./ resources/ src/ src/sample/ src/sample/mtom/ src/sample/mtom/client/ src/sample/mtom/service/

Author: thilina
Date: Sat Oct 28 03:52:53 2006
New Revision: 468676

URL: http://svn.apache.org/viewvc?view=rev&rev=468676
Log:
The new simplified MTOM sample..

Added:
    webservices/axis2/branches/java/1_1/modules/samples/mtom/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/
    webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java   (with props)

Added: webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml?view=auto&rev=468676
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml Sat Oct 28 03:52:53 2006
@@ -0,0 +1,106 @@
+<!--
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+ -->
+<project basedir="." default="clean">
+
+	<property environment="env" />
+	<property name="build.dir" value="build" />
+	<property name="client.dir" value="${build.dir}/client" />
+	<property name="service.dir" value="${build.dir}/service" />
+	<property name="client.classes.dir" value="${client.dir}/classes" />
+	<property name="skeleton.path" value="src/sample/mtom/service/MTOMServiceSkeleton.java" />
+	<property name="client.path" value="src/sample/mtom/client/Client.java" />
+	<!-- USE AXIS2_HOME FOR THIS -->
+	<property name="lib.dir" value="../lib" />
+
+	<path id="class.path">
+		<fileset dir="${env.AXIS2_HOME}/lib">
+			<include name="**/*.jar" />
+		</fileset>
+	</path>
+
+	<!-- Create Service -->
+	<target name="service">
+		<java classname="org.apache.axis2.wsdl.WSDL2Java">
+			<arg value="-uri" />
+			<arg value="resources/MTOMService.wsdl" />
+			<arg value="-ss" />
+			<arg value="-sd" />
+			<arg value="-p" />
+			<arg value="sample.mtom.service" />
+			<arg value="-o" />
+			<arg value="${service.dir}" />
+			<classpath refid="class.path" />
+		</java>
+		<copy file="${skeleton.path}" tofile="${service.dir}/${skeleton.path}" overwrite="true" />
+		
+	</target>
+	<target name="check-parameters">
+	 <condition property="parameters.set">
+			    <and>
+			      <isset property="dest"/>
+			      <isset property="file"/>
+			    </and>
+			  </condition>
+		<!-- This is a hack to get a if-else working in ant. Some much more "ANTy" person is welcome to improve this -->
+		<antcall target="print-usage"/>
+	</target>
+	
+	<target name="print-usage" unless="parameters.set">
+		<echo message="ant -Dfile &lt;file to be transfered&gt;  -Ddest &lt;name of the destination file&gt;"/>
+	</target>
+
+	<!-- Run Client -->
+	<target name="client" depends="check-parameters" if="parameters.set">
+		<java classname="org.apache.axis2.wsdl.WSDL2Java">
+			<arg value="-uri" />
+			<arg value="resources/MTOMSample.wsdl" />
+			<arg value="-p" />
+			<arg value="sample.mtom.service" />
+			<arg value="-o" />
+			<arg value="${client.dir}" />
+			<classpath refid="class.path" />
+		</java>
+
+		<copy file="${client.path}" tofile="${client.dir}/${client.path}" overwrite="true" />
+
+		<mkdir dir="${client.classes.dir}" />
+		<!-- Compile client -->
+		<javac srcdir="${client.dir}/src" destdir="${client.classes.dir}">
+			<classpath refid="class.path" />
+		</javac>
+
+		<!-- Run client -->
+		<!-- Accept two arguments from the command line, Also use the class.path set earlier -->
+		<java classname="sample.mtom.client.Client" fork="true">
+			<arg value="-file" />
+			<arg value="${file}" />
+			<arg value="-dest" />
+			<arg value="${dest}" />
+			<classpath>
+				<fileset dir="${env.AXIS2_HOME}/lib">
+					<include name="**/*.jar" />
+				</fileset>
+				<dirset dir="${client.classes.dir}" />
+			</classpath>
+		</java>
+	</target>
+
+	<target name="clean">
+		<delete dir="build" />
+	</target>
+</project>

Propchange: webservices/axis2/branches/java/1_1/modules/samples/mtom/build.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl?view=auto&rev=468676
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl Sat Oct 28 03:52:53 2006
@@ -0,0 +1,84 @@
+<wsdl:definitions xmlns:tns="http://ws.apache.org/axis2/mtomsample/"
+	xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
+	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+	xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
+	xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+	xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
+	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+	xmlns="http://schemas.xmlsoap.org/wsdl/"
+	targetNamespace="http://ws.apache.org/axis2/mtomsample/">
+	<wsdl:types>
+		<xsd:schema xmlns="http://schemas.xmlsoap.org/wsdl/"
+			attributeFormDefault="qualified" elementFormDefault="qualified"
+			targetNamespace="http://ws.apache.org/axis2/mtomsample/">
+			<xsd:import namespace="http://www.w3.org/2005/05/xmlmime"
+				schemaLocation="xmime.xsd" />
+			<xsd:complexType name="AttachmentType">
+				<xsd:sequence>
+					<xsd:element minOccurs="0" name="fileName"
+						type="xsd:string" />
+					<xsd:element minOccurs="0" name="binaryData"
+						type="xmime:base64Binary" />
+				</xsd:sequence>
+			</xsd:complexType>
+			<xsd:element name="AttachmentRequest" type="tns:AttachmentType" />
+			<xsd:element name="AttachmentResponse" type="xsd:string" />
+		</xsd:schema>
+	</wsdl:types>
+	<wsdl:message name="AttachmentRequest">
+		<wsdl:part name="part1" element="tns:AttachmentRequest" />
+	</wsdl:message>
+	<wsdl:message name="AttachmentResponse">
+		<wsdl:part name="part1" element="tns:AttachmentResponse" />
+	</wsdl:message>
+	<wsdl:portType name="MTOMServicePortType">
+		<wsdl:operation name="attachment">
+			<wsdl:input message="tns:AttachmentRequest"
+				wsaw:Action="attachment" />
+			<wsdl:output message="tns:AttachmentResponse"
+				wsaw:Action="http://schemas.xmlsoap.org/wsdl/MTOMServicePortType/AttachmentResponse" />
+		</wsdl:operation>
+	</wsdl:portType>
+	<wsdl:binding name="MTOMServiceSOAP11Binding"
+		type="tns:MTOMServicePortType">
+		<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
+			style="document" />
+		<wsdl:operation name="attachment">
+			<soap:operation soapAction="attachment" style="document" />
+			<wsdl:input>
+				<soap:body use="literal" />
+			</wsdl:input>
+			<wsdl:output>
+				<soap:body use="literal" />
+			</wsdl:output>
+		</wsdl:operation>
+	</wsdl:binding>
+	<wsdl:binding name="MTOMServiceSOAP12Binding"
+		type="tns:MTOMServicePortType">
+		<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"
+			style="document" />
+		<wsdl:operation name="attachment">
+			<soap12:operation soapAction="attachment" style="document" />
+			<wsdl:input>
+				<soap12:body use="literal" />
+			</wsdl:input>
+			<wsdl:output>
+				<soap12:body use="literal" />
+			</wsdl:output>
+		</wsdl:operation>
+	</wsdl:binding>
+	<wsdl:service name="MTOMSample">
+		<wsdl:port name="MTOMSampleSOAP11port_http"
+			binding="tns:MTOMServiceSOAP11Binding">
+			<soap:address
+				location="http://localhost:8080/axis2/services/MTOMSample" />
+		</wsdl:port>
+		<wsdl:port name="MTOMSampleSOAP12port_http"
+			binding="tns:MTOMServiceSOAP12Binding">
+			<soap12:address
+				location="http://localhost:8080/axis2/services/MTOMService" />
+		</wsdl:port>
+	</wsdl:service>
+</wsdl:definitions>
\ No newline at end of file

Propchange: webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/MTOMSample.wsdl
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd?view=auto&rev=468676
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd Sat Oct 28 03:52:53 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+	targetNamespace="http://www.w3.org/2005/05/xmlmime">
+	<xs:attribute name="contentType">
+		<xs:simpleType>
+			<xs:restriction base="xs:string">
+				<xs:minLength value="3" />
+			</xs:restriction>
+		</xs:simpleType>
+	</xs:attribute>
+	<xs:attribute name="expectedContentTypes" type="xs:string" />
+	<xs:complexType name="base64Binary">
+		<xs:simpleContent>
+			<xs:extension base="xs:base64Binary">
+				<xs:attribute ref="xmime:contentType" />
+			</xs:extension>
+		</xs:simpleContent>
+	</xs:complexType>
+	<xs:complexType name="hexBinary">
+		<xs:simpleContent>
+			<xs:extension base="xs:hexBinary">
+				<xs:attribute ref="xmime:contentType" />
+			</xs:extension>
+		</xs:simpleContent>
+	</xs:complexType>
+</xs:schema>

Propchange: webservices/axis2/branches/java/1_1/modules/samples/mtom/resources/xmime.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java?view=auto&rev=468676
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java Sat Oct 28 03:52:53 2006
@@ -0,0 +1,100 @@
+package sample.mtom.client;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.rmi.RemoteException;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.util.CommandLineOption;
+import org.apache.axis2.util.CommandLineOptionParser;
+import org.apache.axis2.util.OptionsValidator;
+
+import sample.mtom.service.MTOMSampleStub;
+import sample.mtom.service.MTOMSampleStub.AttachmentRequest;
+import sample.mtom.service.MTOMSampleStub.AttachmentResponse;
+import sample.mtom.service.MTOMSampleStub.AttachmentType;
+import sample.mtom.service.MTOMSampleStub.Base64Binary;
+
+public class Client {
+
+	/**
+	 * @param args
+	 * @throws Exception
+	 */
+	public static void main(String[] args) throws Exception {
+		CommandLineOptionParser optionsParser = new CommandLineOptionParser(
+				args);
+		List invalidOptionsList = optionsParser
+				.getInvalidOptions(new OptionsValidator() {
+					public boolean isInvalid(CommandLineOption option) {
+						String optionType = option.getOptionType();
+						return !("dest".equalsIgnoreCase(optionType) || "file"
+								.equalsIgnoreCase(optionType));
+					}
+				});
+
+		if ((invalidOptionsList.size() > 0) || (args.length != 4)) {
+			// printUsage();
+			System.out.println("Invalid Parameters.");
+			return;
+		}
+
+		Map optionsMap = optionsParser.getAllOptions();
+
+		CommandLineOption fileOption = (CommandLineOption) optionsMap
+				.get("file");
+		CommandLineOption destinationOption = (CommandLineOption) optionsMap
+				.get("dest");
+		File file = new File(fileOption.getOptionValue());
+		if (file.exists())
+			transferFile(file, destinationOption.getOptionValue());
+		else
+			throw new FileNotFoundException();
+	}
+
+	public static void transferFile(File file, String destination)
+			throws RemoteException {
+		MTOMSampleStub serviceStub = new MTOMSampleStub(
+				"http://localhost:8081/axis2/services/MTOMSample");
+
+		// Enable MTOM in the client side
+		serviceStub._getServiceClient().getOptions().setProperty(
+				Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+
+		// Uncomment and fill the following if you want to have client side file
+		// caching switched ON.
+		/*
+		 * serviceStub._getServiceClient().getOptions().setProperty(
+		 * Constants.Configuration.CACHE_ATTACHMENTS, Constants.VALUE_TRUE);
+		 * serviceStub._getServiceClient().getOptions().setProperty(
+		 * Constants.Configuration.ATTACHMENT_TEMP_DIR, "your temp dir");
+		 * serviceStub._getServiceClient().getOptions().setProperty(
+		 * Constants.Configuration.FILE_SIZE_THRESHOLD, "4000");
+		 */
+
+		// Populating the code generated beans
+		AttachmentRequest attachmentRequest = new AttachmentRequest();
+		AttachmentType attachmentType = new AttachmentType();
+		Base64Binary base64Binary = new Base64Binary();
+
+		// Creating a javax.activation.FileDataSource from the input file.
+		FileDataSource fileDataSource = new FileDataSource(file);
+		// Create a dataHandler using the fileDataSource. Any implementation of
+		// javax.activation.DataSource interface can fit here.
+		DataHandler dataHandler = new DataHandler(fileDataSource);
+		base64Binary.setBase64Binary(dataHandler);
+		base64Binary.setContentType(dataHandler.getContentType());
+		attachmentType.setBinaryData(base64Binary);
+		attachmentType.setFileName(destination);
+		attachmentRequest.setAttachmentRequest(attachmentType);
+
+		AttachmentResponse response = serviceStub.attachment(attachmentRequest);
+		System.out.println(response.getAttachmentResponse());
+	}
+
+}

Propchange: webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/client/Client.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java?view=auto&rev=468676
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java Sat Oct 28 03:52:53 2006
@@ -0,0 +1,50 @@
+/**
+ * MTOMServiceSkeleton.java
+ *
+ * This file was auto-generated from WSDL
+ * by the Apache Axis2 version: 1.1-SNAPSHOT Oct 19, 2006 (07:04:21 LKT)
+ */
+package sample.mtom.service;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import javax.activation.DataHandler;
+
+import org.apache.ws.axis2.mtomsample.AttachmentResponse;
+import org.apache.ws.axis2.mtomsample.AttachmentType;
+import org.w3.www._2005._05.xmlmime.Base64Binary;
+
+/**
+ * MTOMServiceSkeleton java skeleton for the axisService
+ */
+public class MTOMSampleSkeleton {
+
+	/**
+	 * Auto generated method signature
+	 * 
+	 * @param param0
+	 * @throws Exception 
+	 * 
+	 */
+	public org.apache.ws.axis2.mtomsample.AttachmentResponse attachment(
+			org.apache.ws.axis2.mtomsample.AttachmentRequest param0)
+			throws Exception
+
+	{
+		AttachmentType attachmentRequest = param0.getAttachmentRequest();
+		Base64Binary binaryData = attachmentRequest.getBinaryData();
+		DataHandler dataHandler = binaryData.getBase64Binary();
+		File file = new File(
+				attachmentRequest.getFileName());
+		FileOutputStream fileOutputStream = new FileOutputStream(file);
+		dataHandler.writeTo(fileOutputStream);
+		fileOutputStream.flush();
+		fileOutputStream.close();
+		
+		AttachmentResponse response = new AttachmentResponse();
+		response.setAttachmentResponse("File saved succesfully.");
+		return response;
+	}
+
+}

Propchange: webservices/axis2/branches/java/1_1/modules/samples/mtom/src/sample/mtom/service/MTOMSampleSkeleton.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org