You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by th...@apache.org on 2006/09/28 10:41:28 UTC

svn commit: r450759 - in /webservices/axis2/trunk/java/modules/samples: ./ src/sample/mtom/filetransfer/ src/sample/mtom/filetransfer/client/ src/sample/mtom/filetransfer/service/ src/sample/mtom/filetransfer/service/meta-inf/

Author: thilina
Date: Thu Sep 28 01:41:26 2006
New Revision: 450759

URL: http://svn.apache.org/viewvc?view=rev&rev=450759
Log:
Commited the patch at http://issues.apache.org/jira/browse/AXIS2-1259
Did some changes to make it compatible with JDK1.5
Modified the maven.xml to build the new sample

Thanks Saliya for this excellent improvement to the MTOM/SwA sample


Added:
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java   (with props)
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java   (with props)
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java   (with props)
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java   (with props)
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/
    webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml   (with props)
Modified:
    webservices/axis2/trunk/java/modules/samples/maven.xml

Modified: webservices/axis2/trunk/java/modules/samples/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/maven.xml?view=diff&rev=450759&r1=450758&r2=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/samples/maven.xml Thu Sep 28 01:41:26 2006
@@ -209,7 +209,7 @@
     </goal>
 
     <!-- ================================================================ -->
-    <!--- Google MTOM Sample -->
+    <!--- MTOM Sample -->
     <!-- ================================================================ -->
 
     <goal name="mtomSample">
@@ -224,16 +224,16 @@
             <ant:fileset dir="script/mtomSample"/>
         </ant:copy>
         <jar destfile="${samples.dir}/mtom/mtomSample.aar">
-            <fileset dir="src/sample/mtom/imagetransfer/service/">
+            <fileset dir="src/sample/mtom/filetransfer/service/">
                 <include name="META-INF/**"/>
             </fileset>
             <fileset dir="target/classes">
-                <include name="sample/mtom/imagetransfer/service/**/*.class"/>
+                <include name="sample/mtom/filetransfer/service/**/*.class"/>
             </fileset>
         </jar>
         <jar destfile="${samples.dir}/mtom/mtomClient.jar">
             <fileset dir="target/classes">
-                <include name="sample/mtom/imagetransfer/client/**/*.class"/>
+                <include name="sample/mtom/filetransfer/client/**/*.class"/>
             </fileset>
         </jar>
     </goal>

Added: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java?view=auto&rev=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java Thu Sep 28 01:41:26 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.mtom.filetransfer.client;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class MTOMClient extends JFrame {
+    public static final int TOLERANCE = 200;
+    public static final int WIDTH = 430;
+    public static final int HEIGHT = 560;
+
+    public MTOMClient(String title) throws HeadlessException {
+        super(title);
+
+        this.getContentPane().add(new UserInterface(this));
+        this.setVisible(true);
+    }
+
+    public static void main(String[] args) {
+        MTOMClient form = new MTOMClient("MTOM Sample Client");
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        int left = (screenSize.width - WIDTH) / 2;
+        int top = (screenSize.height - HEIGHT) / 2;
+        form.setLocation(left, top);
+        form.setSize(WIDTH, HEIGHT);
+        form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+        form.setVisible(true);
+    }
+}

