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 com.atlassian.xmlrpc.AuthenticationInfo;
26 import com.atlassian.xmlrpc.Binder;
27 import com.atlassian.xmlrpc.BindingException;
28 import com.atlassian.xmlrpc.DefaultBinder;
29 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
30 import org.apache.archiva.web.xmlrpc.api.PingService;
31 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
32 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
37 * Test client for Archiva Web Services.
40 * 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
44 * 2. execute 'mvn exec:java' from the command-line
48 public class SampleClient
50 public static void main( String[] args )
52 Binder binder = new DefaultBinder();
56 AuthenticationInfo authnInfo = new AuthenticationInfo( args[1], args[2] );
57 AdministrationService adminService = binder.bind( AdministrationService.class, new URL( args[0] ), authnInfo );
58 PingService pingService = binder.bind( PingService.class, new URL( args[0] ), authnInfo );
60 System.out.println( "Ping : " + pingService.ping() );
62 List<ManagedRepository> managedRepos = adminService.getAllManagedRepositories();
64 System.out.println( "\n******** Managed Repositories ********" );
65 for( ManagedRepository managedRepo : managedRepos )
67 System.out.println( "=================================" );
68 System.out.println( "Id: " + managedRepo.getId() );
69 System.out.println( "Name: " + managedRepo.getName() );
70 System.out.println( "Layout: " + managedRepo.getLayout() );
71 System.out.println( "URL: " + managedRepo.getUrl() );
72 System.out.println( "Releases: " + managedRepo.isReleases() );
73 System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
76 System.out.println( "\n******** Remote Repositories ********" );
77 List<RemoteRepository> remoteRepos = adminService.getAllRemoteRepositories();
78 for( RemoteRepository remoteRepo : remoteRepos )
80 System.out.println( "=================================" );
81 System.out.println( "Id: " + remoteRepo.getId() );
82 System.out.println( "Name: " + remoteRepo.getName() );
83 System.out.println( "Layout: " + remoteRepo.getLayout() );
84 System.out.println( "URL: " + remoteRepo.getUrl() );
87 System.out.println( "\n******** Repository Consumers ********" );
88 List<String> repoConsumers = adminService.getAllRepositoryConsumers();
89 for( String consumer : repoConsumers )
91 System.out.println( consumer );
94 Boolean success = adminService.configureRepositoryConsumer( "internal", "repository-purge", true );
95 System.out.println( "\nConfigured repo consumer 'repository-purge' : " +
96 ( (Boolean) success ).booleanValue() );
98 success = adminService.executeRepositoryScanner( "internal" );
99 System.out.println( "\nExecuted repo scanner of repository 'internal' : " +
100 ( (Boolean) success ).booleanValue() );
102 /* delete artifact */
104 * NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!
106 success = adminService.deleteArtifact( "internal", "javax.activation", "activation", "1.1" );
107 System.out.println( "\nDeleted artifact 'javax.activation:activation:1.1' from repository 'internal' : " +
108 ( (Boolean) success ).booleanValue() );
113 * NOTE: before enabling & invoking search service, make sure that the artifacts you're searching
114 * for has been indexed already in order to get results
116 SearchService searchService = binder.bind( SearchService.class, new URL( args[0] ), authnInfo );
117 List<Artifact> artifacts = searchService.quickSearch( "org" );
119 System.out.println( "\n************ Search Results for 'org' *************" );
120 for( Artifact artifact : artifacts )
122 System.out.println( "Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() +
123 ":" + artifact.getVersion() );
128 catch ( BindingException e )