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.net.MalformedURLException;
24 import java.util.Iterator;
25 import java.util.List;
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;
41 * Test client for Archiva Web Services.
44 * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
48 * 2. execute 'mvn exec:java' from the command-line
53 public class SampleClient
55 public static void main( String[] args )
59 XmlRpcClient client = new XmlRpcClient();
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 );
67 client.setConfig( config );
69 /* managed repositories */
70 Object[] params = new Object[]{};
71 Object[] managedRepos = (Object[])
72 client.execute( "AdministrationService.getAllManagedRepositories", params );
74 System.out.println( "\n******** Managed Repositories ********" );
75 for( int i = 0; i < managedRepos.length; i++ )
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() );
87 /* remote repositories */
88 params = new Object[]{};
89 Object[] remoteReposObj = (Object[])
90 client.execute( "AdministrationService.getAllRemoteRepositories", params );
92 System.out.println( "\n******** Remote Repositories ********" );
93 for( int i = 0; i < remoteReposObj.length; i++ )
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() );
104 params = new Object[]{};
105 Object[] repoConsumers = (Object[])
106 client.execute( "AdministrationService.getAllRepositoryConsumers", params );
108 System.out.println( "\n******** Repository Consumers ********" );
109 for( int i = 0; i < repoConsumers.length; i++ )
111 System.out.println( repoConsumers[i] );
115 params = new Object[]{};
116 Object[] dbConsumers = (Object[])
117 client.execute( "AdministrationService.getAllDatabaseConsumers", params );
119 System.out.println( "\n******** Database Consumers ********" );
120 for( int i = 0; i < dbConsumers.length; i++ )
122 System.out.println( dbConsumers[i] );
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() );
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() );
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() );
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() );
149 catch ( MalformedURLException e )
153 catch ( XmlRpcException e )