Propchange: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClient.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java?view=auto&rev=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java Thu Sep 28 01:41:26 2006
@@ -0,0 +1,369 @@
+/*
+ * 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.mtom.filetransfer.client;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.awt.image.BufferedImage;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.imageio.ImageIO;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.*;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axis2.Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.OperationClient;
+
+
+public class MTOMClientModel {
+    private ArrayList fileList = null;
+
+    private String cacheFolder;
+
+    private int cacheThreshold;
+
+    private EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/mtomSample");
+
+    public MTOMClientModel() {
+
+    }
+
+    /**
+     * @param cacheThreshold Threshold value in bytes
+     */
+    public void setCacheThreshold(int cacheThreshold) {
+        this.cacheThreshold = cacheThreshold;
+    }
+
+    /**
+     * @param cacheFolder Absolute path of the cache folder
+     */
+    public void setCacheFolder(String cacheFolder) {
+        this.cacheFolder = cacheFolder;
+    }
+
+    /**
+     * @param folderName Absolute path of the destination folder
+     * @param operation  Name of the appropriate operation on the server
+     * @return The payload
+     * @throws Exception
+     */
+    private OMElement buildPayloadForMTOM(String folderName, String operation) throws Exception {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+
+        OMElement data = fac.createOMElement(operation, omNs);
+        OMElement folder = fac.createOMElement("folderName", omNs);
+        if (folderName != null) {
+            folder.setText(folderName);
+        }
+        data.addChild(folder);
+
+        OMElement files = fac.createOMElement("files", omNs);
+        data.addChild(files);
+
+        DataHandler dataHandler;
+
+        for (int i = 0; i < fileList.size(); i++) {
+            OMElement file = fac.createOMElement("file" + (i + 1), omNs);
+            file.addAttribute(fac.createOMAttribute("type", omNs, ((File)fileList.get(i)).getName()));
+            FileDataSource dataSource = new FileDataSource((File)fileList.get(i));
+            dataHandler = new DataHandler(dataSource);
+            OMText textData = fac.createOMText(dataHandler, true);
+            file.addChild(textData);
+            files.addChild(file);
+        }
+        return data;
+
+    }
+
+    /**
+     * @param folderName Absolute path of the destination folder
+     * @param operation  Name of the appropriate operation on the server
+     * @return The message context
+     * @throws Exception
+     */
+    private MessageContext createMessageContextForSwA(String folderName, String operation) throws Exception {
+
+        MessageContext mc = new MessageContext();
+        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope soapEnvelope = fac.createSOAPEnvelope();
+
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+        OMElement data = fac.createOMElement(operation, omNs);
+        OMElement folder = fac.createOMElement("folderName", omNs);
+        if (folderName != null) {
+            folder.setText(folderName);
+        }
+        data.addChild(folder);
+        OMElement files = fac.createOMElement("files", omNs);
+        data.addChild(files);
+
+        DataHandler dataHandler;
+        for (int i = 0; i < fileList.size(); i++) {
+            OMElement file = fac.createOMElement("file" + (i + 1), omNs);
+            file.addAttribute(fac.createOMAttribute("type", omNs,((File)fileList.get(i)).getName()));
+            FileDataSource dataSource = new FileDataSource((File)fileList.get(i));
+            dataHandler = new DataHandler(dataSource);
+            String contentID = mc.addAttachment(dataHandler);
+
+            file.setText(contentID);
+            files.addChild(file);
+        }
+        SOAPBody body = fac.createSOAPBody(soapEnvelope);
+        body.addChild(data);
+        mc.setEnvelope(soapEnvelope);
+        return mc;
+
+    }
+
+    /**
+     * @param folderName Absolute path of the destination folder
+     * @return The response from the server
+     * @throws Exception
+     */
+    public OMElement sendFilesUsingSwA(String folderName) 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);
+
+        ServiceClient sender = new ServiceClient(null, null);
+        sender.setOptions(options);
+        OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
+
+        MessageContext mc = createMessageContextForSwA(folderName, "uploadFileUsingSwA");
+        mepClient.addMessageContext(mc);
+        mepClient.execute(true);
+        MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+        return (OMElement) (response.getEnvelope().getBody().getChildren().next());
+    }
+
+    /**
+     * @param folderName Absolute path of the destination folder
+     * @return The response from the server
+     * @throws Exception
+     */
+    public OMElement sendFilesUsingMTOM(String folderName) throws Exception {
+
+        OMElement payload = buildPayloadForMTOM(folderName, "uploadFileUsingMTOM");
+        Options options = new Options();
+        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        options.setTo(targetEPR);
+        // enabling MTOM in the client side
+        options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+        ServiceClient sender = new ServiceClient();
+        sender.setOptions(options);
+        return sender.sendReceive(payload);
+    }
+
+    public OMElement sendReceiveUsingMTOM(String folderName, boolean cacheEnable) throws Exception {
+        OMElement payload = buildPayloadForMTOM(folderName, "sendReceiveUsingMTOM");
+        Options options = new Options();
+        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        options.setTo(targetEPR);
+
+        // enabling MTOM in the client side
+        options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+        // enabling file caching in the client side
+        if (cacheEnable) {
+            options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS,
+                    Constants.VALUE_TRUE);
+            options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR, cacheFolder);
+            options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, ("" + cacheThreshold));
+        }
+        ServiceClient sender = new ServiceClient();
+        sender.setOptions(options);
+        OMElement response = sender.sendReceive(payload);
+        response.buildWithAttachments();
+        return handleMTOMResponse(response);
+    }
+
+    public OMElement sendReceiveUsingSwA(String folderName, boolean cacheEnable) 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);
+
+        // enabling file caching in the client side
+        if (cacheEnable) {
+            options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS,
+                    Constants.VALUE_TRUE);
+            options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR, cacheFolder);
+            options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, ("" + cacheThreshold));
+        }
+
+        ServiceClient sender = new ServiceClient(null, null);
+        sender.setOptions(options);
+        OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
+
+        MessageContext mc = createMessageContextForSwA(folderName, "sendReceiveUsingSwA");
+        mepClient.addMessageContext(mc);
+        mepClient.execute(true);
+        MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+        return handleSwAResponse(response);
+
+    }
+
+
+    private OMElement handleMTOMResponse(OMElement element) throws Exception {
+        OMElement folder;
+        OMElement files;
+        OMElement file;
+        String folderName;
+
+        Iterator itr = element.getChildElements();
+        folder = (OMElement) itr.next();
+        if (folder == null) throw new AxisFault("Destination Folder is null");
+        folderName = folder.getText();
+        File destFolder = new File(folderName);
+        if (!destFolder.exists()) {
+            destFolder.mkdirs();
+        }
+
+        files = (OMElement) itr.next();
+        itr = files.getChildElements();
+
+        int i = 1;
+        String fileName = null;
+        while (itr.hasNext()) {
+            file = (OMElement) itr.next();
+            if (file == null) throw new AxisFault("File " + i + " is null");
+            OMText binaryNode = (OMText) file.getFirstOMChild();
+            DataHandler dataHandler;
+            dataHandler = (DataHandler) binaryNode.getDataHandler();
+            fileName = createFileName(folderName, file, i);
+            writeData(dataHandler.getDataSource().getInputStream(), fileName);
+            i++;
+        }
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
+        OMElement ele = fac.createOMElement("handledResponse", ns);
+        ele.setText("" + (i - 1) + " Files(s) Saved Successfully on Client at " + folderName);
+        return ele;
+    }
+
+    private OMElement handleSwAResponse(MessageContext mc) throws Exception {
+        String folderName;
+        OMElement folder;
+        OMElement files;
+        OMElement file;
+
+        OMElement element = (OMElement) (mc.getEnvelope().getBody().getChildren().next());
+
+        Iterator itr = element.getChildElements();
+        folder = (OMElement) itr.next();
+        if (folder == null) throw new AxisFault("Destination Folder is null");
+        folderName = folder.getText();
+        File destFolder = new File(folderName);
+        if (!destFolder.exists()) {
+            destFolder.mkdirs();
+        }
+
+        files = (OMElement) itr.next();
+        itr = files.getChildElements();
+
+        Attachments attachment = mc.getAttachmentMap();
+
+        int i = 1;
+        String fileName;
+        DataHandler dataHandler;
+        while (itr.hasNext()) {
+            file = (OMElement) itr.next();
+            if (file == null) throw new AxisFault("File " + i + " is null");
+            dataHandler = attachment.getDataHandler(file.getText());
+            fileName = createFileName(folderName, file, i);
+            writeData(dataHandler.getDataSource().getInputStream(), fileName);
+            i++;
+        }
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
+        OMElement ele = fac.createOMElement("response", ns);
+        ele.setText("" + (i - 1) + " File(s) Saved Successfully on Client at " + folderName);
+        return ele;
+
+    }
+
+
+    /**
+     * @param inStrm   An input stream linking to the data
+     * @param fileName The absolute path of the file to which the data should be written
+     * @throws Exception
+     */
+    private void writeData(InputStream inStrm, String fileName) throws Exception {
+        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+        int b;
+        while (true) {
+            b = inStrm.read();
+            if (b == -1) {
+                break;
+            }
+            raf.writeByte(b);
+        }
+        inStrm.close();
+        raf.close();
+    }
+
+    private String createFileName(String folderName, OMElement file, int count) {
+        String fileName;
+        fileName = folderName + "/" + file.getAttributeValue(
+                new QName(file.getNamespace().getNamespaceURI(), "type"));
+
+        if (new File(fileName).exists()) {
+            fileName = folderName + "/copy(" + (count - 1) + ")" + file.getAttributeValue(
+                    new QName(file.getNamespace().getNamespaceURI(), "type"));
+            while (new File(fileName).exists()) {
+                count ++;
+                fileName = folderName + "/copy(" + (count - 1) + ")" + file.getAttributeValue(
+                        new QName(file.getNamespace().getNamespaceURI(), "type"));
+            }
+        }
+
+        return fileName;
+    }
+
+
+    public void setTargetEPR(String targetEPR) {
+        this.targetEPR = new EndpointReference(targetEPR);
+
+    }
+
+
+    public void setFileList(ArrayList fileList) {
+        this.fileList = fileList;
+    }
+}

