KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > secure > SecureXmlRpcClient


1 /*
2  * Copyright 1999,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.xmlrpc.secure;
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.xmlrpc.XmlRpcClient;
25
26 /**
27  * A multithreaded, reusable XML-RPC client object. Use this if you need a full-grown
28  * HTTP client (e.g. for Proxy and Cookies support). If you don't need that, <code>XmlRpcClientLite</code>
29  * may work better for you.
30  */

31 public class SecureXmlRpcClient
32     extends XmlRpcClient
33 {
34     /**
35      * Construct a XML-RPC client with this URL.
36      */

37     public SecureXmlRpcClient (URL JavaDoc url) {
38         super(url);
39     }
40
41     /**
42      * Construct a XML-RPC client for the URL represented by this String.
43      */

44     public SecureXmlRpcClient (String JavaDoc url) throws MalformedURLException JavaDoc {
45         super(url);
46     }
47    
48     /**
49      * Construct a XML-RPC client for the specified hostname and port.
50      */

51     public SecureXmlRpcClient (String JavaDoc hostname, int port) throws MalformedURLException JavaDoc
52     {
53         super("https://" + hostname + ':' + port + "/RPC2");
54     }
55     
56     /**
57      * This allows us to setup
58      */

59      public void setup() throws Exception JavaDoc
60      {
61          SecurityTool.setup();
62      }
63
64     /**
65      * Just for testing.
66      */

67     public static void main (String JavaDoc args[]) throws Exception JavaDoc
68     {
69         // XmlRpc.setDebug (true);
70
try {
71             String JavaDoc url = args[0];
72             String JavaDoc method = args[1];
73             Vector JavaDoc v = new Vector JavaDoc ();
74             for (int i=2; i<args.length; i++) try {
75                 v.addElement (new Integer JavaDoc (Integer.parseInt (args[i])));
76             } catch (NumberFormatException JavaDoc nfx) {
77                 v.addElement (args[i]);
78             }
79             SecureXmlRpcClient client = new SecureXmlRpcClient (url);
80             try {
81                 System.err.println (client.execute (method, v));
82             } catch (Exception JavaDoc ex) {
83                 System.err.println ("Error: "+ex.getMessage());
84             }
85         } catch (Exception JavaDoc x) {
86             System.err.println (x);
87             System.err.println ("Usage: java " +
88                                 SecureXmlRpcClient.class.getName() +
89                                 " <url> <method> [args]");
90             System.err.println ("Arguments are sent as integers or strings.");
91         }
92     }
93 }
94
Popular Tags