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