org/objectweb/proactive/ext/webservices/utils/ProActiveWSUtils.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.ext.webservices.utils;
00032 
00033 import java.io.File;
00034 import java.net.MalformedURLException;
00035 import java.net.URL;
00036 
00037 import javax.activation.DataHandler;
00038 import javax.xml.messaging.URLEndpoint;
00039 import javax.xml.soap.AttachmentPart;
00040 import javax.xml.soap.MessageFactory;
00041 import javax.xml.soap.Name;
00042 import javax.xml.soap.SOAPConnection;
00043 import javax.xml.soap.SOAPConnectionFactory;
00044 import javax.xml.soap.SOAPException;
00045 import javax.xml.soap.SOAPFactory;
00046 import javax.xml.soap.SOAPMessage;
00047 
00048 
00053 public class ProActiveWSUtils {
00054     private static MessageFactory messageFactory;
00055     private static SOAPConnection connection;
00056     private static SOAPConnectionFactory soapConnFactory;
00057     private static SOAPFactory soapFactory;
00058     public static final String PA_WEBSERVICE = "ProActiveWebService";
00059     public static final String NAME = "name";
00060     public static final String UNDEPLOY = "undeploy";
00061     public static final String ACTION = "Action";
00062     public static final String ACTION_NAME = "actionName";
00063     public static final String WSDL = "wsdl";
00064     public static final String DEPLOY = "deploy";
00065     public static final String URN = "urn";
00066     public static final String OAID = "ObjectID";
00067     public static final String VN_NAME = "VirtualNodeName";
00068     public static final String RT_URL = "RuntimeUrl";
00069     private static boolean init = false;
00070 
00075     private static void init() {
00076         if (!init) {
00077             try {
00078                 soapFactory = SOAPFactory.newInstance();
00079                 soapConnFactory = SOAPConnectionFactory.newInstance();
00080                 connection = soapConnFactory.createConnection();
00081                 messageFactory = MessageFactory.newInstance();
00082             } catch (SOAPException e) {
00083                 e.printStackTrace();
00084             }
00085         }
00086     }
00087 
00093     public static SOAPMessage sendMessage(String url, SOAPMessage message) {
00094         init();
00095 
00096         SOAPMessage reponse = null;
00097 
00098         try {
00099             URLEndpoint destination = new URLEndpoint(url);
00100 
00101             reponse = connection.call(message, destination);
00102             connection.close();
00103         } catch (SOAPException e) {
00104             return null;
00105         }
00106 
00107         return reponse;
00108     }
00109 
00115     public static SOAPMessage attachFile(SOAPMessage message, File file,
00116         String contentId) {
00117         init();
00118 
00119         String pathUrl = "file://" + file.getAbsoluteFile();
00120 
00121         try {
00122             URL url = new URL(pathUrl);
00123             DataHandler handler = new DataHandler(url);
00124 
00125             AttachmentPart attachment = message.createAttachmentPart(handler);
00126             attachment.setContentId(contentId);
00127             message.addAttachmentPart(attachment);
00128         } catch (MalformedURLException e) {
00129             e.printStackTrace();
00130 
00131             return null;
00132         }
00133 
00134         return message;
00135     }
00136 
00140     public static SOAPMessage createMessage() throws SOAPException {
00141         init();
00142 
00143         SOAPMessage message = messageFactory.createMessage();
00144 
00145         //message. 
00146         return message;
00147     }
00148 
00152     public static Name createName(String string) throws SOAPException {
00153         init();
00154 
00155         return soapFactory.createName(string);
00156     }
00157 }

Generated on Mon Jan 22 15:16:11 2007 for ProActive by  doxygen 1.5.1