Propchange: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/MTOMClientModel.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java?view=auto&rev=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java Thu Sep 28 01:41:26 2006
@@ -0,0 +1,420 @@
+/*
+ * 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.mtom.filetransfer.client;
+
+import org.apache.axiom.om.OMElement;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.io.File;
+import java.util.ArrayList;
+
+public class UserInterface extends JPanel implements ActionListener {
+
+    JButton browseButton;
+    JButton addFileButton;
+    JButton removeButton;
+    JButton executeButton;
+
+    JRadioButton sendRadio;
+    JRadioButton sendRecRadio;
+    JRadioButton MTOMRadio;
+    JRadioButton SOAPRadio;
+
+    JCheckBox cacheBox;
+
+    DefaultListModel model;
+    JList fileList;
+    JScrollPane fileListScroller;
+    JFileChooser fileChooser;
+
+    File file = null;
+
+    JTextField cacheThresholdText;
+    JTextField cacheFolderText;
+    JTextField EPRText;
+    JTextField destFolderText;
+    JTextField fileField;
+
+    JLabel fileListLabel;
+    JLabel EPRLabel;
+    JLabel destDir;
+    JLabel opLabel;
+    JLabel MTOMSOAPLabel;
+    JLabel thresholdLabel;
+    JLabel cacheFolderLabel;
+
+    private boolean cacheEnable = false;
+
+    private String destFolder = null;
+
+    private String EPR = null;
+
+    private ArrayList files;
+
+    private MTOMClient parent;
+
+    private MTOMClientModel mtomTest;
+
+    public UserInterface(MTOMClient parent) {
+        this.parent = parent;
+        initComponents();
+
+        browseButton.addActionListener(this);
+        addFileButton.addActionListener(this);
+        removeButton.addActionListener(this);
+
+        fileField.addKeyListener(new KeyListener() {
+            public void keyTyped(KeyEvent e) {
+                addFileButton.setEnabled(true);
+
+            }
+
+            public void keyPressed(KeyEvent e) {
+            }
+
+            public void keyReleased(KeyEvent e) {
+                if (fileField.getText().equals("")) {
+                    addFileButton.setEnabled(false);
+                }
+            }
+        });
+
+        MTOMRadio.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                switchRadios(MTOMRadio, SOAPRadio);
+            }
+        });
+        SOAPRadio.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                switchRadios(SOAPRadio, MTOMRadio);
+            }
+        });
+
+        sendRadio.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                switchRadios(sendRadio, sendRecRadio);
+                cacheBox.setEnabled(false);
+                cacheBox.setSelected(false);
+                enableCaching();
+            }
+        });
+        sendRecRadio.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                switchRadios(sendRecRadio, sendRadio);
+                cacheBox.setEnabled(true);
+                enableCaching();
+            }
+        });
+
+        cacheBox.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                enableCaching();
+            }
+        });
+
+        executeButton.addActionListener(this);
+
+
+        Container pane = parent.getContentPane();
+        this.setLayout(null);
+
+        pane.add(fileField);
+        pane.add(browseButton);
+        pane.add(addFileButton);
+        pane.add(removeButton);
+
+        pane.add(fileListLabel);
+        pane.add(fileListScroller);
+
+        pane.add(destDir);
+        pane.add(destFolderText);
+
+        pane.add(EPRLabel);
+        pane.add(EPRText);
+
+        pane.add(opLabel);
+        pane.add(MTOMRadio);
+        pane.add(SOAPRadio);
+
+        pane.add(MTOMSOAPLabel);
+        pane.add(sendRadio);
+        pane.add(sendRecRadio);
+
+        pane.add(cacheBox);
+
+        pane.add(thresholdLabel);
+        pane.add(cacheThresholdText);
+
+        pane.add(cacheFolderLabel);
+        pane.add(cacheFolderText);
+
+        pane.add(executeButton);
+    }
+
+    public void initComponents() {
+        files = new ArrayList(0);
+
+        fileField = new JTextField();
+        fileField.setBounds(20, 20, 270, 20);
+
+        this.browseButton = new JButton("Browse");
+        browseButton.setBounds(300, 20, 100, 20);
+
+        addFileButton = new JButton("Add");
+        addFileButton.setBounds(20, 50, 100, 20);
+        addFileButton.setEnabled(false);
+
+        removeButton = new JButton("Remove Selection");
+        removeButton.setBounds(140, 50, 150, 20);
+        removeButton.setEnabled(false);
+
+        fileListLabel = new JLabel("File List");
+        fileListLabel.setBounds(20, 80, 50, 20);
+
+        model = new DefaultListModel();
+        fileList = new JList(model);
+        fileListScroller = new JScrollPane(fileList);
+        fileListScroller.setBounds(20, 100, 380, 80);
+
+
+        destDir = new JLabel("Dest. Folder: ", JLabel.RIGHT);
+        destDir.setBounds(20, 200, 100, 20);
+        destFolderText = new JTextField();
+        destFolderText.setBounds(120, 200, 280, 20);
+
+
+        EPRLabel = new JLabel("End Point: ", JLabel.RIGHT);
+        EPRLabel.setBounds(20, 230, 100, 20);
+        EPRText = new JTextField();
+        EPRText.setText("http://127.0.0.1:8080/axis2/services/mtomSample");
+        EPRText.setBounds(120, 230, 280, 20);
+
+        MTOMSOAPLabel = new JLabel("Send Using");
+        MTOMSOAPLabel.setBounds(20, 270, 150, 20);
+
+        MTOMRadio = new JRadioButton("MTOM");
+        MTOMRadio.setBounds(20, 295, 100, 20);
+        MTOMRadio.setSelected(true);
+
+        SOAPRadio = new JRadioButton("SOAP with Attachments");
+        SOAPRadio.setBounds(140, 295, 200, 20);
+
+        opLabel = new JLabel("Select Operation");
+        opLabel.setBounds(20, 320, 150, 20);
+
+        sendRadio = new JRadioButton("Send");
+        sendRadio.setBounds(20, 345, 100, 20);
+        sendRadio.setSelected(true);
+
+        sendRecRadio = new JRadioButton("Send & Receive");
+        sendRecRadio.setBounds(140, 345, 150, 20);
+
+        cacheBox = new JCheckBox("Enable File Caching");
+        cacheBox.setSelected(false);
+        cacheBox.setEnabled(false);
+        cacheBox.setBounds(20, 380, 150, 20);
+
+        thresholdLabel = new JLabel("File Cache Threshold: ");
+        thresholdLabel.setBounds(50, 410, 150, 20);
+        thresholdLabel.setEnabled(false);
+        cacheThresholdText = new JTextField();
+        cacheThresholdText.setBounds(200, 410, 40, 20);
+        cacheThresholdText.setEnabled(false);
+
+        cacheFolderLabel = new JLabel("Cache Folder: ");
+        cacheFolderLabel.setBounds(50, 440, 150, 20);
+        cacheFolderLabel.setEnabled(false);
+        cacheFolderText = new JTextField();
+        cacheFolderText.setBounds(200, 440, 200, 20);
+        cacheFolderText.setEnabled(false);
+
+        this.executeButton = new JButton("Execute");
+        executeButton.setBounds(20, 490, 150, 20);
+
+        fileChooser = new JFileChooser();
+        fileChooser.setName("File Chooser");
+    }
+
+    public void handleSelection() {
+        if (!files.isEmpty()) {
+            removeButton.setEnabled(false);
+        }
+    }
+
+    public void enableCaching() {
+        cacheEnable = cacheBox.isSelected();
+        thresholdLabel.setEnabled(cacheEnable);
+        cacheThresholdText.setEnabled(cacheEnable);
+        cacheFolderLabel.setEnabled(cacheEnable);
+        cacheFolderText.setEnabled(cacheEnable);
+    }
+
+    public void switchRadios(JRadioButton me, JRadioButton partner) {
+        me.setSelected(true);
+        partner.setSelected(false);
+    }
+
+    public void actionPerformed(ActionEvent e) {
+        if (e.getSource() == browseButton) {
+            browse();
+        } else if (e.getSource() == executeButton) {
+            execute();
+        } else if (e.getSource() == addFileButton) {
+            addFile();
+        } else if (e.getSource() == removeButton) {
+            removeFromList();
+        }
+    }
+
+    public void browse() {
+        int returnVal = fileChooser.showDialog(this,
+                "Select");
+
+        if (returnVal == JFileChooser.APPROVE_OPTION) {
+            file = fileChooser.getSelectedFile();
+            if (file.getAbsolutePath() != null) {
+                fileField.setText(file.getAbsolutePath());
+                addFileButton.setEnabled(true);
+            }
+        }
+        fileChooser.setSelectedFile(null);
+    }
+
+    public void addFile() {
+        file = new File(fileField.getText());
+        if (file.exists() && file.isFile()) {
+            files.add(file);
+            model.addElement(file.getAbsolutePath());
+            fileList.setSelectedIndex(files.size() - 1);
+            removeButton.setEnabled(true);
+        } else {
+            JOptionPane.showMessageDialog(parent,
+                    "File does not exist", "File Error",
+                    JOptionPane.ERROR_MESSAGE);
+        }
+    }
+
+    public void removeFromList() {
+        String selection = (String) fileList.getSelectedValue();
+        if (selection != null) {
+            file = new File(selection);
+            files.remove(file);
+            model.remove(fileList.getSelectedIndex());
+            fileList.setSelectedIndex(files.size() - 1);
+            if (files.isEmpty()) {
+                removeButton.setEnabled(false);
+            }
+        }
+    }
+
+    public void execute() {
+        EPR = EPRText.getText();
+        String operation;
+        String sendMethod;
+        String cacheFolder = null;
+        int cacheThreshold = 0;
+        File cache;
+        destFolder = destFolderText.getText();
+
+        if (!model.isEmpty()) {
+            if (!destFolder.equals("") && !EPR.equals("")) {
+                sendMethod = (MTOMRadio.isSelected() ? "MTOM" : "SOAP");
+                operation = (sendRadio.isSelected() ? "send" : "sendreceive");
+                if (cacheEnable) {
+                    try {
+                        String temp = cacheThresholdText.getText();
+                        if (!temp.equals("")) {
+                            cacheThreshold = Integer.parseInt(temp);
+                        } else {
+                            throw new NumberFormatException();
+                        }
+
+                        cache = new File(cacheFolderText.getText());
+                        if (!cache.exists()) {
+                            cache.mkdirs();
+                        }
+                        cacheFolder = cache.getAbsolutePath();
+
+                    } catch (NumberFormatException e) {
+                        JOptionPane.showMessageDialog(parent, "Please enter an integer value",
+                                "Cache Threshold Error", JOptionPane.ERROR_MESSAGE);
+                    }
+                }
+
+                mtomTest = new MTOMClientModel();
+                mtomTest.setFileList(files);
+                mtomTest.setTargetEPR(EPR);
+
+                if (operation.equals("send")) {
+                    send(sendMethod);
+                } else {
+                    sendAndReceive(sendMethod, cacheThreshold, cacheFolder);
+                }
+                return;
+            }
+            JOptionPane.showMessageDialog(parent, "Destination Folder or End Point cannot be null",
+                    "Data Error", JOptionPane.ERROR_MESSAGE);
+        } else {
+            JOptionPane.showMessageDialog(parent, "Add at least one file",
+                    "File List Empty", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+
+    public void sendAndReceive(String sendMethod, int cacheThreshold, String cacheFolder) {
+        OMElement result;
+        try {
+            mtomTest.setCacheFolder(cacheFolder);
+            mtomTest.setCacheThreshold(cacheThreshold);
+            String temp = (cacheEnable) ? "Enabled" : "Disabled";
+            if (sendMethod.equals("MTOM")) {
+                result = mtomTest.sendReceiveUsingMTOM(destFolder, cacheEnable);
+
+                temp = "File Caching " + temp + "\n\n" + result.getText();
+                JOptionPane.showMessageDialog(parent, temp,
+                        "Result of Send & Receive using MTOM", JOptionPane.PLAIN_MESSAGE);
+            } else {
+                result = mtomTest.sendReceiveUsingSwA(destFolder, cacheEnable);
+
+                temp = "File Caching " + temp + "\n\n" + result.getText();
+                JOptionPane.showMessageDialog(parent, temp,
+                        "Result of Send & Receive using SwA", JOptionPane.PLAIN_MESSAGE);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public void send(String sendMethod) {
+        OMElement result;
+        try {
+            if (sendMethod.equals("MTOM")) {
+                result = mtomTest.sendFilesUsingMTOM(destFolder);
+                JOptionPane.showMessageDialog(parent, result.getText(),
+                        "Result of Send using MTOM", JOptionPane.PLAIN_MESSAGE);
+            } else {
+                result = mtomTest.sendFilesUsingSwA(destFolder);
+                JOptionPane.showMessageDialog(parent, result.getText(),
+                        "Result of Send using SOAP with Attachments", JOptionPane.PLAIN_MESSAGE);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
\ No newline at end of file

Propchange: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/client/UserInterface.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java?view=auto&rev=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java Thu Sep 28 01:41:26 2006
@@ -0,0 +1,203 @@
+/*
+ * 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.mtom.filetransfer.service;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.*;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+import javax.activation.DataHandler;
+import javax.imageio.IIOImage;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
+import javax.xml.namespace.QName;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.util.Iterator;
+
+public class MTOMService {
+    private OperationContext opcts;
+
+    private OMElement folder;
+    private OMElement files;
+    private OMElement file;
+    private String folderName;
+
+    public void setOperationContext(OperationContext oc) throws AxisFault {
+        opcts = oc;
+    }
+
+    /**
+     * @param element The OMElement handed by the Axis2 engine
+     * @return An OMElement containing the response of the operation
+     * @throws Exception
+     */
+    public OMElement uploadFileUsingMTOM(OMElement element) throws Exception {
+
+        Iterator itr = element.getChildElements();
+        folder = (OMElement) itr.next(); // Get the folderName element
+
+        // Throw AxisFault if destination folder is null
+        if (folder == null) throw new AxisFault("Destination Folder is null");
+
+        folderName = folder.getText();
+
+        // Create destination folder hierarchy if it does not exist
+        File destFolder = new File(folderName);
+        if (!destFolder.exists()) {
+            destFolder.mkdirs();
+        }
+
+        files = (OMElement) itr.next(); // Get the files element
+        itr = files.getChildElements(); // Get iterator for file elements
+
+
+        int i = 1;
+        String fileName;
+
+        // loop through each file element
+        while (itr.hasNext()) {
+            file = (OMElement) itr.next(); // Get next file element
+
+            // Throw AxisFault if the file element is null
+            if (file == null) throw new AxisFault("File " + i + " is null");
+
+            OMText binaryNode = (OMText) file.getFirstOMChild();
+            binaryNode.setBinary(true);
+            DataHandler dataHandler;
+            dataHandler = (DataHandler) binaryNode.getDataHandler(); // Get corresponding DataHandler
+            fileName = createFileName(i);
+            writeData(dataHandler.getDataSource().getInputStream(), fileName);
+            i++;
+        }
+
+        // Create response element
+        OMFactory fac = OMAbstractFactory.getOMFactory(); // Get OMFactory
+        OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns"); // Create a namespace
+        OMElement ele = fac.createOMElement("response", ns); // Create response element
+        ele.setText("" + (i - 1) + " File(s) Saved Successfully on Server at " + folderName);
+        return ele;
+    }
+
+
+    /**
+     * @param element The OMElement handed by the Axis2 engine
+     * @return An OMElement containing the response of the operation
+     * @throws Exception
+     */
+    public OMElement uploadFileUsingSwA(OMElement element) throws Exception {
+
+        Iterator itr = element.getChildElements();
+
+        folder = (OMElement) itr.next(); // Get the folderName element
+
+        // Throw AxisFault if destination folder is null
+        if (folder == null) throw new AxisFault("Destination Folder is null");
+
+        folderName = folder.getText();
+
+        // Create destination folder hierarchy if it does not exist
+        File destFolder = new File(folderName);
+        if (!destFolder.exists()) {
+            destFolder.mkdirs();
+        }
+
+        files = (OMElement) itr.next(); // Get the files element
+        itr = files.getChildElements(); // Get iterator for file elements
+
+        // Get attachements from the MessageContext
+        Attachments attachment = (opcts.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)).getAttachmentMap();
+
+        // loop through each file element
+        int i = 1;
+        String fileName;
+        DataHandler dataHandler;
+        while (itr.hasNext()) {
+            file = (OMElement) itr.next();
+            if (file == null) throw new AxisFault("File " + i + " is null");
+            dataHandler = attachment.getDataHandler(file.getText()); // Get corresponding DataHandler
+            fileName = createFileName(i);
+            writeData(dataHandler.getDataSource().getInputStream(), fileName);
+            i++;
+        }
+
+        // Create response element
+        OMFactory fac = OMAbstractFactory.getOMFactory(); // Get OMFactory
+        OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns"); // Create a namespace
+        OMElement ele = fac.createOMElement("response", ns); // Create response element
+        ele.setText("" + (i - 1) + " File(s) Saved Successfully on Server at " + folderName);
+        return ele;
+
+    }
+
+    public OMElement sendReceiveUsingMTOM(OMElement element) {
+        element.buildWithAttachments();
+        element.detach();
+        return element;
+    }
+
+    public OMElement sendReceiveUsingSwA(OMElement element) throws Exception {
+        Attachments attachment = (opcts.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)).getAttachmentMap();
+        opcts.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE).setAttachmentMap(attachment);
+        element.buildWithAttachments();
+        element.detach();
+        return element;
+    }
+
+
+    private String createFileName(int count) {
+        String fileName;
+        fileName = folderName + "/" + file.getAttributeValue(
+                new QName(file.getNamespace().getNamespaceURI(), "type"));
+
+        if (new File(fileName).exists()) {
+            fileName = folderName + "/copy(" + (count - 1) + ")" + file.getAttributeValue(
+                    new QName(file.getNamespace().getNamespaceURI(), "type"));
+            while (new File(fileName).exists()) {
+                count ++;
+                fileName = folderName + "/copy(" + (count - 1) + ")" + file.getAttributeValue(
+                        new QName(file.getNamespace().getNamespaceURI(), "type"));
+            }
+        }
+
+        return fileName;
+    }
+
+    /**
+     * @param inStrm   An input stream linking to the data
+     * @param fileName The absolute path of the file to which the data should be written
+     * @throws Exception
+     */
+    private void writeData(InputStream inStrm, String fileName) throws Exception {
+        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+        int b;
+        while (true) {
+            b = inStrm.read();
+            if (b == -1) {
+                break;
+            }
+            raf.writeByte(b);
+        }
+        inStrm.close();
+        raf.close();
+    }
+}
\ No newline at end of file

