1 /****************************************************************
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * @author: Copyright (C) Tim Carver
19 ***************************************************************/
21 package ext.jemboss.soap;
26 import ext.jemboss.JembossParams;
27 import javax.swing.JOptionPane;
29 import org.apache.axis.client.Call;
30 import org.apache.axis.client.Service;
31 import javax.xml.namespace.QName;
32 import org.apache.axis.encoding.XMLType;
36 * Make a axis call to a private server, using the default service
39 public class PrivateRequest
42 /** results from calling the web service */
43 private Hashtable proganswer;
47 * @param mysettings jemboss properties
48 * @param method method to call
49 * @param args arguments
50 * @throws JembossSoapException if authentication fails
53 public PrivateRequest(JembossParams mysettings, String method, Vector args)
54 throws JembossSoapException
56 this(mysettings, mysettings.getPrivateSoapService(), method, args);
61 * @param mysettings jemboss properties
62 * @param service service to call
63 * @param method method to call
64 * @throws JembossSoapException If authentication fails
67 public PrivateRequest(JembossParams mysettings, String service, String method)
68 throws JembossSoapException
70 this(mysettings, service, method, (Vector) null);
75 * @param mysettings jemboss properties
76 * @param service service to call
77 * @param method method to call
78 * @param args arguments
79 * @throws JembossSoapException if authentication fails
81 public PrivateRequest(JembossParams mysettings, String service, String method,
82 Vector args) throws JembossSoapException
86 String endpoint = mysettings.getPublicSoapURL()+"/"+service;
87 org.apache.axis.client.Service serv =
88 new org.apache.axis.client.Service();
89 Call call = (Call) serv.createCall();
90 QName qn = new QName(service, method);
91 call.setTargetEndpointAddress( new java.net.URL(endpoint) );
92 call.setOperationName(new QName(service, method));
93 call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);
96 Object params[] = null;
99 if(mysettings.getUseAuth())
100 nargs = args.size()+2;
102 nargs = args.size()+1;
104 params = new Object[nargs];
105 Enumeration e = args.elements();
106 for(int i=0;i<args.size();i++)
108 Object obj = e.nextElement();
110 if(obj.getClass().equals(String.class))
112 call.addParameter("Args"+i, XMLType.XSD_STRING,
113 javax.xml.rpc.ParameterMode.IN);
115 else if(obj.getClass().equals(Hashtable.class))
117 params[i] = getVector((Hashtable)obj);
119 call.addParameter("Args"+i, XMLType.SOAP_VECTOR,
120 javax.xml.rpc.ParameterMode.IN);
124 call.addParameter("ByteArray", XMLType.XSD_BASE64,
125 javax.xml.rpc.ParameterMode.IN);
132 if(mysettings.getUseAuth() == true)
137 params = new Object[nargs];
139 call.addParameter("Door", XMLType.XSD_STRING,
140 javax.xml.rpc.ParameterMode.IN);
141 params[nargs-2] = mysettings.getServiceUserName();
143 call.addParameter("Key", XMLType.XSD_BASE64,
144 javax.xml.rpc.ParameterMode.IN);
145 params[nargs-1] = mysettings.getServicePasswdByte();
147 else //No authorization reqd, so use user name here
148 { //to create own sand box on server
152 params = new Object[nargs];
157 call.addParameter("Door", XMLType.XSD_STRING,
158 javax.xml.rpc.ParameterMode.IN);
159 params[nargs-1] = System.getProperty("user.name");
162 call.setReturnType(org.apache.axis.Constants.SOAP_VECTOR);
163 Vector vans = (Vector)call.invoke( params );
165 proganswer = new Hashtable();
166 // assumes it's even sized
168 for(int j=0;j<n;j+=2)
170 String s = (String)vans.get(j);
173 String msg = (String)vans.get(j+1);
174 if(msg.startsWith("Failed Authorisation"))
175 throw new JembossSoapException("Authentication Failed");
176 else if(msg.startsWith("Error"))
177 throw new JembossSoapException(msg);
179 proganswer.put(s,vans.get(j+1));
184 System.out.println("Exception in PrivateRequest "+
188 throw new JembossSoapException(" Fault Code = " + e);
195 * Change the contents of a hashtable to a vector
196 * @return contents of the hash
199 private Vector getVector(Hashtable h)
201 Vector v = new Vector();
202 for(Enumeration e = h.keys() ; e.hasMoreElements() ;)
204 String s = (String)e.nextElement();
215 * Gets an element out of the embreo result hash
216 * @param val key to look up
217 * @return the element, or an empty String if there is no
218 * element that matches the key
221 public Object getVal(String val)
223 if (proganswer.containsKey(val))
224 return proganswer.get(val);
231 * Get the results returned by the server call
235 public Hashtable getHash()