1 package org.exoplatform.services.wsrp; 2 3 import org.apache.axis.AxisFault; 4 import org.apache.axis.EngineConfiguration; 5 import org.apache.axis.client.Call; 6 import org.apache.axis.client.Service; 7 import org.apache.axis.components.logger.LogFactory; 8 import org.apache.axis.deployment.wsdd.WSDDConstants; 9 import org.apache.axis.message.SOAPBodyElement; 10 import org.apache.axis.utils.Messages; 11 import org.apache.axis.utils.Options; 12 import org.apache.commons.logging.Log; 13 14 import javax.xml.rpc.ServiceException ; 15 import java.io.ByteArrayInputStream ; 16 import java.io.File ; 17 import java.io.FileInputStream ; 18 import java.io.InputStream ; 19 import java.net.URL ; 20 import java.util.StringTokenizer ; 21 import java.util.Vector ; 22 23 26 public class AdminClient 27 { 28 29 public static void setDefaultConfiguration(EngineConfiguration config) 30 { 31 defaultConfiguration.set(config); 32 } 33 34 private static String getUsageInfo() 35 { 36 String lSep = System.getProperty("line.separator"); 37 StringBuffer msg = new StringBuffer (); 38 msg.append(Messages.getMessage("acUsage00")).append(lSep); 39 msg.append(Messages.getMessage("acUsage01")).append(lSep); 40 msg.append(Messages.getMessage("acUsage02")).append(lSep); 41 msg.append(Messages.getMessage("acUsage03")).append(lSep); 42 msg.append(Messages.getMessage("acUsage04")).append(lSep); 43 msg.append(Messages.getMessage("acUsage05")).append(lSep); 44 msg.append(Messages.getMessage("acUsage06")).append(lSep); 45 msg.append(Messages.getMessage("acUsage07")).append(lSep); 46 msg.append(Messages.getMessage("acUsage08")).append(lSep); 47 msg.append(Messages.getMessage("acUsage09")).append(lSep); 48 msg.append(Messages.getMessage("acUsage10")).append(lSep); 49 msg.append(Messages.getMessage("acUsage11")).append(lSep); 50 msg.append(Messages.getMessage("acUsage12")).append(lSep); 51 msg.append(Messages.getMessage("acUsage13")).append(lSep); 52 msg.append(Messages.getMessage("acUsage14")).append(lSep); 53 msg.append(Messages.getMessage("acUsage15")).append(lSep); 54 msg.append(Messages.getMessage("acUsage16")).append(lSep); 55 msg.append(Messages.getMessage("acUsage17")).append(lSep); 56 msg.append(Messages.getMessage("acUsage18")).append(lSep); 57 msg.append(Messages.getMessage("acUsage19")).append(lSep); 58 msg.append(Messages.getMessage("acUsage20")).append(lSep); 59 msg.append(Messages.getMessage("acUsage21")).append(lSep); 60 msg.append(Messages.getMessage("acUsage22")).append(lSep); 61 msg.append(Messages.getMessage("acUsage23")).append(lSep); 62 msg.append(Messages.getMessage("acUsage24")).append(lSep); 63 msg.append(Messages.getMessage("acUsage25")).append(lSep); 64 msg.append(Messages.getMessage("acUsage26")).append(lSep); 65 return msg.toString(); 66 } 67 68 public AdminClient() 69 { 70 try 71 { 72 EngineConfiguration config = (EngineConfiguration)defaultConfiguration.get(); 73 Service service; 74 if(config != null) 75 service = new Service(config); 76 else 77 service = new Service(); 78 call = (Call)service.createCall(); 79 } 80 catch(ServiceException e) 81 { 82 System.err.println(Messages.getMessage("couldntCall00") + ": " + e); 83 call = null; 84 } 85 } 86 87 public Call getCall() 88 { 89 return call; 90 } 91 92 public String list(Options opts) 93 throws Exception 94 { 95 processOpts(opts); 96 return list(); 97 } 98 99 public String list() throws Exception { 100 log.debug(Messages.getMessage("doList00")); 101 String str = "<m:list xmlns:m=\"http://xml.apache.org/axis/wsdd/\"/>"; 102 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 103 return process(input); 104 } 105 106 public String quit(Options opts) throws Exception { 107 processOpts(opts); 108 return quit(); 109 } 110 111 public String quit() throws Exception { 112 log.debug(Messages.getMessage("doQuit00")); 113 String str = "<m:quit xmlns:m=\"http://xml.apache.org/axis/wsdd/\"/>"; 114 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 115 return process(input); 116 } 117 118 public String undeployHandler(String handlerName) throws Exception 119 { 120 log.debug(Messages.getMessage("doQuit00")); 121 String str = "<m:" + ROOT_UNDEPLOY + " xmlns:m=\"" + "http://xml.apache.org/axis/wsdd/" + "\">" + "<handler name=\"" + handlerName + "\"/>" + "</m:" + ROOT_UNDEPLOY + ">"; 122 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 123 return process(input); 124 } 125 126 public String undeployService(String serviceName) throws Exception 127 { 128 log.debug(Messages.getMessage("doQuit00")); 129 String str = "<m:" + ROOT_UNDEPLOY + " xmlns:m=\"" + "http://xml.apache.org/axis/wsdd/" + "\">" + "<service name=\"" + serviceName + "\"/>" + "</m:" + ROOT_UNDEPLOY + ">"; 130 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 131 return process(input); 132 } 133 134 public String process(String args[]) 135 throws Exception 136 { 137 StringBuffer sb = new StringBuffer (); 138 Options opts = new Options(args); 139 opts.setDefaultURL("http://localhost:8080/axis/services/AdminService"); 140 if(opts.isFlagSet('d') <= 0); 141 args = opts.getRemainingArgs(); 142 if(args == null || opts.isFlagSet('?') > 0) 143 { 144 System.out.println(Messages.getMessage("usage00", "AdminClient [Options] [list | <deployment-descriptor-files>]")); 145 System.out.println(""); 146 System.out.println(getUsageInfo()); 147 return null; 148 } 149 for(int i = 0; i < args.length; i++) 150 { 151 InputStream input = null; 152 if(args[i].equals("list")) 153 sb.append(list(opts)); 154 else 155 if(args[i].equals("quit")) 156 sb.append(quit(opts)); 157 else 158 if(args[i].equals("passwd")) 159 { 160 System.out.println(Messages.getMessage("changePwd00")); 161 if(args[i + 1] == null) 162 { 163 System.err.println(Messages.getMessage("needPwd00")); 164 return null; 165 } 166 String str = "<m:passwd xmlns:m=\"http://xml.apache.org/axis/wsdd/\">"; 167 str = str + args[i + 1]; 168 str = str + "</m:passwd>"; 169 input = new ByteArrayInputStream (str.getBytes()); 170 i++; 171 sb.append(process(opts, input)); 172 } else 173 if(args[i].indexOf(File.pathSeparatorChar) == -1) 174 { 175 System.out.println(Messages.getMessage("processFile00", args[i])); 176 sb.append(process(opts, args[i])); 177 } else 178 { 179 StringTokenizer tokenizer = null; 180 for(tokenizer = new StringTokenizer (args[i], File.pathSeparator); tokenizer.hasMoreTokens();) 181 { 182 String file = tokenizer.nextToken(); 183 System.out.println(Messages.getMessage("processFile00", file)); 184 sb.append(process(opts, file)); 185 if(tokenizer.hasMoreTokens()) 186 sb.append("\n"); 187 } 188 189 } 190 } 191 192 return sb.toString(); 193 } 194 195 public void processOpts(Options opts) 196 throws Exception 197 { 198 if(call == null) 199 throw new Exception (Messages.getMessage("nullCall00")); 200 call.setTargetEndpointAddress(new URL (opts.getURL())); 201 call.setUsername(opts.getUser()); 202 call.setPassword(opts.getPassword()); 203 String tName = opts.isValueSet('t'); 204 if(tName != null && !tName.equals("")) 205 call.setProperty("transport_name", tName); 206 } 207 208 public String process(InputStream input) 209 throws Exception 210 { 211 return process(null, input); 212 } 213 214 public String process(URL xmlURL) 215 throws Exception 216 { 217 return process(null, xmlURL.openStream()); 218 } 219 220 public String process(String xmlFile) 221 throws Exception 222 { 223 FileInputStream in = new FileInputStream (xmlFile); 224 String result = process(null, ((InputStream ) (in))); 225 in.close(); 226 return result; 227 } 228 229 public String process(Options opts, String xmlFile) 230 throws Exception 231 { 232 processOpts(opts); 233 return process(xmlFile); 234 } 235 236 public String process(Options opts, InputStream input) throws Exception { 237 if(call == null) 238 throw new Exception (Messages.getMessage("nullCall00")); 239 if(opts != null) 240 processOpts(opts); 241 call.setUseSOAPAction(true); 242 call.setSOAPActionURI("AdminService"); 243 Vector result = null; 244 Object params[] = { 245 new SOAPBodyElement(input) 246 }; 247 result = (Vector )call.invoke(params); 248 input.close(); 249 if(result == null || result.isEmpty()) 250 { 251 throw new AxisFault(Messages.getMessage("nullResponse00")); 252 } else 253 { 254 SOAPBodyElement body = (SOAPBodyElement)result.elementAt(0); 255 return body.toString(); 256 } 257 } 258 259 public static void main(String args[]) { 260 try { 261 AdminClient admin = new AdminClient(); 262 String result = admin.process(args); 263 if(result != null) 264 System.out.println(result); 265 else 266 System.exit(1); 267 } catch(Exception e) { 268 e.printStackTrace() ; 269 System.err.println(Messages.getMessage("exception00") + ": " + e); 270 System.exit(1); 271 } 272 } 273 274 static Class _mthclass$(String x0) throws Exception { 275 return Class.forName(x0); 276 } 277 278 protected static Log log; 279 private static ThreadLocal defaultConfiguration = new ThreadLocal (); 280 protected Call call; 281 protected static final String ROOT_UNDEPLOY; 282 283 static { 284 log = LogFactory.getLog((org.apache.axis.client.AdminClient.class).getName()); 285 ROOT_UNDEPLOY = WSDDConstants.QNAME_UNDEPLOY.getLocalPart(); 286 } 287 } 288 | Popular Tags |