00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00146 return message;
00147 }
00148
00152 public static Name createName(String string) throws SOAPException {
00153 init();
00154
00155 return soapFactory.createName(string);
00156 }
00157 }