]> source.dussan.org Git - archiva.git/commitdiff
updated sample client to use the atlassian-xmlrpc-binder instead of apache xmlrpc...
authorMaria Odea B. Ching <oching@apache.org>
Tue, 4 Nov 2008 22:09:47 +0000 (22:09 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Tue, 4 Nov 2008 22:09:47 +0000 (22:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@711444 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/pom.xml
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/src/main/java/org/apache/archiva/web/xmlrpc/client/SampleClient.java
pom.xml

index 8410e2267d7e2905c5ed332a8d7e272cc0f90c18..6b8a17070e3a44a8f6ae2f1c66bb3f82eaa21108 100644 (file)
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.xmlrpc</groupId>
-      <artifactId>xmlrpc-client</artifactId>
-      <version>3.1</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-beanutils</groupId>
-      <artifactId>commons-beanutils</artifactId>
-      <version>1.8.0</version>
+      <groupId>com.atlassian.xmlrpc</groupId>
+      <artifactId>atlassian-xmlrpc-binder</artifactId>
+      <version>0.8.2</version>
     </dependency>
   </dependencies>
   <build>
                  USERNAME & PASSWORD: Archiva credentials  
             --> 
             <argument>http://127.0.0.1:8080/archiva/xmlrpc</argument>
-            <argument>admin</argument>
-            <argument>admin1</argument>
+            <argument>username</argument>
+            <argument>password</argument>
           </arguments>
         </configuration>
       </plugin>
-      <!-- override parent config, commons-logging cannot be excluded from commons-beanutils - NoClassDef error occurs -->
+      <!-- override parent config, commons-logging cannot be excluded from atlassian-xml-rpc-binder - NoClassDef error occurs -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
index 7f94734a1cd73b50731d616f1d1ab9bbce2713de..c87e35fad2587e1b64d67e0c7e8169d286f06c8e 100644 (file)
@@ -19,23 +19,17 @@ package org.apache.archiva.web.xmlrpc.client;
  * under the License.
  */
 
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
-import org.apache.xmlrpc.client.util.ClientFactory;
+
+import com.atlassian.xmlrpc.AuthenticationInfo;
+import com.atlassian.xmlrpc.Binder;
+import com.atlassian.xmlrpc.BindingException;
+import com.atlassian.xmlrpc.DefaultBinder;
 
 /**
  * TestClient
@@ -56,138 +50,82 @@ public class SampleClient
 {   
     public static void main( String[] args ) 
     {       
+        Binder binder = new DefaultBinder();
+        
         try
         {
-            XmlRpcClient client = new XmlRpcClient();
-            
-            XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
-            config.setServerURL( new URL( args[0] ) );
-            config.setBasicUserName( args[1] );
-            config.setBasicPassword( args[2] );
-            config.setEnabledForExtensions( true );
-            
-            client.setConfig( config );
-            
-            /* managed repositories */
-            Object[] params = new Object[]{};
-            Object[] managedRepos = (Object[])
-                 client.execute( "AdministrationService.getAllManagedRepositories", params );                        
+            AuthenticationInfo authnInfo = new AuthenticationInfo( args[1], args[2] );
+            AdministrationService adminService = binder.bind( AdministrationService.class, new URL( args[0] ), authnInfo );
+            List<ManagedRepository> managedRepos = adminService.getAllManagedRepositories();
             
             System.out.println( "\n******** Managed Repositories ********" );
-            for( int i = 0; i < managedRepos.length; i++ )
+            for( ManagedRepository managedRepo : managedRepos )
             {
                 System.out.println( "=================================" );
-                ManagedRepository managedRepo = new ManagedRepository(); 
-                try
-                {   
-                    BeanUtils.populate( managedRepo, (Map)managedRepos[i] );
-                }
-                catch ( IllegalAccessException e )
-                {
-                    e.printStackTrace();
-                }
-                catch ( InvocationTargetException e )
-                {
-                    e.printStackTrace();
-                }
                 System.out.println( "Id: " + managedRepo.getId() );
                 System.out.println( "Name: " + managedRepo.getName() );
                 System.out.println( "Layout: " + managedRepo.getLayout() );
                 System.out.println( "URL: " + managedRepo.getUrl() );
                 System.out.println( "Releases: " + managedRepo.isReleases() );
                 System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
-            }
-                        
-            /* remote repositories */
-            params = new Object[]{};
-            Object[] remoteRepos = (Object[])
-                 client.execute( "AdministrationService.getAllRemoteRepositories", params );
+            }                
             
             System.out.println( "\n******** Remote Repositories ********" );
-            for( int i = 0; i < remoteRepos.length; i++ )
+            List<RemoteRepository> remoteRepos = adminService.getAllRemoteRepositories();
+            for( RemoteRepository remoteRepo : remoteRepos )
             {
                 System.out.println( "=================================" );
-                RemoteRepository remoteRepo = new RemoteRepository();
-                
-                try
-                {   
-                    BeanUtils.populate( remoteRepo, (Map) remoteRepos[i] );
-                }
-                catch ( IllegalAccessException e )
-                {
-                    e.printStackTrace();
-                }
-                catch ( InvocationTargetException e )
-                {
-                    e.printStackTrace();
-                }
                 System.out.println( "Id: " + remoteRepo.getId() );
                 System.out.println( "Name: " + remoteRepo.getName() );
                 System.out.println( "Layout: " + remoteRepo.getLayout() );
-                System.out.println( "URL: " + remoteRepo.getUrl() );                    
+                System.out.println( "URL: " + remoteRepo.getUrl() );
             }
             
-            /* repo consumers */
-            params = new Object[]{};
-            Object[] repoConsumers = (Object[])
-                 client.execute( "AdministrationService.getAllRepositoryConsumers", params );
-            
             System.out.println( "\n******** Repository Consumers ********" );
-            for( int i = 0; i < repoConsumers.length; i++ )
-            {   
-                System.out.println( repoConsumers[i] );                    
+            List<String> repoConsumers = adminService.getAllRepositoryConsumers();
+            for( String consumer : repoConsumers )
+            {
+                System.out.println( consumer );
             }
             
-            /* db consumers */
-            params = new Object[]{};
-            Object[] dbConsumers = (Object[])
-                 client.execute( "AdministrationService.getAllDatabaseConsumers", params );
-            
             System.out.println( "\n******** Database Consumers ********" );
-            for( int i = 0; i < dbConsumers.length; i++ )
-            {   
-                System.out.println( dbConsumers[i] );                    
+            List<String> dbConsumers = adminService.getAllDatabaseConsumers();
+            for( String consumer : dbConsumers )
+            {
+                System.out.println( consumer );
             }
             
-            /* configure repo consumer */
-            Object[] configureRepoConsumerParams = new Object[] { "internal", "repository-purge", true };            
-            Object configured = client.execute( "AdministrationService.configureRepositoryConsumer", configureRepoConsumerParams );            
-            System.out.println( "\nConfigured repo consumer 'repository-purge' : " + ( ( Boolean ) configured ).booleanValue() );
-            
-            
-            /* configure db consumer */
-            Object[] configureDbConsumerParams = new Object[] { "update-db-bytecode-stats", false };            
-            configured = client.execute( "AdministrationService.configureDatabaseConsumer", configureDbConsumerParams );            
-            System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " + ( ( Boolean ) configured ).booleanValue() );            
-            
+            Boolean success = adminService.configureRepositoryConsumer( "internal", "repository-purge", true );
+            System.out.println( "\nConfigured repo consumer 'repository-purge' : " +
+                ( (Boolean) success ).booleanValue() );
             
-            /* execute repo scanner */
-            Object[] executeRepoScanParams = new Object[] { "internal" };            
-            configured = client.execute( "AdministrationService.executeRepositoryScanner", executeRepoScanParams );            
-            System.out.println( "\nExecuted repo scanner of repository 'internal' : " + ( ( Boolean ) configured ).booleanValue() );
+            success = adminService.configureDatabaseConsumer( "update-db-bytecode-stats", false );
+            System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " +
+                ( (Boolean) success ).booleanValue() );
             
+            success = adminService.executeRepositoryScanner( "internal" );
+            System.out.println( "\nExecuted repo scanner of repository 'internal' : " +
+                ( (Boolean) success ).booleanValue() );
             
-            /* execute db scanner */
-            Object[] executeDbScanParams = new Object[] {};            
-            configured = client.execute( "AdministrationService.executeDatabaseScanner", executeDbScanParams );
-            System.out.println( "\nExecuted database scanner : " + ( ( Boolean ) configured ).booleanValue() );
-            
+            success = adminService.executeDatabaseScanner();
+            System.out.println( "\nExecuted database scanner : " + ( (Boolean) success ).booleanValue() );
+           
             /* delete artifact */
             /* 
-             * NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!            
-            Object[] deleteArtifactParams = new Object[] { "internal", "javax.activation", "activation", "1.1" };
-            Object artifactDeleted = client.execute( "AdministrationService.deleteArtifact", deleteArtifactParams );
+             * NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!
+             *                      
+            success = adminService.deleteArtifact( "internal", "javax.activation", "activation", "1.1" );
             System.out.println( "\nDeleted artifact 'javax.activation:activation:1.1' from repository 'internal' : " +
-                ( (Boolean) artifactDeleted ).booleanValue() );    
-            */ 
+                ( (Boolean) success ).booleanValue() );
+            */
         }
-        catch ( MalformedURLException e )
+        catch ( BindingException e )
         {
-            e.printStackTrace();
+            e.printStackTrace();             
         }
-        catch ( XmlRpcException e )
+        catchException e )
         {
             e.printStackTrace();
-        }           
+        }
     }
 }
diff --git a/pom.xml b/pom.xml
index ae9839f88d428bdfbb6b9f4d572be6373ab4d3b0..acb701671242dd783bec5936fe927240bb4aba6a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <groupId>com.atlassian.xmlrpc</groupId>
         <artifactId>atlassian-xmlrpc-binder</artifactId>
         <version>${binder.version}</version>
-        <scope>test</scope>
       </dependency>
       <dependency>
         <groupId>com.atlassian.xmlrpc</groupId>