KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > XmlRpcClientLite


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;
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 /**
25  * A multithreaded, reusable XML-RPC client object. This version uses a homegrown
26  * HTTP client which can be quite a bit faster than java.net.URLConnection, especially
27  * when used with XmlRpc.setKeepAlive(true).
28  *
29  * @author <a HREF="mailto:hannes@apache.org">Hannes Wallnoefer</a>
30  * @author <a HREF="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
31  * @version $Id: XmlRpcClientLite.java,v 1.13 2005/04/22 10:25:57 hgomez Exp $
32  */

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

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

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

54     public XmlRpcClientLite (String JavaDoc hostname, int port)
55             throws MalformedURLException JavaDoc
56     {
57         super (hostname, port);
58     }
59
60     protected XmlRpcTransport createTransport()
61     {
62         return new LiteXmlRpcTransport(url);
63     }
64
65     /**
66      * Just for testing.
67      */

68     public static void main(String JavaDoc args[]) throws Exception JavaDoc
69     {
70         // XmlRpc.setDebug (true);
71
try
72         {
73             String JavaDoc url = args[0];
74             String JavaDoc method = args[1];
75             XmlRpcClientLite client = new XmlRpcClientLite (url);
76             Vector JavaDoc v = new Vector JavaDoc ();
77             for (int i = 2; i < args.length; i++)
78             {
79                 try
80                 {
81                     v.addElement(new Integer JavaDoc(Integer.parseInt(args[i])));
82                 }
83                 catch (NumberFormatException JavaDoc nfx)
84                 {
85                     v.addElement(args[i]);
86                 }
87             }
88             // XmlRpc.setEncoding ("UTF-8");
89
try
90             {
91                 System.out.println(client.execute(method, v));
92             }
93             catch (Exception JavaDoc ex)
94             {
95                 System.err.println("Error: " + ex.getMessage());
96             }
97         }
98         catch (Exception JavaDoc x)
99         {
100             System.err.println(x);
101             System.err.println("Usage: java org.apache.xmlrpc.XmlRpcClient "
102                     + "<url> <method> <arg> ....");
103             System.err.println("Arguments are sent as integers or strings.");
104         }
105     }
106 }
107
Popular Tags