Coverage Report - org.apache.archiva.web.xmlrpc.client.SampleClient
 
Classes in this File Line Coverage Branch Coverage Complexity
SampleClient
0%
0/46
0%
0/8
0
 
 1  
 package org.apache.archiva.web.xmlrpc.client;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.net.URL;
 23  
 import java.util.List;
 24  
 
 25  
 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
 26  
 import org.apache.archiva.web.xmlrpc.api.PingService;
 27  
 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
 28  
 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
 29  
 
 30  
 import com.atlassian.xmlrpc.AuthenticationInfo;
 31  
 import com.atlassian.xmlrpc.Binder;
 32  
 import com.atlassian.xmlrpc.BindingException;
 33  
 import com.atlassian.xmlrpc.DefaultBinder;
 34  
 
 35  
 /**
 36  
  * TestClient
 37  
  * 
 38  
  * Test client for Archiva Web Services. 
 39  
  * To execute:
 40  
  * 
 41  
  * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
 42  
  *    - url
 43  
  *    - username
 44  
  *    - password
 45  
  * 2. execute 'mvn exec:java' from the command-line
 46  
  * 
 47  
  * @version $Id$
 48  
  */
 49  0
 public class SampleClient
 50  
 {   
 51  
     public static void main( String[] args ) 
 52  
     {       
 53  0
         Binder binder = new DefaultBinder();
 54  
         
 55  
         try
 56  
         {
 57  0
             AuthenticationInfo authnInfo = new AuthenticationInfo( args[1], args[2] );
 58  0
             AdministrationService adminService = binder.bind( AdministrationService.class, new URL( args[0] ), authnInfo );
 59  0
             PingService pingService = binder.bind( PingService.class, new URL( args[0] ), authnInfo );
 60  
                        
 61  0
             System.out.println( "Ping : " + pingService.ping() );
 62  
             
 63  0
             List<ManagedRepository> managedRepos = adminService.getAllManagedRepositories();
 64  
             
 65  0
             System.out.println( "\n******** Managed Repositories ********" );
 66  0
             for( ManagedRepository managedRepo : managedRepos )
 67  
             {
 68  0
                 System.out.println( "=================================" );
 69  0
                 System.out.println( "Id: " + managedRepo.getId() );
 70  0
                 System.out.println( "Name: " + managedRepo.getName() );
 71  0
                 System.out.println( "Layout: " + managedRepo.getLayout() );
 72  0
                 System.out.println( "URL: " + managedRepo.getUrl() );
 73  0
                 System.out.println( "Releases: " + managedRepo.isReleases() );
 74  0
                 System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
 75  
             }                
 76  
             
 77  0
             System.out.println( "\n******** Remote Repositories ********" );
 78  0
             List<RemoteRepository> remoteRepos = adminService.getAllRemoteRepositories();
 79  0
             for( RemoteRepository remoteRepo : remoteRepos )
 80  
             {
 81  0
                 System.out.println( "=================================" );
 82  0
                 System.out.println( "Id: " + remoteRepo.getId() );
 83  0
                 System.out.println( "Name: " + remoteRepo.getName() );
 84  0
                 System.out.println( "Layout: " + remoteRepo.getLayout() );
 85  0
                 System.out.println( "URL: " + remoteRepo.getUrl() );
 86  
             }
 87  
             
 88  0
             System.out.println( "\n******** Repository Consumers ********" );
 89  0
             List<String> repoConsumers = adminService.getAllRepositoryConsumers();
 90  0
             for( String consumer : repoConsumers )
 91  
             {
 92  0
                 System.out.println( consumer );
 93  
             }
 94  
             
 95  0
             System.out.println( "\n******** Database Consumers ********" );
 96  0
             List<String> dbConsumers = adminService.getAllDatabaseConsumers();
 97  0
             for( String consumer : dbConsumers )
 98  
             {
 99  0
                 System.out.println( consumer );
 100  
             }
 101  
             
 102  0
             Boolean success = adminService.configureRepositoryConsumer( "internal", "repository-purge", true );
 103  0
             System.out.println( "\nConfigured repo consumer 'repository-purge' : " +
 104  
                 ( (Boolean) success ).booleanValue() );
 105  
             
 106  0
             success = adminService.configureDatabaseConsumer( "update-db-bytecode-stats", false );
 107  0
             System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " +
 108  
                 ( (Boolean) success ).booleanValue() );
 109  
             
 110  0
             success = adminService.executeRepositoryScanner( "internal" );
 111  0
             System.out.println( "\nExecuted repo scanner of repository 'internal' : " +
 112  
                 ( (Boolean) success ).booleanValue() );
 113  
             
 114  0
             success = adminService.executeDatabaseScanner();
 115  0
             System.out.println( "\nExecuted database scanner : " + ( (Boolean) success ).booleanValue() );
 116  
            
 117  
             /* delete artifact */
 118  
             /* 
 119  
              * NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!
 120  
              *                      
 121  
             success = adminService.deleteArtifact( "internal", "javax.activation", "activation", "1.1" );
 122  
             System.out.println( "\nDeleted artifact 'javax.activation:activation:1.1' from repository 'internal' : " +
 123  
                 ( (Boolean) success ).booleanValue() );
 124  
             */
 125  
             
 126  
             /* quick search */            
 127  
             /*
 128  
              * NOTE: before enabling & invoking search service, make sure that the artifacts you're searching
 129  
              *      for has been indexed already in order to get results
 130  
              *        
 131  
             SearchService searchService = binder.bind( SearchService.class, new URL( args[0] ), authnInfo );
 132  
             List<Artifact> artifacts = searchService.quickSearch( "org" );
 133  
             
 134  
             System.out.println( "\n************ Search Results for 'org' *************" );
 135  
             for( Artifact artifact : artifacts )
 136  
             {
 137  
                 System.out.println( "Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() +
 138  
                                     ":" + artifact.getVersion() );
 139  
             }            
 140  
              */
 141  
             
 142  
         }
 143  0
         catch ( BindingException e )
 144  
         {
 145  0
             e.printStackTrace();             
 146  
         }
 147  0
         catch( Exception e )
 148  
         {
 149  0
             e.printStackTrace();
 150  0
         }
 151  0
     }
 152  
 }