Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.atlassian.xmlrpc;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.net.URL;
Used to bind the given XML-RPC service to an instance of the given interface type This implementation uses the Apache XML-RPC client

Author(s):
James William Dumay
 
 public class ApacheBinder implements Binder
 {
     public <T> T bind(Class<T> bindClassURL urlthrows BindingException
     {
         return bind(bindClassurlnew ConnectionInfo());
     }
 
     public <T> T bind(Class<T> bindClassURL urlConnectionInfo connectionInfothrows BindingException
     {
         if (!bindClass.isInterface())
         {
             throw new BindingException("Class " + bindClass.getName() + "is not an interface");
         }
         ServiceObject serviceObject = bindClass.getAnnotation(ServiceObject.class);
         if (serviceObject == null)
         {
             throw new BindingException("Could not find ServiceObject annotation on " + bindClass.getName());
         }
         final XmlRpcClient client = getXmlRpcClient(urlconnectionInfo);
         
         {
             public Object execute(String serviceNameString methodNameVector argumentsthrows BindingException
             {
                 try
                 {
                     return client.execute(serviceName + "." + methodNamearguments);
                 }
                 catch (XmlRpcException e)
                 {
                     throw new BindingException(e);
                 }
             }
         });
 
         return (T)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { bindClass }, handler);
     }
 
     private XmlRpcClient getXmlRpcClient(URL urlConnectionInfo connectionInfo)
     {
         XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
         clientConfig.setServerURL(url);
         clientConfig.setEnabledForExceptions(true);
         
         if (connectionInfo != null)
         {
             clientConfig.setBasicUserName(connectionInfo.getUsername());
             clientConfig.setBasicPassword(connectionInfo.getPassword());
             clientConfig.setBasicEncoding(connectionInfo.getEncoding());
             clientConfig.setGzipCompressing(connectionInfo.isGzip());
             clientConfig.setGzipRequesting(connectionInfo.isGzip());
             clientConfig.setReplyTimeout(connectionInfo.getTimeout());
             clientConfig.setConnectionTimeout(connectionInfo.getTimeout());
             clientConfig.setTimeZone(connectionInfo.getTimeZone());
         }
         
         XmlRpcClient client = new XmlRpcClient();
         client.setTypeFactory(new BinderTypeFactory(client));
         client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
         client.setConfig(clientConfig);
         return client;
     }
New to GrepCode? Check out our FAQ X