]> source.dussan.org Git - archiva.git/blob
34557aea02d8b27511eaa918d73b6046ef0aed73
[archiva.git] /
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.MalformedURLException;
23 import java.net.URL;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
30 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
31 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
32 import org.apache.xmlrpc.XmlRpcException;
33 import org.apache.xmlrpc.client.XmlRpcClient;
34 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
35 import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
36 import org.apache.xmlrpc.client.util.ClientFactory;
37
38 /**
39  * TestClient
40  * 
41  * Test client for Archiva Web Services. 
42  * To execute:
43  * 
44  * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
45  *    - url
46  *    - username
47  *    - password
48  * 2. execute 'mvn exec:java' from the command-line
49  * 
50  * @author 
51  * @version $Id$
52  */
53 public class SampleClient
54 {   
55     public static void main( String[] args ) 
56     {       
57         try
58         {
59             XmlRpcClient client = new XmlRpcClient();
60             
61             XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
62             config.setServerURL( new URL( args[0] ) );
63             config.setBasicUserName( args[1] );
64             config.setBasicPassword( args[2] );
65             config.setEnabledForExtensions( true );
66             
67             client.setConfig( config );
68             
69             /* managed repositories */
70             Object[] params = new Object[]{};
71             Object[] managedRepos = (Object[])
72                  client.execute( "AdministrationService.getAllManagedRepositories", params );                        
73             
74             System.out.println( "\n******** Managed Repositories ********" );
75             for( int i = 0; i < managedRepos.length; i++ )
76             {
77                 System.out.println( "=================================" );
78                 ManagedRepository managedRepo = (ManagedRepository) managedRepos[i];
79                 System.out.println( "Id: " + managedRepo.getId() );
80                 System.out.println( "Name: " + managedRepo.getName() );
81                 System.out.println( "Layout: " + managedRepo.getLayout() );
82                 System.out.println( "URL: " + managedRepo.getUrl() );
83                 System.out.println( "Releases: " + managedRepo.isReleases() );
84                 System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
85             }
86                         
87             /* remote repositories */
88             params = new Object[]{};
89             Object[] remoteReposObj = (Object[])
90                  client.execute( "AdministrationService.getAllRemoteRepositories", params );
91             
92             System.out.println( "\n******** Remote Repositories ********" );
93             for( int i = 0; i < remoteReposObj.length; i++ )
94             {
95                 System.out.println( "=================================" );
96                 RemoteRepository remoteRepo = (RemoteRepository) remoteReposObj[i];
97                 System.out.println( "Id: " + remoteRepo.getId() );
98                 System.out.println( "Name: " + remoteRepo.getName() );
99                 System.out.println( "Layout: " + remoteRepo.getLayout() );
100                 System.out.println( "URL: " + remoteRepo.getUrl() );                    
101             }
102             
103             /* repo consumers */
104             params = new Object[]{};
105             Object[] repoConsumers = (Object[])
106                  client.execute( "AdministrationService.getAllRepositoryConsumers", params );
107             
108             System.out.println( "\n******** Repository Consumers ********" );
109             for( int i = 0; i < repoConsumers.length; i++ )
110             {   
111                 System.out.println( repoConsumers[i] );                    
112             }
113             
114             /* db consumers */
115             params = new Object[]{};
116             Object[] dbConsumers = (Object[])
117                  client.execute( "AdministrationService.getAllDatabaseConsumers", params );
118             
119             System.out.println( "\n******** Database Consumers ********" );
120             for( int i = 0; i < dbConsumers.length; i++ )
121             {   
122                 System.out.println( dbConsumers[i] );                    
123             }
124             
125             /* configure repo consumer */
126             Object[] configureRepoConsumerParams = new Object[] { "internal", "repository-purge", true };            
127             Object configured = client.execute( "AdministrationService.configureRepositoryConsumer", configureRepoConsumerParams );            
128             System.out.println( "\nConfigured repo consumer 'repository-purge' : " + ( ( Boolean ) configured ).booleanValue() );
129             
130             
131             /* configure db consumer */
132             Object[] configureDbConsumerParams = new Object[] { "update-db-bytecode-stats", false };            
133             configured = client.execute( "AdministrationService.configureDatabaseConsumer", configureDbConsumerParams );            
134             System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " + ( ( Boolean ) configured ).booleanValue() );            
135             
136             
137             /* execute repo scanner */
138             Object[] executeRepoScanParams = new Object[] { "internal" };            
139             configured = client.execute( "AdministrationService.executeRepositoryScanner", executeRepoScanParams );            
140             System.out.println( "\nExecuted repo scanner of repository 'internal' : " + ( ( Boolean ) configured ).booleanValue() );
141             
142             
143             /* execute db scanner */
144             Object[] executeDbScanParams = new Object[] {};            
145             configured = client.execute( "AdministrationService.executeDatabaseScanner", executeDbScanParams );
146             System.out.println( "\nExecuted database scanner : " + ( ( Boolean ) configured ).booleanValue() );            
147             
148         }
149         catch ( MalformedURLException e )
150         {
151             e.printStackTrace();
152         }
153         catch ( XmlRpcException e )
154         {
155             e.printStackTrace();
156         }           
157     }
158 }