- 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
This commit is contained in:
Maria Odea B. Ching 2008-10-16 09:56:06 +00:00
parent 9e9384ab4e
commit 5f18f8d013
10 changed files with 296 additions and 132 deletions

View File

@ -84,6 +84,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-rss</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-services</artifactId>

View File

@ -31,18 +31,25 @@
<property name="location" value="classpath:application.properties" />
</bean>
<bean name="testXmlRpcService" lazy-init="true" scope="singleton" class="org.apache.maven.archiva.web.xmlrpc.services.PingServiceImpl"/>
<bean name="testXmlRpcService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.PingServiceImpl"/>
<bean name="administrationXmlRpcService" lazy-init="true" scope="singleton" class="org.apache.maven.archiva.web.xmlrpc.services.AdministrationServiceImpl"/>
<bean name="administrationService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.AdministrationServiceImpl">
<constructor-arg ref="archivaConfiguration"/>
<constructor-arg ref="repositoryContentConsumers"/>
<constructor-arg ref="databaseConsumers"/>
<constructor-arg ref="repositoryContentFactory"/>
<constructor-arg ref="artifactDAO#jdo"/>
<constructor-arg ref="databaseCleanupConsumer#not-present-remove-db-artifact"/>
<constructor-arg ref="databaseCleanupConsumer#not-present-remove-db-project"/>
</bean>
<bean name="xmlrpcServicesList" class="java.util.ArrayList">
<constructor-arg>
<ref bean="testXmlRpcService"/>
<ref bean="administrationXmlRpcService"/>
<bean name="xmlrpcServicesList" lazy-init="true" scope="singleton" class="java.util.ArrayList">
<constructor-arg>
<ref bean="administrationService"/>
</constructor-arg>
</bean>
<bean name="xmlRpcAuthenticator" class="org.apache.maven.archiva.xmlrpc.security.XmlRpcAuthenticator">
<bean name="xmlRpcAuthenticator" class="org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator">
<constructor-arg>
<ref bean="securitySystem"/>
</constructor-arg>

View File

@ -113,6 +113,10 @@
<param-name>authHandlerBeanName</param-name>
<param-value>xmlRpcAuthenticator</param-value>
</init-param>
<init-param>
<param-name>enabledForExtensions</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

View File

@ -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<String> 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:

View File

@ -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();
}
}
}

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->
<project>
<parent>
<artifactId>archiva-xmlrpc</artifactId>
<groupId>org.apache.archiva</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>archiva-xmlrpc-client</artifactId>
<name>Archiva Web :: XML-RPC Client</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<mainClass>org.apache.archiva.web.xmlrpc.client.SampleClient</mainClass>
<arguments>
<!-- URL ex. http://127.0.0.1:8080/archiva/xmlrpc -->
<argument>URL</argument>
<argument>USERNAME</argument>
<argument>PASSWORD</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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 <arguments> 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();
}
}
}

View File

@ -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<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
List<DatabaseUnprocessedArtifactConsumer> 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;
}
}

View File

@ -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 */

View File

@ -17,11 +17,7 @@
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
@ -36,5 +32,6 @@
<module>archiva-xmlrpc-api</module>
<module>archiva-xmlrpc-services</module>
<module>archiva-xmlrpc-security</module>
<module>archiva-xmlrpc-client</module>
</modules>
</project>
</project>