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
23 import java.util.List;
25 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
26 import org.apache.archiva.web.xmlrpc.api.SearchService;
27 import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
28 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
29 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
31 import com.atlassian.xmlrpc.AuthenticationInfo;
32 import com.atlassian.xmlrpc.Binder;
33 import com.atlassian.xmlrpc.BindingException;
34 import com.atlassian.xmlrpc.DefaultBinder;
39 * Test client for Archiva Web Services.
42 * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
46 * 2. execute 'mvn exec:java' from the command-line
50 public class SampleClient
52 public static void main( String[] args )
54 Binder binder = new DefaultBinder();
58 AuthenticationInfo authnInfo = new AuthenticationInfo( args[1], args[2] );
59 AdministrationService adminService = binder.bind( AdministrationService.class, new URL( args[0] ), authnInfo );
60 List<ManagedRepository> managedRepos = adminService.getAllManagedRepositories();
62 System.out.println( "\n******** Managed Repositories ********" );
63 for( ManagedRepository managedRepo : managedRepos )
65 System.out.println( "=================================" );
66 System.out.println( "Id: " + managedRepo.getId() );
67 System.out.println( "Name: " + managedRepo.getName() );
68 System.out.println( "Layout: " + managedRepo.getLayout() );
69 System.out.println( "URL: " + managedRepo.getUrl() );
70 System.out.println( "Releases: " + managedRepo.isReleases() );
71 System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
74 System.out.println( "\n******** Remote Repositories ********" );
75 List<RemoteRepository> remoteRepos = adminService.getAllRemoteRepositories();
76 for( RemoteRepository remoteRepo : remoteRepos )
78 System.out.println( "=================================" );
79 System.out.println( "Id: " + remoteRepo.getId() );
80 System.out.println( "Name: " + remoteRepo.getName() );
81 System.out.println( "Layout: " + remoteRepo.getLayout() );
82 System.out.println( "URL: " + remoteRepo.getUrl() );
85 System.out.println( "\n******** Repository Consumers ********" );
86 List<String> repoConsumers = adminService.getAllRepositoryConsumers();
87 for( String consumer : repoConsumers )
89 System.out.println( consumer );
92 System.out.println( "\n******** Database Consumers ********" );
93 List<String> dbConsumers = adminService.getAllDatabaseConsumers();
94 for( String consumer : dbConsumers )
96 System.out.println( consumer );
99 Boolean success = adminService.configureRepositoryConsumer( "internal", "repository-purge", true );
100 System.out.println( "\nConfigured repo consumer 'repository-purge' : " +
101 ( (Boolean) success ).booleanValue() );
103 success = adminService.configureDatabaseConsumer( "update-db-bytecode-stats", false );
104 System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " +
105 ( (Boolean) success ).booleanValue() );
107 success = adminService.executeRepositoryScanner( "internal" );
108 System.out.println( "\nExecuted repo scanner of repository 'internal' : " +
109 ( (Boolean) success ).booleanValue() );
111 success = adminService.executeDatabaseScanner();
112 System.out.println( "\nExecuted database scanner : " + ( (Boolean) success ).booleanValue() );
114 /* delete artifact */
116 * NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!
118 success = adminService.deleteArtifact( "internal", "javax.activation", "activation", "1.1" );
119 System.out.println( "\nDeleted artifact 'javax.activation:activation:1.1' from repository 'internal' : " +
120 ( (Boolean) success ).booleanValue() );
125 * NOTE: before enabling & invoking search service, make sure that the artifacts you're searching
126 * for has been indexed already in order to get results
128 SearchService searchService = binder.bind( SearchService.class, new URL( args[0] ), authnInfo );
129 List<Artifact> artifacts = searchService.quickSearch( "org" );
131 System.out.println( "\n************ Search Results for 'org' *************" );
132 for( Artifact artifact : artifacts )
134 System.out.println( "Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() +
135 ":" + artifact.getVersion() );
140 catch ( BindingException e )