Propchange: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/MTOMService.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml?view=auto&rev=450759
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml Thu Sep 28 01:41:26 2006
@@ -0,0 +1,30 @@
+<service name="MTOMService">
+    <description>
+        This is a sample Web Service for illustrating MTOM based binary data transfer.
+    </description>
+    <parameter name="ServiceClass" locked="false">sample.mtom.filetransfer.service.MTOMService</parameter>
+    <operation name="uploadFileUsingMTOM">
+        <parameter name="enableMTOM" locked="false">true</parameter>
+        <parameter name="enableSwA" locked="false">false</parameter>
+        <actionMapping>urn:uploadFileUsingMTOM</actionMapping>
+        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+    </operation>
+    <operation name="uploadFileUsingSwA">
+        <parameter name="enableMTOM" locked="false">false</parameter>
+        <parameter name="enableSwA" locked="false">true</parameter>
+        <actionMapping>urn:uploadFileUsingSwA</actionMapping>
+        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+    </operation>
+    <operation name="sendReceiveUsingMTOM">
+        <parameter name="enableMTOM" locked="false">true</parameter>
+        <parameter name="enableSwA" locked="false">false</parameter>
+        <actionMapping>urn:sendReceiveUsingMTOM</actionMapping>
+        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+    </operation>
+    <operation name="sendReceiveUsingSwA">
+        <parameter name="enableMTOM" locked="false">false</parameter>
+        <parameter name="enableSwA" locked="false">true</parameter>
+        <actionMapping>urn:sendReceiveUsingSwA</actionMapping>
+        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+    </operation>
+</service>
\ No newline at end of file

Propchange: webservices/axis2/trunk/java/modules/samples/src/sample/mtom/filetransfer/service/meta-inf/services.xml
------------------------------------------------------------------------------
    svn:executable = *



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