1 16 17 package org.apache.axis.client ; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.EngineConfiguration; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.axis.deployment.wsdd.WSDDConstants; 23 import org.apache.axis.message.SOAPBodyElement; 24 import org.apache.axis.utils.Messages; 25 import org.apache.axis.utils.Options; 26 import org.apache.axis.utils.StringUtils; 27 import org.apache.commons.logging.Log; 28 29 import javax.xml.rpc.ServiceException ; 30 import java.io.ByteArrayInputStream ; 31 import java.io.FileInputStream ; 32 import java.io.InputStream ; 33 import java.net.URL ; 34 import java.util.Vector ; 35 36 37 45 46 public class AdminClient 47 { 48 protected static Log log = 49 LogFactory.getLog(AdminClient.class.getName()); 50 51 private static ThreadLocal defaultConfiguration = new ThreadLocal (); 52 53 61 public static void setDefaultConfiguration(EngineConfiguration config) 62 { 63 defaultConfiguration.set(config); 64 } 65 66 private static String getUsageInfo() 67 { 68 String lSep = System.getProperty("line.separator"); 69 StringBuffer msg = new StringBuffer (); 70 msg.append(Messages.getMessage("acUsage00")).append(lSep); 72 msg.append(Messages.getMessage("acUsage01")).append(lSep); 73 msg.append(Messages.getMessage("acUsage02")).append(lSep); 74 msg.append(Messages.getMessage("acUsage03")).append(lSep); 75 msg.append(Messages.getMessage("acUsage04")).append(lSep); 76 msg.append(Messages.getMessage("acUsage05")).append(lSep); 77 msg.append(Messages.getMessage("acUsage06")).append(lSep); 78 msg.append(Messages.getMessage("acUsage07")).append(lSep); 79 msg.append(Messages.getMessage("acUsage08")).append(lSep); 80 msg.append(Messages.getMessage("acUsage09")).append(lSep); 81 msg.append(Messages.getMessage("acUsage10")).append(lSep); 82 msg.append(Messages.getMessage("acUsage11")).append(lSep); 83 msg.append(Messages.getMessage("acUsage12")).append(lSep); 84 msg.append(Messages.getMessage("acUsage13")).append(lSep); 85 msg.append(Messages.getMessage("acUsage14")).append(lSep); 86 msg.append(Messages.getMessage("acUsage15")).append(lSep); 87 msg.append(Messages.getMessage("acUsage16")).append(lSep); 88 msg.append(Messages.getMessage("acUsage17")).append(lSep); 89 msg.append(Messages.getMessage("acUsage18")).append(lSep); 90 msg.append(Messages.getMessage("acUsage19")).append(lSep); 91 msg.append(Messages.getMessage("acUsage20")).append(lSep); 92 msg.append(Messages.getMessage("acUsage21")).append(lSep); 93 msg.append(Messages.getMessage("acUsage22")).append(lSep); 94 msg.append(Messages.getMessage("acUsage23")).append(lSep); 95 msg.append(Messages.getMessage("acUsage24")).append(lSep); 96 msg.append(Messages.getMessage("acUsage25")).append(lSep); 97 msg.append(Messages.getMessage("acUsage26")).append(lSep); 98 return msg.toString(); 99 } 100 101 102 105 protected Call call; 106 107 113 public AdminClient() 114 { 115 try { 116 initAdminClient(); 117 } catch (ServiceException e) { 118 System.err.println(Messages.getMessage("couldntCall00") + ": " + e); 119 call = null; 120 } 121 } 122 123 124 129 public AdminClient(boolean ignored) throws ServiceException { 130 initAdminClient(); 131 } 132 133 138 private void initAdminClient() throws ServiceException { 139 EngineConfiguration config = 143 (EngineConfiguration) defaultConfiguration.get(); 144 Service service; 145 if (config != null) { 146 service = new Service(config); 147 } else { 148 service = new Service(); 149 } 150 call = (Call) service.createCall(); 151 } 152 153 154 160 public Call getCall() 161 { 162 return call; 163 } 164 165 171 public String list(Options opts) throws Exception { 172 processOpts( opts ); 173 return list(); 174 } 175 176 181 public String list() throws Exception { 182 log.debug( Messages.getMessage("doList00") ); 183 String str = "<m:list xmlns:m=\"" + WSDDConstants.URI_WSDD + "\"/>" ; 184 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 185 return process(input); 186 } 187 188 194 public String quit(Options opts) throws Exception { 195 processOpts( opts ); 196 return quit(); 197 } 198 199 202 protected static final String ROOT_UNDEPLOY= WSDDConstants.QNAME_UNDEPLOY.getLocalPart(); 203 204 209 public String quit() throws Exception { 210 log.debug(Messages.getMessage("doQuit00")); 211 String str = "<m:quit xmlns:m=\"" + WSDDConstants.URI_WSDD + "\"/>"; 212 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 213 return process(input); 214 } 215 216 222 public String undeployHandler(String handlerName) throws Exception { 223 log.debug(Messages.getMessage("doQuit00")); 224 String str = "<m:"+ROOT_UNDEPLOY +" xmlns:m=\"" + WSDDConstants.URI_WSDD + "\">" + 225 "<handler name=\"" + handlerName + "\"/>"+ 226 "</m:"+ROOT_UNDEPLOY +">" ; 227 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 228 return process(input); 229 } 230 231 237 public String undeployService(String serviceName) throws Exception { 238 log.debug(Messages.getMessage("doQuit00")); 239 String str = "<m:"+ROOT_UNDEPLOY +" xmlns:m=\"" + WSDDConstants.URI_WSDD + "\">" + 240 "<service name=\"" + serviceName + "\"/>"+ 241 "</m:"+ROOT_UNDEPLOY +">" ; 242 ByteArrayInputStream input = new ByteArrayInputStream (str.getBytes()); 243 return process(input); 244 } 245 246 277 278 public String process(String [] args) throws Exception { 279 StringBuffer sb = new StringBuffer (); 280 281 Options opts = new Options( args ); 282 opts.setDefaultURL("http://localhost:8080/axis/services/AdminService"); 283 284 if (opts.isFlagSet('d') > 0) { 285 } 287 288 args = opts.getRemainingArgs(); 289 290 if ( args == null || opts.isFlagSet('?') > 0) { 291 System.out.println(Messages.getMessage("usage00","AdminClient [Options] [list | <deployment-descriptor-files>]")); 292 System.out.println(""); 293 System.out.println(getUsageInfo()); 294 return null; 295 } 296 297 for ( int i = 0 ; i < args.length ; i++ ) { 298 InputStream input = null; 299 300 if ( args[i].equals("list") ) 301 sb.append( list(opts) ); 302 else if (args[i].equals("quit")) 303 sb.append( quit(opts) ); 304 else if (args[i].equals("passwd")) { 305 System.out.println(Messages.getMessage("changePwd00")); 306 if (args[i + 1] == null) { 307 System.err.println(Messages.getMessage("needPwd00")); 308 return null; 309 } 310 String str = "<m:passwd xmlns:m=\"http://xml.apache.org/axis/wsdd/\">"; 311 str += args[i + 1]; 312 str += "</m:passwd>"; 313 input = new ByteArrayInputStream (str.getBytes()); 314 i++; 315 sb.append( process(opts, input) ); 316 } 317 else { 318 if(args[i].indexOf(java.io.File.pathSeparatorChar)==-1){ 319 System.out.println( Messages.getMessage("processFile00", args[i]) ); 320 sb.append( process(opts, args[i] ) ); 321 } else { 322 java.util.StringTokenizer tokenizer = null ; 323 tokenizer = new java.util.StringTokenizer (args[i], 324 java.io.File.pathSeparator); 325 while(tokenizer.hasMoreTokens()) { 326 String file = tokenizer.nextToken(); 327 System.out.println( Messages.getMessage("processFile00", file) ); 328 sb.append( process(opts, file) ); 329 if(tokenizer.hasMoreTokens()) 330 sb.append("\n"); 331 } 332 } 333 } 334 } 335 336 return sb.toString(); 337 } 338 339 344 public void processOpts(Options opts) throws Exception { 345 if (call == null) { 346 throw new Exception (Messages.getMessage("nullCall00")); 347 } 348 349 URL address = new URL (opts.getURL()); 350 setTargetEndpointAddress(address); 351 setLogin(opts.getUser(), opts.getPassword()); 352 353 String tName = opts.isValueSet( 't' ); 354 setTransport(tName); 355 } 356 357 363 public void setLogin(String user, String password) { 364 call.setUsername( user ); 365 call.setPassword( password ); 366 } 367 368 373 public void setTargetEndpointAddress(URL address) { 374 call.setTargetEndpointAddress( address ); 375 } 376 377 382 public void setTransport(String transportName) { 383 if(transportName != null && !transportName.equals("")) { 384 call.setProperty( Call.TRANSPORT_NAME, transportName ); 385 } 386 } 387 388 public String process(InputStream input) throws Exception { 389 return process(null, input ); 390 } 391 392 public String process(URL xmlURL) throws Exception { 393 return process(null, xmlURL.openStream() ); 394 } 395 396 402 public String process(String xmlFile) throws Exception { 403 FileInputStream in = new FileInputStream (xmlFile); 404 String result = process(null, in ); 405 return result ; 406 } 407 408 public String process(Options opts, String xmlFile) throws Exception { 409 processOpts( opts ); 410 return process( xmlFile ); 411 } 412 413 422 public String process(Options opts, InputStream input) throws Exception { 423 try { 424 if (call == null) { 425 throw new Exception (Messages.getMessage("nullCall00")); 427 } 428 429 if ( opts != null ) { 430 processOpts( opts ); 432 } 433 434 call.setUseSOAPAction( true); 435 call.setSOAPActionURI( "urn:AdminService"); 436 437 Vector result = null ; 438 Object [] params = new Object [] { new SOAPBodyElement(input) }; 439 result = (Vector ) call.invoke( params ); 440 441 if (result == null || result.isEmpty()) { 442 throw new AxisFault(Messages.getMessage("nullResponse00")); 443 } 444 445 SOAPBodyElement body = (SOAPBodyElement) result.elementAt(0); 446 return body.toString(); 447 } finally { 448 input.close(); 449 } 450 } 451 452 458 public static void main (String [] args) 459 { 460 try { 461 AdminClient admin = new AdminClient(); 462 463 String result = admin.process(args); 464 if (result != null) { 465 System.out.println( StringUtils.unescapeNumericChar(result) ); 466 } else { 467 System.exit(1); 468 } 469 } catch (AxisFault ae) { 470 System.err.println(Messages.getMessage("exception00") + " " + ae.dumpToString()); 471 System.exit(1); 472 } catch (Exception e) { 473 System.err.println(Messages.getMessage("exception00") + " " + e.getMessage()); 474 System.exit(1); 475 } 476 } 477 } 478 479 | Popular Tags |