Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 3948 invoked from network); 15 Jun 2004 16:06:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 15 Jun 2004 16:06:42 -0000 Received: (qmail 17069 invoked by uid 500); 15 Jun 2004 16:03:41 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 16991 invoked by uid 500); 15 Jun 2004 16:03:41 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 16963 invoked by uid 99); 15 Jun 2004 16:03:40 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 15 Jun 2004 09:03:40 -0700 Received: (qmail 1417 invoked by uid 1365); 15 Jun 2004 16:03:26 -0000 Date: 15 Jun 2004 16:03:26 -0000 Message-ID: <20040615160326.1416.qmail@minotaur.apache.org> From: stevel@apache.org To: ws-axis-cvs@apache.org Subject: cvs commit: ws-axis/java/src/org/apache/axis/client AdminClient.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N stevel 2004/06/15 09:03:26 Modified: java/src/org/apache/axis/client AdminClient.java Log: Some more accessor methods that bind to the call object, and a new constructor that throws an exception if the call instance could not be created. This constructor takes a boolean which it ignores. This was the least backwards-incompatible solution, ugly that it is. Revision Changes Path 1.84 +158 -36 ws-axis/java/src/org/apache/axis/client/AdminClient.java Index: AdminClient.java =================================================================== RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/client/AdminClient.java,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- AdminClient.java 8 Apr 2004 13:09:05 -0000 1.83 +++ AdminClient.java 15 Jun 2004 16:03:26 -0000 1.84 @@ -98,35 +98,62 @@ } + /** + * the object that represents our call + */ protected Call call; /** * Construct an admin client w/o a logger. + * If the client cannot create a call object, then it does not throw an exception. + * Instead it prints a message to {@link System.err}. + * This is for 'historical reasons' */ public AdminClient() { try { - // Initialize our Service - allow the user to override the - // default configuration with a thread-local version (see - // setDefaultConfiguration() above) - EngineConfiguration config = - (EngineConfiguration)defaultConfiguration.get(); - Service service; - if (config != null) { - service = new Service(config); - } else { - service = new Service(); - } - call = (Call) service.createCall(); + initAdminClient(); } catch (ServiceException e) { System.err.println(Messages.getMessage("couldntCall00") + ": " + e); call = null; } } + /** - * External access to our CallCallCall object this instance uses */ public Call getCall() @@ -134,11 +161,22 @@ return call; } + /** + * process the options then run a list call + * @param opts + * @return + * @throws Exception + */ public String list(Options opts) throws Exception { processOpts( opts ); return list(); } + /** + * send a list command + * @return the response from the call + * @throws Exception + */ public String list() throws Exception { log.debug( Messages.getMessage("doList00") ); String str = "" ; @@ -146,13 +184,27 @@ return process(input); } + /** + * process the command line ops, then send a quit command + * @param opts + * @return + * @throws Exception + */ public String quit(Options opts) throws Exception { processOpts( opts ); return quit(); } + /** + * root element of the undeploy request + */ protected static final String ROOT_UNDEPLOY= WSDDConstants.QNAME_UNDEPLOY.getLocalPart(); + /** + * make a quit command + * @return + * @throws Exception + */ public String quit() throws Exception { log.debug(Messages.getMessage("doQuit00")); String str = ""; @@ -160,6 +212,12 @@ return process(input); } + /** + * undeploy a handler + * @param handlerName name of the handler to undeploy + * @return + * @throws Exception + */ public String undeployHandler(String handlerName) throws Exception { log.debug(Messages.getMessage("doQuit00")); String str = "" + @@ -169,6 +227,12 @@ return process(input); } + /** + * undeploy a service + * @param serviceName name of service + * @return + * @throws Exception + */ public String undeployService(String serviceName) throws Exception { log.debug(Messages.getMessage("doQuit00")); String str = "" + @@ -271,17 +335,53 @@ return sb.toString(); } + /** + * go from the (parsed) command line to setting properties on our call object. + * @param opts + * @throws Exception if call==null + */ public void processOpts(Options opts) throws Exception { - if (call == null) + if (call == null) { throw new Exception(Messages.getMessage("nullCall00")); + } - call.setTargetEndpointAddress( new URL(opts.getURL()) ); - call.setUsername( opts.getUser() ); - call.setPassword( opts.getPassword() ); + URL address = new URL(opts.getURL()); + setTargetEndpointAddress(address); + setLogin(opts.getUser(), opts.getPassword()); String tName = opts.isValueSet( 't' ); - if ( tName != null && !tName.equals("") ) - call.setProperty( Call.TRANSPORT_NAME, tName ); + setTransport(tName); + } + + /** + * set the username and password + * requires that call!=null + * @param user username + * @param password password + */ + public void setLogin(String user, String password) { + call.setUsername( user ); + call.setPassword( password ); + } + + /** + * set the URL to deploy to + * requires that call!=null + * @param address + */ + public void setTargetEndpointAddress(URL address) { + call.setTargetEndpointAddress( address ); + } + + /** + * set the transport to deploy with. + * requires that call!=null + * @param transportName a null or empty value does not trigger a setting + */ + public void setTransport(String transportName) { + if(transportName != null && !transportName.equals("")) { + call.setProperty( Call.TRANSPORT_NAME, transportName ); + } } public String process(InputStream input) throws Exception { @@ -292,10 +392,15 @@ return process(null, xmlURL.openStream() ); } + /** + * process an XML file containing a pre-prepared admin message + * @param xmlFile file to load + * @return + * @throws Exception + */ public String process(String xmlFile) throws Exception { - FileInputStream in = new FileInputStream(xmlFile); - String result = process(null, in ); - in.close(); + FileInputStream in = new FileInputStream(xmlFile); + String result = process(null, in ); return result ; } @@ -304,26 +409,43 @@ return process( xmlFile ); } + /** + * submit the input stream's contents to the endpoint, return the results as a string. + * The input stream is always closed after the call, whether the request worked or not + * @param opts options -can be null + * @param input -input stream for request + * @return + * @throws Exception if the call was null + * @throws AxisFault if the invocation returned an empty response + */ public String process(Options opts, InputStream input) throws Exception { - if (call == null) - throw new Exception(Messages.getMessage("nullCall00")); - - if ( opts != null ) processOpts( opts ); + try { + if (call == null) { + //validate that the call is not null + throw new Exception(Messages.getMessage("nullCall00")); + } - call.setUseSOAPAction( true); - call.setSOAPActionURI( "AdminService"); + if ( opts != null ) { + //process options if supplied + processOpts( opts ); + } - Vector result = null ; - Object[] params = new Object[] { new SOAPBodyElement(input) }; - result = (Vector) call.invoke( params ); + call.setUseSOAPAction( true); + call.setSOAPActionURI( "AdminService"); - input.close(); + Vector result = null ; + Object[] params = new Object[] { new SOAPBodyElement(input) }; + result = (Vector) call.invoke( params ); - if (result == null || result.isEmpty()) - throw new AxisFault(Messages.getMessage("nullResponse00")); + if (result == null || result.isEmpty()) { + throw new AxisFault(Messages.getMessage("nullResponse00")); + } - SOAPBodyElement body = (SOAPBodyElement) result.elementAt(0); - return body.toString(); + SOAPBodyElement body = (SOAPBodyElement) result.elementAt(0); + return body.toString(); + } finally { + input.close(); + } } /**