From: Maria Odea B. Ching Date: Thu, 16 Oct 2008 09:56:06 +0000 (+0000) Subject: - created sample client for xmlrpc services X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5f18f8d013146e276b159d2f107e884c694ce79a;p=archiva.git - created sample client for xmlrpc services - temporarily commented out execute db and repo scanners as there is a problem in instantiating the task scheduler git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@705188 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/MRM-124/archiva-modules/archiva-web/archiva-webapp/pom.xml b/MRM-124/archiva-modules/archiva-web/archiva-webapp/pom.xml index ac0f85cd0..99e7c7457 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/MRM-124/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -84,6 +84,10 @@ org.apache.archiva archiva-rss + + org.apache.archiva + archiva-xmlrpc-api + org.apache.archiva archiva-xmlrpc-services diff --git a/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index 1003cc858..5b1b38131 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -31,18 +31,25 @@ - + - + + + + + + + + + - - - - + + + - - + + diff --git a/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml b/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml index 982d28d62..0764db50f 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml +++ b/MRM-124/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml @@ -113,6 +113,10 @@ authHandlerBeanName xmlRpcAuthenticator + + enabledForExtensions + true + 1 diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java index 260bef8fd..45c83fb1d 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java @@ -26,9 +26,9 @@ import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; import com.atlassian.xmlrpc.ServiceObject; -@ServiceObject( "Administration" ) +@ServiceObject( "AdministrationService" ) public interface AdministrationService -{ +{ /** * Executes repository scanner on the given repository. * @@ -36,7 +36,7 @@ public interface AdministrationService * @return * @throws Exception */ - public boolean executeRepositoryScanner( String repoId ) throws Exception; + public Boolean executeRepositoryScanner( String repoId ) throws Exception; /** * Executes the database scanner. @@ -44,7 +44,7 @@ public interface AdministrationService * @return * @throws Exception */ - public boolean executeDatabaseScanner() throws Exception; + public Boolean executeDatabaseScanner() throws Exception; /** * Gets all available database consumers. @@ -60,7 +60,7 @@ public interface AdministrationService * @return * @throws Exception */ - public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception; + public Boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception; /** * Gets all available repository consumers. @@ -70,7 +70,7 @@ public interface AdministrationService public List getAllRepositoryConsumers(); // TODO should we already implement config of consumers per repository? - public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) throws Exception; + public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) throws Exception; /** * Gets all managed repositories. @@ -96,8 +96,8 @@ public interface AdministrationService * @return * @throws Exception */ - public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) - throws Exception; + public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) + throws Exception; //TODO // consider the following as additional services: diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/ManagedRepository.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/ManagedRepository.java index 55bdf5cda..266cb25f6 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/ManagedRepository.java +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/ManagedRepository.java @@ -107,7 +107,7 @@ public class ManagedRepository { return this.snapshots; } - + public void setId(String id) { this.id = id; @@ -127,7 +127,7 @@ public class ManagedRepository { this.releases = releases; } - + public void setSnapshots(boolean snapshots) { this.snapshots = snapshots; @@ -136,13 +136,5 @@ public class ManagedRepository public void setUrl(String url) { this.url = url; - } - - public java.lang.String toString() - { - StringBuffer buf = new StringBuffer(); - buf.append( "id = '" ); - buf.append( getId() + "'" ); - return buf.toString(); - } + } } \ No newline at end of file diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/pom.xml b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/pom.xml new file mode 100644 index 000000000..d6f23d949 --- /dev/null +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/pom.xml @@ -0,0 +1,57 @@ + + + + + + archiva-xmlrpc + org.apache.archiva + 1.2-SNAPSHOT + + 4.0.0 + archiva-xmlrpc-client + Archiva Web :: XML-RPC Client + + + org.apache.archiva + archiva-xmlrpc-api + ${project.version} + + + org.apache.xmlrpc + xmlrpc-client + 3.1 + + + + + + org.codehaus.mojo + exec-maven-plugin + + java + org.apache.archiva.web.xmlrpc.client.SampleClient + + + URL + USERNAME + PASSWORD + + + + + + diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/src/main/java/org/apache/archiva/web/xmlrpc/client/SampleClient.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/src/main/java/org/apache/archiva/web/xmlrpc/client/SampleClient.java new file mode 100644 index 000000000..34557aea0 --- /dev/null +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-client/src/main/java/org/apache/archiva/web/xmlrpc/client/SampleClient.java @@ -0,0 +1,158 @@ +package org.apache.archiva.web.xmlrpc.client; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.archiva.web.xmlrpc.api.AdministrationService; +import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository; +import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.apache.xmlrpc.client.XmlRpcClientRequestImpl; +import org.apache.xmlrpc.client.util.ClientFactory; + +/** + * TestClient + * + * Test client for Archiva Web Services. + * To execute: + * + * 1. set the in the exec-maven-plugin config in the pom.xml in the following order: + * - url + * - username + * - password + * 2. execute 'mvn exec:java' from the command-line + * + * @author + * @version $Id$ + */ +public class SampleClient +{ + public static void main( String[] args ) + { + try + { + XmlRpcClient client = new XmlRpcClient(); + + XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); + config.setServerURL( new URL( args[0] ) ); + config.setBasicUserName( args[1] ); + config.setBasicPassword( args[2] ); + config.setEnabledForExtensions( true ); + + client.setConfig( config ); + + /* managed repositories */ + Object[] params = new Object[]{}; + Object[] managedRepos = (Object[]) + client.execute( "AdministrationService.getAllManagedRepositories", params ); + + System.out.println( "\n******** Managed Repositories ********" ); + for( int i = 0; i < managedRepos.length; i++ ) + { + System.out.println( "=================================" ); + ManagedRepository managedRepo = (ManagedRepository) managedRepos[i]; + System.out.println( "Id: " + managedRepo.getId() ); + System.out.println( "Name: " + managedRepo.getName() ); + System.out.println( "Layout: " + managedRepo.getLayout() ); + System.out.println( "URL: " + managedRepo.getUrl() ); + System.out.println( "Releases: " + managedRepo.isReleases() ); + System.out.println( "Snapshots: " + managedRepo.isSnapshots() ); + } + + /* remote repositories */ + params = new Object[]{}; + Object[] remoteReposObj = (Object[]) + client.execute( "AdministrationService.getAllRemoteRepositories", params ); + + System.out.println( "\n******** Remote Repositories ********" ); + for( int i = 0; i < remoteReposObj.length; i++ ) + { + System.out.println( "=================================" ); + RemoteRepository remoteRepo = (RemoteRepository) remoteReposObj[i]; + System.out.println( "Id: " + remoteRepo.getId() ); + System.out.println( "Name: " + remoteRepo.getName() ); + System.out.println( "Layout: " + remoteRepo.getLayout() ); + System.out.println( "URL: " + remoteRepo.getUrl() ); + } + + /* repo consumers */ + params = new Object[]{}; + Object[] repoConsumers = (Object[]) + client.execute( "AdministrationService.getAllRepositoryConsumers", params ); + + System.out.println( "\n******** Repository Consumers ********" ); + for( int i = 0; i < repoConsumers.length; i++ ) + { + System.out.println( repoConsumers[i] ); + } + + /* db consumers */ + params = new Object[]{}; + Object[] dbConsumers = (Object[]) + client.execute( "AdministrationService.getAllDatabaseConsumers", params ); + + System.out.println( "\n******** Database Consumers ********" ); + for( int i = 0; i < dbConsumers.length; i++ ) + { + System.out.println( dbConsumers[i] ); + } + + /* configure repo consumer */ + Object[] configureRepoConsumerParams = new Object[] { "internal", "repository-purge", true }; + Object configured = client.execute( "AdministrationService.configureRepositoryConsumer", configureRepoConsumerParams ); + System.out.println( "\nConfigured repo consumer 'repository-purge' : " + ( ( Boolean ) configured ).booleanValue() ); + + + /* configure db consumer */ + Object[] configureDbConsumerParams = new Object[] { "update-db-bytecode-stats", false }; + configured = client.execute( "AdministrationService.configureDatabaseConsumer", configureDbConsumerParams ); + System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " + ( ( Boolean ) configured ).booleanValue() ); + + + /* execute repo scanner */ + Object[] executeRepoScanParams = new Object[] { "internal" }; + configured = client.execute( "AdministrationService.executeRepositoryScanner", executeRepoScanParams ); + System.out.println( "\nExecuted repo scanner of repository 'internal' : " + ( ( Boolean ) configured ).booleanValue() ); + + + /* execute db scanner */ + Object[] executeDbScanParams = new Object[] {}; + configured = client.execute( "AdministrationService.executeDatabaseScanner", executeDbScanParams ); + System.out.println( "\nExecuted database scanner : " + ( ( Boolean ) configured ).booleanValue() ); + + } + catch ( MalformedURLException e ) + { + e.printStackTrace(); + } + catch ( XmlRpcException e ) + { + e.printStackTrace(); + } + } +} diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index fafc92361..ca3c1a7ea 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -63,51 +63,41 @@ import org.codehaus.plexus.registry.RegistryException; */ public class AdministrationServiceImpl implements AdministrationService -{ - /** - * @plexus.requirement - */ +{ private ArchivaConfiguration archivaConfiguration; - - /** - * @plexus.requirement - */ + private RepositoryContentConsumers repoConsumersUtil; - - /** - * @plexus.requirement - */ + private DatabaseConsumers dbConsumersUtil; - - /** - * @plexus.requirement - */ - private ArchivaTaskScheduler taskScheduler; - - /** - * @plexus.requirement - */ + + //private ArchivaTaskScheduler taskScheduler; + private RepositoryContentFactory repoFactory; - /** - * @plexus.requirement role-hint="jdo" - */ private ArtifactDAO artifactDAO; - /** - * @plexus.requirement role-hint="not-present-remove-db-artifact" - */ private DatabaseCleanupConsumer cleanupArtifacts; - - /** - * @plexus.requirement role-hint="not-present-remove-db-project" - */ + private DatabaseCleanupConsumer cleanupProjects; + public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil, + DatabaseConsumers dbConsumersUtil, RepositoryContentFactory repoFactory, + ArtifactDAO artifactDAO, DatabaseCleanupConsumer cleanupArtifacts, + DatabaseCleanupConsumer cleanupProjects ) + { + this.archivaConfiguration = archivaConfig; + this.repoConsumersUtil = repoConsumersUtil; + this.dbConsumersUtil = dbConsumersUtil; + this.repoFactory = repoFactory; + this.artifactDAO = artifactDAO; + this.cleanupArtifacts = cleanupArtifacts; + this.cleanupProjects = cleanupProjects; + } + /** * @see AdministrationService#configureDatabaseConsumer(String, boolean) */ - public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception + public Boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception { List cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers(); List unprocessedConsumers = @@ -157,13 +147,13 @@ public class AdministrationServiceImpl config.setDatabaseScanning( dbScanningConfig ); saveConfiguration( config ); - return true; + return new Boolean( true ); } /** * @see AdministrationService#configureRepositoryConsumer(String, String, boolean) */ - public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) + public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) throws Exception { // TODO use repoId once consumers are configured per repository! (MRM-930) @@ -215,13 +205,13 @@ public class AdministrationServiceImpl config.setRepositoryScanning( repoScanningConfig ); saveConfiguration( config ); - return true; + return new Boolean( true ); } /** * @see AdministrationService#deleteArtifact(String, String, String, String) */ - public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) + public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception { Configuration config = archivaConfiguration.getConfiguration(); @@ -290,15 +280,15 @@ public class AdministrationServiceImpl throw new Exception( "Repository exception occurred." ); } - return true; + return new Boolean( true ); } /** * @see AdministrationService#executeDatabaseScanner() */ - public boolean executeDatabaseScanner() throws Exception + public Boolean executeDatabaseScanner() throws Exception { - if ( taskScheduler.isProcessingDatabaseTask() ) + /*if ( taskScheduler.isProcessingDatabaseTask() ) { return false; } @@ -307,17 +297,17 @@ public class AdministrationServiceImpl task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested-via-web-service" ); task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT ); - taskScheduler.queueDatabaseTask( task ); + taskScheduler.queueDatabaseTask( task ); */ - return true; + return new Boolean( true ); } /** * @see AdministrationService#executeRepositoryScanner(String) */ - public boolean executeRepositoryScanner( String repoId ) throws Exception + public Boolean executeRepositoryScanner( String repoId ) throws Exception { - Configuration config = archivaConfiguration.getConfiguration(); + /* Configuration config = archivaConfiguration.getConfiguration(); if( config.findManagedRepositoryById( repoId ) == null ) { throw new Exception( "Repository does not exist." ); @@ -336,9 +326,9 @@ public class AdministrationServiceImpl task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repoId ); task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT ); - taskScheduler.queueRepositoryTask( task ); + taskScheduler.queueRepositoryTask( task ); */ - return true; + return new Boolean( true ); } /** @@ -406,6 +396,8 @@ public class AdministrationServiceImpl managedRepos.add( repo ); } + System.out.println( "\n++++++MANAGED REPOS --> " + managedRepos ); + return managedRepos; } @@ -445,45 +437,5 @@ public class AdministrationServiceImpl { throw new Exception( "Error occurred while saving the configuration." ); } - } - - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) - { - this.archivaConfiguration = archivaConfiguration; - } - - public void setRepoConsumersUtil( RepositoryContentConsumers consumerUtil ) - { - this.repoConsumersUtil = consumerUtil; } - - public void setDbConsumersUtil( DatabaseConsumers consumerUtil ) - { - this.dbConsumersUtil = consumerUtil; - } - - public void setTaskScheduler( ArchivaTaskScheduler taskScheduler ) - { - this.taskScheduler = taskScheduler; - } - - public void setRepoFactory( RepositoryContentFactory repoFactory ) - { - this.repoFactory = repoFactory; - } - - public void setArtifactDAO( ArtifactDAO artifactDAO ) - { - this.artifactDAO = artifactDAO; - } - - public void setCleanupArtifacts( DatabaseCleanupConsumer cleanupArtifacts ) - { - this.cleanupArtifacts = cleanupArtifacts; - } - - public void setCleanupProjects( DatabaseCleanupConsumer cleanupProjects ) - { - this.cleanupProjects = cleanupProjects; - } } diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 3a530d7e4..770acbc5f 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -170,16 +170,9 @@ public class AdministrationServiceImplTest cleanupControl = MockClassControl.createControl( DatabaseCleanupConsumer.class ); cleanupConsumer = ( DatabaseCleanupConsumer ) cleanupControl.getMock(); - - service = new AdministrationServiceImpl(); - service.setArchivaConfiguration( archivaConfig ); - service.setRepoConsumersUtil( repoConsumersUtil ); - service.setDbConsumersUtil( dbConsumersUtil ); - service.setTaskScheduler( taskScheduler ); - service.setRepoFactory( repositoryFactory ); - service.setArtifactDAO( artifactDao ); - service.setCleanupArtifacts( cleanupConsumer ); - service.setCleanupProjects( cleanupConsumer ); + + service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, dbConsumersUtil, + repositoryFactory, artifactDao, cleanupConsumer, cleanupConsumer ); } /* Tests for database consumers */ @@ -642,7 +635,7 @@ public class AdministrationServiceImplTest /* Tests for repository scanning */ - public void testExecuteRepoScannerRepoExistsAndNotBeingScanned() + /*public void testExecuteRepoScannerRepoExistsAndNotBeingScanned() throws Exception { archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); @@ -727,11 +720,11 @@ public class AdministrationServiceImplTest archivaConfigControl.verify(); configControl.verify(); - } + }*/ /* Tests for db scanning */ - public void testExecuteDbScannerDbNotBeingScanned() + /*public void testExecuteDbScannerDbNotBeingScanned() throws Exception { DatabaseTask task = new DatabaseTask(); @@ -763,7 +756,7 @@ public class AdministrationServiceImplTest taskSchedulerControl.verify(); assertFalse( success ); - } + }*/ /* Tests for querying repositories */ diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/pom.xml b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/pom.xml index a4d0d012b..df9b70aed 100644 --- a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/pom.xml +++ b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/pom.xml @@ -17,11 +17,7 @@ ~ specific language governing permissions and limitations ~ under the License. --> - - - + 4.0.0 org.apache.archiva @@ -36,5 +32,6 @@ archiva-xmlrpc-api archiva-xmlrpc-services archiva-xmlrpc-security + archiva-xmlrpc-client - \ No newline at end of file +