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/30 14:01:24 UTC

svn commit: r469140 - in /webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments: ./ resources/ resources/meta-inf/ src/ src/sample/ src/sample/soapwithattachments/ src/sample/soapwithattachments/client/ src/sample/soapwithattachments/...

Author: thilina
Date: Mon Oct 30 05:01:23 2006
New Revision: 469140

URL: http://svn.apache.org/viewvc?view=rev&rev=469140
Log:
new soap with attachments sample


Added:
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/build.xml
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/SWAClient.java   (with props)
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/
    webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/AttachmentService.java   (with props)

Added: webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/build.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/build.xml?view=auto&rev=469140
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/build.xml (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/build.xml Mon Oct 30 05:01:23 2006
@@ -0,0 +1,45 @@
+<project name="SOAPWithAttachmentsSample" default="service">
+	<property environment="env" />
+	<property name="axis2.home" value="../../" />
+	<property name="axis2.repo" value="${axis2.home}/repository" />
+	<property name="build.dir" value="build" />
+	<property name="client.classes.dir" value="${build.dir}/classes" />
+	<path id="axis.classpath">
+		<fileset dir="${axis2.home}/lib">
+			<include name="*.jar" />
+		</fileset>
+		<pathelement location="build/swaSampleClient.jar" />
+	</path>
+
+	<target name="service" depends="compile">
+		<jar destfile="${build.dir}/swaSample.aar">	
+			<fileset dir="src/sample/soapwithattachments/service/">
+				<include name="meta-inf/services.xml" />
+			</fileset>
+			<fileset dir="${build.dir}/classes">
+				<include name="sample/soapwithattachments/service/**/*.class" />
+			</fileset>
+		</jar>
+	</target>
+
+	<target name="compile">
+		<mkdir dir="${client.classes.dir}" />
+		<!-- Compile client -->
+		<javac srcdir="src" destdir="${client.classes.dir}">
+			<classpath refid="axis.classpath" />
+		</javac>
+	</target>
+	<target name="client" depends="compile">
+		<jar destfile="${build.dir}/swaSampleClient.jar">
+			<fileset dir="${build.dir}/classes">
+				<include name="sample/soapwithattachments/client/**/*.class" />
+			</fileset>
+		</jar>
+		<java classname="sample.soapwithattachments.client.SWAClient" classpathref="axis.classpath" fork="true">
+			<jvmarg value="-Daxis2.repo=${axis2.repo}" />
+		</java>
+	</target>
+	<target name="clean">
+		<delete dir="build" />
+	</target>
+</project>

Added: webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml?view=auto&rev=469140
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml Mon Oct 30 05:01:23 2006
@@ -0,0 +1,10 @@
+<service name="SWASampleService">
+    <description>
+        This is a sample Web Service for illustrating Attachments API of Axis2
+    </description>
+    <parameter name="ServiceClass" locked="false">sample.soapwithattachments.service.AttachmentService</parameter>
+    <operation name="uploadFile">
+        <actionMapping>urn:uploadFile</actionMapping>
+        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
+    </operation>
+</service>

Propchange: webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/resources/meta-inf/services.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/SWAClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/SWAClient.java?view=auto&rev=469140
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/SWAClient.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/client/SWAClient.java Mon Oct 30 05:01:23 2006
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+package sample.soapwithattachments.client;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.util.CommandLineOption;
+import org.apache.axis2.util.CommandLineOptionParser;
+import org.apache.axis2.util.OptionsValidator;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+public class SWAClient {
+
+	private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/swaSample");
+
+	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 destinationFile)
+			throws Exception {
+
+		Options options = new Options();
+		options.setTo(targetEPR);
+		options.setProperty(Constants.Configuration.ENABLE_SWA,
+				Constants.VALUE_TRUE);
+		options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+		options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+		options.setTimeOutInMilliSeconds(100000);
+//		options.setAction(Constants.AXIS2_NAMESPACE_URI + "/"
+//				+ operationName.getLocalPart());
+		options.setTo(targetEPR);
+
+		ConfigurationContext configContext = ConfigurationContextFactory
+				.createConfigurationContextFromFileSystem(
+						"../../repository", null);
+
+		ServiceClient sender = new ServiceClient(configContext, null);
+		sender.setOptions(options);
+		OperationClient mepClient = sender
+				.createClient(ServiceClient.ANON_OUT_IN_OP);
+
+		MessageContext mc = new MessageContext();
+		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);
+		String attachmentID = mc.addAttachment(dataHandler);
+		
+		SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+		SOAPEnvelope env = fac.getDefaultEnvelope();
+
+		OMNamespace omNs = fac.createOMNamespace("http://service.soapwithattachments.sample/xsd","swa");
+		OMElement nameEle = fac.createOMElement("param0", omNs);
+		nameEle.setText(destinationFile);
+		OMElement idEle = fac.createOMElement("param1", omNs);
+		idEle.setText(attachmentID);
+		
+		env.getBody().addChild(nameEle);
+		mc.setEnvelope(env);
+
+		mepClient.addMessageContext(mc);
+		mepClient.execute(true);
+		MessageContext response = mepClient
+				.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+	}
+}
\ No newline at end of file

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

Added: webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/AttachmentService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/AttachmentService.java?view=auto&rev=469140
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/AttachmentService.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/soapwithattachments/src/sample/soapwithattachments/service/AttachmentService.java Mon Oct 30 05:01:23 2006
@@ -0,0 +1,28 @@
+package sample.soapwithattachments.service;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axis2.context.MessageContext;
+
+public class AttachmentService {
+
+	public String uploadFile(String name, String attchmentID) throws IOException
+	{
+        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
+        Attachments attachment = msgCtx.getAttachmentMap();
+        DataHandler dataHandler = attachment.getDataHandler(attchmentID);
+        File file = new File(
+				name);
+		FileOutputStream fileOutputStream = new FileOutputStream(file);
+		dataHandler.writeTo(fileOutputStream);
+		fileOutputStream.flush();
+		fileOutputStream.close();
+		
+		return "File saved succesfully.";
+	}
+
+}

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



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