1 55 56 package org.jboss.axis.client; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.deployment.wsdd.WSDDConstants; 60 import org.jboss.axis.message.SOAPBodyElementAxisImpl; 61 import org.jboss.axis.utils.Messages; 62 import org.jboss.axis.utils.Options; 63 import org.jboss.logging.Logger; 64 65 import javax.xml.rpc.ServiceException ; 66 import java.io.ByteArrayInputStream ; 67 import java.io.File ; 68 import java.io.FileInputStream ; 69 import java.io.FileNotFoundException ; 70 import java.io.InputStream ; 71 import java.net.URL ; 72 import java.util.Vector ; 73 74 75 83 84 public class AdminClient 85 { 86 private static Logger log = Logger.getLogger(AdminClient.class.getName()); 87 88 private static String getUsageInfo() 89 { 90 String lSep = System.getProperty("line.separator"); 91 StringBuffer msg = new StringBuffer (); 92 msg.append(Messages.getMessage("acUsage00")).append(lSep); 94 msg.append(Messages.getMessage("acUsage01")).append(lSep); 95 msg.append(Messages.getMessage("acUsage02")).append(lSep); 96 msg.append(Messages.getMessage("acUsage03")).append(lSep); 97 msg.append(Messages.getMessage("acUsage04")).append(lSep); 98 msg.append(Messages.getMessage("acUsage05")).append(lSep); 99 msg.append(Messages.getMessage("acUsage06")).append(lSep); 100 msg.append(Messages.getMessage("acUsage07")).append(lSep); 101 msg.append(Messages.getMessage("acUsage08")).append(lSep); 102 msg.append(Messages.getMessage("acUsage09")).append(lSep); 103 msg.append(Messages.getMessage("acUsage10")).append(lSep); 104 msg.append(Messages.getMessage("acUsage11")).append(lSep); 105 msg.append(Messages.getMessage("acUsage12")).append(lSep); 106 msg.append(Messages.getMessage("acUsage13")).append(lSep); 107 msg.append(Messages.getMessage("acUsage14")).append(lSep); 108 msg.append(Messages.getMessage("acUsage15")).append(lSep); 109 msg.append(Messages.getMessage("acUsage16")).append(lSep); 110 msg.append(Messages.getMessage("acUsage17")).append(lSep); 111 msg.append(Messages.getMessage("acUsage18")).append(lSep); 112 msg.append(Messages.getMessage("acUsage19")).append(lSep); 113 msg.append(Messages.getMessage("acUsage20")).append(lSep); 114 msg.append(Messages.getMessage("acUsage21")).append(lSep); 115 msg.append(Messages.getMessage("acUsage22")).append(lSep); 116 msg.append(Messages.getMessage("acUsage23")).append(lSep); 117 msg.append(Messages.getMessage("acUsage24")).append(lSep); 118 msg.append(Messages.getMessage("acUsage25")).append(lSep); 119 msg.append(Messages.getMessage("acUsage26")).append(lSep); 120 return msg.toString(); 121 } 122 123 124 protected Call call; 125 126 129 public AdminClient() 130 { 131 try 132 { 133 Service service = new Service(); 134 call = (Call)service.createCall(); 135 } 136 catch (ServiceException e) 137 { 138 System.err.println(Messages.getMessage("couldntCall00") + ": " + e); 139 call = null; 140 } 141 } 142 143 146 public Call getCall() 147 { 148 return call; 149 } 150 151 public String list(Options opts) throws Exception 152 { 153 processOpts(opts); 154 return list(); 155 } 156 157 public String list() throws Exception 158 { 159 log.debug(Messages.getMessage("doList00")); 160 String str = "<m:list xmlns:m=\"" + WSDDConstants.URI_WSDD + "\"/>"; 161 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 162 return process(input); 163 } 164 165 public String quit(Options opts) throws Exception 166 { 167 processOpts(opts); 168 return quit(); 169 } 170 171 protected static final String ROOT_UNDEPLOY = WSDDConstants.QNAME_UNDEPLOY.getLocalPart(); 172 173 public String quit() throws Exception 174 { 175 log.debug(Messages.getMessage("doQuit00")); 176 String str = "<m:quit xmlns:m=\"" + WSDDConstants.URI_WSDD + "\"/>"; 177 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 178 return process(input); 179 } 180 181 public String undeployHandler(String handlerName) throws Exception 182 { 183 log.debug(Messages.getMessage("doQuit00")); 184 String str = "<m:" + ROOT_UNDEPLOY + " xmlns:m=\"" + WSDDConstants.URI_WSDD + "\">" + 185 "<handler name=\"" + handlerName + "\"/>" + 186 "</m:" + ROOT_UNDEPLOY + ">"; 187 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 188 return process(input); 189 } 190 191 public String undeployService(String serviceName) throws Exception 192 { 193 log.debug(Messages.getMessage("doQuit00")); 194 String str = "<m:" + ROOT_UNDEPLOY + " xmlns:m=\"" + WSDDConstants.URI_WSDD + "\">" + 195 "<service name=\"" + serviceName + "\"/>" + 196 "</m:" + ROOT_UNDEPLOY + ">"; 197 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 198 return process(input); 199 } 200 201 232 233 public String process(String [] args) throws Exception 234 { 235 StringBuffer sb = new StringBuffer (); 236 237 Options opts = new Options(args); 238 opts.setDefaultURL("http://localhost:8080/axis/services/AdminService"); 239 240 if (opts.isFlagSet('d') > 0) 241 { 242 } 244 245 args = opts.getRemainingArgs(); 246 247 if (args == null || opts.isFlagSet('?') > 0) 248 { 249 System.out.println(Messages.getMessage("usage00", "AdminClient [Options] [list | <deployment-descriptor-files>]")); 250 System.out.println(""); 251 System.out.println(getUsageInfo()); 252 return null; 253 } 254 255 for (int i = 0; i < args.length; i++) 256 { 257 InputStream input = null; 258 259 if (args[i].equals("list")) 260 sb.append(list(opts)); 261 else if (args[i].equals("quit")) 262 sb.append(quit(opts)); 263 else if (args[i].equals("passwd")) 264 { 265 System.out.println(Messages.getMessage("changePwd00")); 266 if (args[i + 1] == null) 267 { 268 System.err.println(Messages.getMessage("needPwd00")); 269 return null; 270 } 271 String str = "<m:passwd xmlns:m=\"http://xml.apache.org/axis/wsdd/\">"; 272 str += args[i + 1]; 273 str += "</m:passwd>"; 274 input = new ByteArrayInputStream (str.getBytes()); 275 i++; 276 sb.append(process(opts, input)); 277 } 278 else 279 { 280 if (args[i].indexOf(java.io.File.pathSeparatorChar) == -1) 281 { 282 System.out.println(Messages.getMessage("processFile00", args[i])); 283 sb.append(process(opts, args[i])); 284 } 285 else 286 { 287 java.util.StringTokenizer tokenizer = null; 288 tokenizer = new java.util.StringTokenizer (args[i], 289 java.io.File.pathSeparator); 290 while (tokenizer.hasMoreTokens()) 291 { 292 String file = tokenizer.nextToken(); 293 System.out.println(Messages.getMessage("processFile00", file)); 294 sb.append(process(opts, file)); 295 if (tokenizer.hasMoreTokens()) 296 sb.append("\n"); 297 } 298 } 299 } 300 } 301 302 return sb.toString(); 303 } 304 305 public void processOpts(Options opts) throws Exception 306 { 307 if (call == null) 308 throw new Exception (Messages.getMessage("nullCall00")); 309 310 call.setTargetEndpointAddress(new URL (opts.getURL())); 311 call.setUsername(opts.getUser()); 312 call.setPassword(opts.getPassword()); 313 314 String tName = opts.isValueSet('t'); 315 if (tName != null && !tName.equals("")) 316 call.setProperty(Call.TRANSPORT_NAME, tName); 317 } 318 319 public String process(InputStream input) throws Exception 320 { 321 return process(null, input); 322 } 323 324 public String process(URL xmlURL) throws Exception 325 { 326 return process(null, xmlURL.openStream()); 327 } 328 329 public String process(String xmlFile) throws Exception 330 { 331 332 InputStream in = null; 333 if (new File (xmlFile).exists()) 334 in = new FileInputStream (xmlFile); 335 else 336 in = getClass().getClassLoader().getResourceAsStream(xmlFile); 337 338 if (in == null) 339 throw new FileNotFoundException (xmlFile); 340 341 String result = process(null, in); 342 in.close(); 343 return result; 344 } 345 346 public String process(Options opts, String xmlFile) throws Exception 347 { 348 processOpts(opts); 349 return process(xmlFile); 350 } 351 352 public String process(Options opts, InputStream input) throws Exception 353 { 354 if (call == null) 355 throw new Exception (Messages.getMessage("nullCall00")); 356 357 if (opts != null) processOpts(opts); 358 359 call.setUseSOAPAction(true); 360 call.setSOAPActionURI("AdminService"); 361 362 Vector result = null; 363 Object [] params = new Object []{new SOAPBodyElementAxisImpl(input)}; 364 result = (Vector )call.invoke(params); 365 366 input.close(); 367 368 if (result == null || result.isEmpty()) 369 throw new AxisFault(Messages.getMessage("nullResponse00")); 370 371 SOAPBodyElementAxisImpl body = (SOAPBodyElementAxisImpl)result.elementAt(0); 372 return body.toString(); 373 } 374 375 382 public static void main(String [] args) 383 { 384 try 385 { 386 AdminClient admin = new AdminClient(); 387 388 String result = admin.process(args); 389 if (result != null) 390 { 391 System.out.println(result); 392 } 393 else 394 { 395 System.exit(1); 396 } 397 } 398 catch (Exception e) 399 { 400 log.error(Messages.getMessage("exception00"), e); 401 System.exit(1); 402 } 403 } 404 } 405 406 | Popular Tags |