1 package org.apache.archiva.web.xmlrpc.client;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.lang.reflect.InvocationTargetException;
23 import java.net.MalformedURLException;
25 import java.util.Iterator;
26 import java.util.List;
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;
43 * Test client for Archiva Web Services.
46 * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
50 * 2. execute 'mvn exec:java' from the command-line
55 public class SampleClient
57 public static void main( String[] args )
61 XmlRpcClient client = new XmlRpcClient();
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 );
69 client.setConfig( config );
71 /* managed repositories */
72 Object[] params = new Object[]{};
73 Object[] managedRepos = (Object[])
74 client.execute( "AdministrationService.getAllManagedRepositories", params );
76 System.out.println( "\n******** Managed Repositories ********" );
77 for( int i = 0; i < managedRepos.length; i++ )
79 System.out.println( "=================================" );
80 ManagedRepository managedRepo = new ManagedRepository();
83 BeanUtils.populate( managedRepo, (Map)managedRepos[i] );
85 catch ( IllegalAccessException e )
89 catch ( InvocationTargetException e )
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() );
101 /* remote repositories */
102 params = new Object[]{};
103 Object[] remoteRepos = (Object[])
104 client.execute( "AdministrationService.getAllRemoteRepositories", params );
106 System.out.println( "\n******** Remote Repositories ********" );
107 for( int i = 0; i < remoteRepos.length; i++ )
109 System.out.println( "=================================" );
110 RemoteRepository remoteRepo = new RemoteRepository();
114 BeanUtils.populate( remoteRepo, (Map) remoteRepos[i] );
116 catch ( IllegalAccessException e )
120 catch ( InvocationTargetException e )
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() );
131 params = new Object[]{};
132 Object[] repoConsumers = (Object[])
133 client.execute( "AdministrationService.getAllRepositoryConsumers", params );
135 System.out.println( "\n******** Repository Consumers ********" );
136 for( int i = 0; i < repoConsumers.length; i++ )
138 System.out.println( repoConsumers[i] );
142 params = new Object[]{};
143 Object[] dbConsumers = (Object[])
144 client.execute( "AdministrationService.getAllDatabaseConsumers", params );
146 System.out.println( "\n******** Database Consumers ********" );
147 for( int i = 0; i < dbConsumers.length; i++ )
149 System.out.println( dbConsumers[i] );
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() );
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() );
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() );
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() );
176 catch ( MalformedURLException e )
180 catch ( XmlRpcException e )