KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > util > webservices > XMLRPCHelper


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.deliver.util.webservices;
25
26 import java.util.Vector JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.apache.xmlrpc.XmlRpc;
30 import org.apache.xmlrpc.XmlRpcClient;
31
32
33 /**
34  * @author Mattias Bogeblad
35  *
36  * This class helps using the popular XML-RPC way of accessing data.
37  */

38
39 public class XMLRPCHelper
40 {
41     private final static Logger logger = Logger.getLogger(XMLRPCHelper.class.getName());
42
43     private String JavaDoc serviceUrl = "";
44     private String JavaDoc method = "";
45     private Vector JavaDoc parameters = new Vector JavaDoc();
46     private Object JavaDoc result = null;
47
48     private String JavaDoc errorCode = "0";
49     private String JavaDoc errorMessage = "Ok";
50
51     /**
52      * The constructor for this class.
53      */

54     
55     public XMLRPCHelper()
56     {
57     }
58     
59     public void makeCall()
60     {
61         try
62         {
63             XmlRpcClient xmlrpc = new XmlRpcClient(serviceUrl);
64             XmlRpc.setEncoding("ISO-8859-1");
65             //Vector params = new Vector ();
66
//params.addElement("7");
67
//params.addElement("peew9yoop");
68
//params.addElement("1");
69

70             // this method returns a string
71
this.result = xmlrpc.execute(this.method, this.parameters);
72             
73             logger.info("result:" + result);
74         }
75         catch(Exception JavaDoc e)
76         {
77             this.errorCode = "1";
78             this.errorMessage = "An error occurred:" + e.getMessage();
79             logger.warn("An error occurred:" + e.getMessage(), e);
80         }
81     }
82     
83     public void setParameters(Vector JavaDoc parameters)
84     {
85         this.parameters = parameters;
86     }
87     
88     public Vector JavaDoc getParameters()
89     {
90         return this.parameters;
91     }
92     
93     public String JavaDoc getServiceUrl()
94     {
95         return serviceUrl;
96     }
97
98     public void setServiceUrl(String JavaDoc serviceUrl)
99     {
100         this.serviceUrl = serviceUrl;
101     }
102
103     public Object JavaDoc getResult()
104     {
105         return this.result;
106     }
107
108     public String JavaDoc getErrorCode()
109     {
110         return this.errorCode;
111     }
112
113     public String JavaDoc getErrorMessage()
114     {
115         return this.errorMessage;
116     }
117
118     public void setErrorCode(String JavaDoc errorCode)
119     {
120         this.errorCode = errorCode;
121     }
122
123     public void setErrorMessage(String JavaDoc errorMessage)
124     {
125         this.errorMessage = errorMessage;
126     }
127
128     public String JavaDoc getMethod()
129     {
130         return this.method;
131     }
132
133     public void setMethod(String JavaDoc method)
134     {
135         this.method = method;
136     }
137
138 }
Popular Tags