Coverage Report - org.apache.xmlrpc.client.XmlRpcClient
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlRpcClient
34% 
N/A 
1
 
 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  
 package org.apache.xmlrpc.client;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.xmlrpc.XmlRpcConfig;
 21  
 import org.apache.xmlrpc.XmlRpcException;
 22  
 import org.apache.xmlrpc.XmlRpcRequest;
 23  
 import org.apache.xmlrpc.client.XmlRpcTransportFactory;
 24  
 import org.apache.xmlrpc.common.XmlRpcController;
 25  
 import org.apache.xmlrpc.common.XmlRpcWorkerFactory;
 26  
 import org.apache.xmlrpc.serializer.DefaultXMLWriterFactory;
 27  
 import org.apache.xmlrpc.serializer.XmlWriterFactory;
 28  
 
 29  
 
 30  
 /** <p>The main access point of an XML-RPC client. This object serves mainly
 31  
  * as an object factory. It is designed with singletons in mind: Basically,
 32  
  * an application should be able to hold a single instance of
 33  
  * <code>XmlRpcClient</code> in a static variable, unless you would be
 34  
  * working with different factories.</p>
 35  
  * <p>Until Apache XML-RPC 2.0, this object was used both as an object
 36  
  * factory and as a place, where configuration details (server URL,
 37  
  * suggested encoding, user credentials and the like) have been stored.
 38  
  * In Apache XML-RPC 3.0, the configuration details has been moved to
 39  
  * the {@link org.apache.xmlrpc.client.XmlRpcClientConfig} object.
 40  
  * The configuration object is designed for being passed through the
 41  
  * actual worker methods.</p>
 42  
  * <p>A configured XmlRpcClient object is thread safe: In other words,
 43  
  * the suggested use is, that you configure the client using
 44  
  * {@link #setTransportFactory(XmlRpcTransportFactory)} and similar
 45  
  * methods, store it in a field and never modify it again. Without
 46  
  * modifications, the client may be used for an arbitrary number
 47  
  * of concurrent requests.</p>
 48  
  * @since 3.0
 49  
  */
 50  404
 public class XmlRpcClient extends XmlRpcController {
 51  202
         private XmlRpcTransportFactory transportFactory = new XmlRpcSunHttpTransportFactory(this);
 52  202
         private XmlRpcClientConfig config = new XmlRpcClientConfigImpl();
 53  202
         private XmlWriterFactory xmlWriterFactory = new DefaultXMLWriterFactory();
 54  
 
 55  
         protected XmlRpcWorkerFactory getDefaultXmlRpcWorkerFactory() {
 56  202
                 return new XmlRpcClientWorkerFactory(this);
 57  
         }
 58  
 
 59  
         /** Sets the clients default configuration. This configuration
 60  
          * is used by the methods
 61  
          * {@link #execute(String, List)},
 62  
          * {@link #execute(String, Object[])}, and
 63  
          * {@link #execute(XmlRpcRequest)}.
 64  
          * You may overwrite this per request by using
 65  
          * {@link #execute(XmlRpcClientConfig, String, List)},
 66  
          * or {@link #execute(XmlRpcClientConfig, String, Object[])}.
 67  
          * @param pConfig The default request configuration.
 68  
          */
 69  
         public void setConfig(XmlRpcClientConfig pConfig) {
 70  0
                 config = pConfig;
 71  0
         }
 72  
 
 73  
         /** Returns the clients default configuration. This configuration
 74  
          * is used by the methods
 75  
          * {@link #execute(String, List)},
 76  
          * {@link #execute(String, Object[])}.
 77  
          * You may overwrite this per request by using
 78  
          * {@link #execute(XmlRpcClientConfig, String, List)},
 79  
          * or {@link #execute(XmlRpcClientConfig, String, Object[])}.
 80  
          * @return The default request configuration.
 81  
          */
 82  
         public XmlRpcConfig getConfig() {
 83  0
                 return config;
 84  
         }
 85  
 
 86  
         /** Returns the clients default configuration. Shortcut for
 87  
          * <code>(XmlRpcClientConfig) getConfig()</code>.
 88  
          * This configuration is used by the methods
 89  
          * {@link #execute(String, List)},
 90  
          * {@link #execute(String, Object[])}.
 91  
          * You may overwrite this per request by using
 92  
          * {@link #execute(XmlRpcClientConfig, String, List)}, or
 93  
          * {@link #execute(XmlRpcClientConfig, String, Object[])}
 94  
          * @return The default request configuration.
 95  
          */
 96  
         public XmlRpcClientConfig getClientConfig() {
 97  0
                 return config;
 98  
         }
 99  
 
 100  
         /** Sets the clients transport factory. The client will invoke the
 101  
          * factory method {@link XmlRpcTransportFactory#getTransport()}
 102  
          * for any request.
 103  
          * @param pFactory The clients transport factory.
 104  
          */
 105  
         public void setTransportFactory(XmlRpcTransportFactory pFactory) {
 106  202
                 transportFactory = pFactory;
 107  202
         }
 108  
         
 109  
         /** Returns the clients transport factory. The client will use this factory
 110  
          * for invocation of {@link XmlRpcTransportFactory#getTransport()}
 111  
          * for any request.
 112  
          * @return The clients transport factory.
 113  
          */
 114  
         public XmlRpcTransportFactory getTransportFactory() {
 115  432
                 return transportFactory;
 116  
         }
 117  
 
 118  
         /** Performs a request with the clients default configuration.
 119  
          * @param pMethodName The method being performed.
 120  
          * @param pParams The parameters.
 121  
          * @return The result object.
 122  
          * @throws XmlRpcException Performing the request failed.
 123  
          */
 124  
         public Object execute(String pMethodName, Object[] pParams) throws XmlRpcException {
 125  0
                 return execute(getClientConfig(), pMethodName, pParams);
 126  
         }
 127  
 
 128  
         /** Performs a request with the given configuration.
 129  
          * @param pConfig The request configuration.
 130  
          * @param pMethodName The method being performed.
 131  
          * @param pParams The parameters.
 132  
          * @return The result object.
 133  
          * @throws XmlRpcException Performing the request failed.
 134  
          */
 135  
         public Object execute(XmlRpcClientConfig pConfig, String pMethodName, Object[] pParams) throws XmlRpcException {
 136  432
                 return execute(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams));
 137  
         }
 138  
 
 139  
         /** Performs a request with the clients default configuration.
 140  
          * @param pMethodName The method being performed.
 141  
          * @param pParams The parameters.
 142  
          * @return The result object.
 143  
          * @throws XmlRpcException Performing the request failed.
 144  
          */
 145  
         public Object execute(String pMethodName, List pParams) throws XmlRpcException {
 146  0
                 return execute(getClientConfig(), pMethodName, pParams);
 147  
         }
 148  
 
 149  
         /** Performs a request with the given configuration.
 150  
          * @param pConfig The request configuration.
 151  
          * @param pMethodName The method being performed.
 152  
          * @param pParams The parameters.
 153  
          * @return The result object.
 154  
          * @throws XmlRpcException Performing the request failed.
 155  
          */
 156  
         public Object execute(XmlRpcClientConfig pConfig, String pMethodName, List pParams) throws XmlRpcException {
 157  0
                 return execute(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams));
 158  
         }
 159  
 
 160  
         /** Performs a request with the clients default configuration.
 161  
          * @param pRequest The request being performed.
 162  
          * @return The result object.
 163  
          * @throws XmlRpcException Performing the request failed.
 164  
          */
 165  
         public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
 166  432
                 return getWorkerFactory().getWorker().execute(pRequest);
 167  
         }
 168  
 
 169  
         /** Performs an asynchronous request with the clients default configuration.
 170  
          * @param pMethodName The method being performed.
 171  
          * @param pParams The parameters.
 172  
          * @param pCallback The callback being notified when the request is finished.
 173  
          * @throws XmlRpcException Performing the request failed.
 174  
          */
 175  
         public void executeAsync(String pMethodName, Object[] pParams,
 176  
                                                          AsyncCallback pCallback) throws XmlRpcException {
 177  0
                 executeAsync(getClientConfig(), pMethodName, pParams, pCallback);
 178  0
         }
 179  
 
 180  
         /** Performs an asynchronous request with the given configuration.
 181  
          * @param pConfig The request configuration.
 182  
          * @param pMethodName The method being performed.
 183  
          * @param pParams The parameters.
 184  
          * @param pCallback The callback being notified when the request is finished.
 185  
          * @throws XmlRpcException Performing the request failed.
 186  
          */
 187  
         public void executeAsync(XmlRpcClientConfig pConfig,
 188  
                                                          String pMethodName, Object[] pParams,
 189  
                                                          AsyncCallback pCallback) throws XmlRpcException {
 190  0
                 executeAsync(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams),
 191  0
                                          pCallback);
 192  0
         }
 193  
 
 194  
         /** Performs an asynchronous request with the clients default configuration.
 195  
          * @param pMethodName The method being performed.
 196  
          * @param pParams The parameters.
 197  
          * @param pCallback The callback being notified when the request is finished.
 198  
          * @throws XmlRpcException Performing the request failed.
 199  
          */
 200  
         public void executeAsync(String pMethodName, List pParams,
 201  
                                                             AsyncCallback pCallback) throws XmlRpcException {
 202  0
                 executeAsync(getClientConfig(), pMethodName, pParams, pCallback);
 203  0
         }
 204  
 
 205  
         /** Performs an asynchronous request with the given configuration.
 206  
          * @param pConfig The request configuration.
 207  
          * @param pMethodName The method being performed.
 208  
          * @param pParams The parameters.
 209  
          * @param pCallback The callback being notified when the request is finished.
 210  
          * @throws XmlRpcException Performing the request failed.
 211  
          */
 212  
         public void executeAsync(XmlRpcClientConfig pConfig,
 213  
                                                          String pMethodName, List pParams,
 214  
                                                           AsyncCallback pCallback) throws XmlRpcException {
 215  0
                 executeAsync(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams), pCallback);
 216  0
         }
 217  
 
 218  
         /** Performs a request with the clients default configuration.
 219  
          * @param pRequest The request being performed.
 220  
          * @param pCallback The callback being notified when the request is finished.
 221  
          * @throws XmlRpcException Performing the request failed.
 222  
          */
 223  
         public void executeAsync(XmlRpcRequest pRequest,
 224  
                                                          AsyncCallback pCallback) throws XmlRpcException {
 225  0
                 XmlRpcClientWorker w = (XmlRpcClientWorker) getWorkerFactory().getWorker();
 226  0
                 w.execute(pRequest, pCallback);
 227  0
         }
 228  
 
 229  
         /** Returns the clients instance of
 230  
          * {@link org.apache.xmlrpc.serializer.XmlWriterFactory}.
 231  
          * @return A factory for creating instances of
 232  
          * {@link org.apache.ws.commons.serialize.XMLWriter}.
 233  
          */
 234  
         public XmlWriterFactory getXmlWriterFactory() {
 235  384
                 return xmlWriterFactory;
 236  
         }
 237  
 
 238  
         /** Sets the clients instance of
 239  
          * {@link org.apache.xmlrpc.serializer.XmlWriterFactory}.
 240  
          * @param pFactory A factory for creating instances of
 241  
          * {@link org.apache.ws.commons.serialize.XMLWriter}.
 242  
          */
 243  
         public void setXmlWriterFactory(XmlWriterFactory pFactory) {
 244  0
                 xmlWriterFactory = pFactory;
 245  0
         }
 246  
 }