<version>${tomcat7Version}</version>
<scope>test</scope>
</dependency>
+ <!--
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>${tomcat7Version}</version>
<scope>provided</scope>
</dependency>
+ -->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-metadata-consumer</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<build>
import org.apache.maven.wagon.providers.http.AbstractHttpClientWagon;
import org.apache.maven.wagon.providers.http.HttpConfiguration;
import org.apache.maven.wagon.providers.http.HttpMethodConfiguration;
+import org.apache.maven.wagon.providers.http.HttpWagon;
+import org.apache.maven.wagon.repository.Repository;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
-
+ HttpWagon foo;
if ( wagon instanceof AbstractHttpClientWagon )
{
HttpConfiguration httpConfiguration = new HttpConfiguration();
AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
}
+ wagon.connect( new Repository( remoteRepository.getId(), remoteRepository.getUrl() ) );
+
// we only check connectivity as remote repo can be empty
wagon.getFileList( "/" );
return Boolean.TRUE;
}
- catch ( RepositoryAdminException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( MalformedURLException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( WagonFactoryException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( TransferFailedException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( ResourceDoesNotExistException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( AuthorizationException e )
+ catch ( Exception e )
{
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
deleteTestRepo( testRepoId );
}
+
+
}
+++ /dev/null
-package org.apache.archiva;
-
-/*
- * 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 org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.redback.rest.api.services.RoleManagementService;
-import org.apache.archiva.remotedownload.AbstractDownloadTest;
-import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
-import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.apache.commons.io.FileUtils;
-import org.apache.maven.wagon.providers.http.HttpWagon;
-import org.apache.maven.wagon.repository.Repository;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-/**
- * @author Olivier Lamy
- */
-@RunWith( ArchivaBlockJUnit4ClassRunner.class )
-public class DownloadSnapshotTest
- extends AbstractDownloadTest
-{
- protected Logger log = LoggerFactory.getLogger( getClass() );
-
- @BeforeClass
- public static void setAppServerBase()
- {
- previousAppServerBase = System.getProperty( "appserver.base" );
- System.setProperty( "appserver.base", "target/" + DownloadSnapshotTest.class.getName() );
- }
-
-
- @AfterClass
- public static void resetAppServerBase()
- {
- System.setProperty( "appserver.base", previousAppServerBase );
- }
-
- protected String getSpringConfigLocation()
- {
- return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
- }
-
-
- @Test
- public void downloadSNAPSHOT()
- throws Exception
- {
-
- File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
- if ( tmpIndexDir.exists() )
- {
- FileUtils.deleteDirectory( tmpIndexDir );
- }
- String id = Long.toString( System.currentTimeMillis() );
- ManagedRepository managedRepository = new ManagedRepository();
- managedRepository.setId( id );
- managedRepository.setName( "name of " + id );
- managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/snapshot-repo" );
- managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
-
- ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
-
- if ( managedRepositoriesService.getManagedRepository( id ) != null )
- {
- managedRepositoriesService.deleteManagedRepository( id, false );
- }
-
- getManagedRepositoriesService().addManagedRepository( managedRepository );
-
- RoleManagementService roleManagementService = getRoleManagementService( authorizationHeader );
-
- if ( !roleManagementService.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
- id ) )
- {
- roleManagementService.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id );
- }
-
- getUserService( authorizationHeader ).createGuestUser();
- roleManagementService.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, "guest" );
-
- roleManagementService.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id,
- "guest" );
-
- getUserService( authorizationHeader ).removeFromCache( "guest" );
-
- File file = new File( "target/archiva-model-1.4-M4-SNAPSHOT.jar" );
- if ( file.exists() )
- {
- file.delete();
- }
-
- HttpWagon httpWagon = new HttpWagon();
- httpWagon.connect( new Repository( "foo", "http://localhost:" + port ) );
-
- httpWagon.get( "/repository/"+ id +"/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file );
-
- ZipFile zipFile = new ZipFile( file );
- List<String> entries = getZipEntriesNames( zipFile );
- ZipEntry zipEntry = zipFile.getEntry( "org/apache/archiva/model/ArchivaArtifact.class" );
- assertNotNull( "cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: "
- + FileUtils.readFileToString( file ), zipEntry );
- zipFile.close();
- file.deleteOnExit();
-
-
-
- }
-
-}
this.redirectPort = redirectServer.getConnectors()[0].getLocalPort();
log.info( "redirect server port {}", redirectPort );
-
-
}
@After
--- /dev/null
+package org.apache.archiva.remotedownload;
+
+/*
+ * 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 org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.redback.rest.api.services.RoleManagementService;
+import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.wagon.providers.http.HttpWagon;
+import org.apache.maven.wagon.repository.Repository;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * @author Olivier Lamy
+ */
+@RunWith( ArchivaBlockJUnit4ClassRunner.class )
+public class DownloadSnapshotTest
+ extends AbstractDownloadTest
+{
+ protected Logger log = LoggerFactory.getLogger( getClass() );
+
+ @BeforeClass
+ public static void setAppServerBase()
+ {
+ previousAppServerBase = System.getProperty( "appserver.base" );
+ System.setProperty( "appserver.base", "target/" + DownloadSnapshotTest.class.getName() );
+ }
+
+
+ @AfterClass
+ public static void resetAppServerBase()
+ {
+ System.setProperty( "appserver.base", previousAppServerBase );
+ }
+
+ protected String getSpringConfigLocation()
+ {
+ return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
+ }
+
+
+ @Test
+ public void downloadSNAPSHOT()
+ throws Exception
+ {
+
+ File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
+ if ( tmpIndexDir.exists() )
+ {
+ FileUtils.deleteDirectory( tmpIndexDir );
+ }
+ String id = Long.toString( System.currentTimeMillis() );
+ ManagedRepository managedRepository = new ManagedRepository();
+ managedRepository.setId( id );
+ managedRepository.setName( "name of " + id );
+ managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/snapshot-repo" );
+ managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
+
+ ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
+
+ if ( managedRepositoriesService.getManagedRepository( id ) != null )
+ {
+ managedRepositoriesService.deleteManagedRepository( id, false );
+ }
+
+ getManagedRepositoriesService().addManagedRepository( managedRepository );
+
+ RoleManagementService roleManagementService = getRoleManagementService( authorizationHeader );
+
+ if ( !roleManagementService.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+ id ) )
+ {
+ roleManagementService.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id );
+ }
+
+ getUserService( authorizationHeader ).createGuestUser();
+ roleManagementService.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, "guest" );
+
+ roleManagementService.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id,
+ "guest" );
+
+ getUserService( authorizationHeader ).removeFromCache( "guest" );
+
+ File file = new File( "target/archiva-model-1.4-M4-SNAPSHOT.jar" );
+ if ( file.exists() )
+ {
+ file.delete();
+ }
+
+ HttpWagon httpWagon = new HttpWagon();
+ httpWagon.connect( new Repository( "foo", "http://localhost:" + port ) );
+
+ httpWagon.get( "/repository/"+ id +"/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file );
+
+ ZipFile zipFile = new ZipFile( file );
+ List<String> entries = getZipEntriesNames( zipFile );
+ ZipEntry zipEntry = zipFile.getEntry( "org/apache/archiva/model/ArchivaArtifact.class" );
+ assertNotNull( "cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: "
+ + FileUtils.readFileToString( file ), zipEntry );
+ zipFile.close();
+ file.deleteOnExit();
+
+
+
+ }
+
+}
--- /dev/null
+package org.apache.archiva;
+
+import com.google.common.io.Files;
+import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.remotedownload.AbstractDownloadTest;
+import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.commons.io.FileUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+
+/**
+ * @author Olivier Lamy
+ */
+public class RemoteRepositoryConnectivityCheckTest
+ extends AbstractDownloadTest
+{
+
+ @BeforeClass
+ public static void setAppServerBase()
+ {
+ previousAppServerBase = System.getProperty( "appserver.base" );
+ System.setProperty( "appserver.base", "target/" + RemoteRepositoryConnectivityCheckTest.class.getName() );
+ }
+
+
+ @AfterClass
+ public static void resetAppServerBase()
+ {
+ System.setProperty( "appserver.base", previousAppServerBase );
+ }
+
+ protected String getSpringConfigLocation()
+ {
+ return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
+ }
+
+ @Test
+ public void checkRemoteConnectivity()
+ throws Exception
+ {
+
+ Server repoServer =
+ buildStaticServer( new File( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ) );
+ repoServer.start();
+
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
+
+ WebClient.client( service ).header( "Authorization", authorizationHeader );
+
+ try
+ {
+
+ int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
+
+ RemoteRepository repo = getRemoteRepository();
+
+ repo.setUrl( "http://localhost:" + repoServerPort );
+
+ service.addRemoteRepository( repo );
+
+ service.checkRemoteConnectivity( repo.getId() );
+ }
+ finally
+ {
+ service.deleteRemoteRepository( "id-new" );
+ repoServer.stop();
+ }
+ }
+
+ @Test
+ public void checkRemoteConnectivityEmptyRemote()
+ throws Exception
+ {
+
+ File tmpDir = Files.createTempDir();
+ Server repoServer = buildStaticServer( tmpDir );
+ repoServer.start();
+
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
+
+ WebClient.client( service ).header( "Authorization", authorizationHeader );
+
+ try
+ {
+
+ int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
+
+ RemoteRepository repo = getRemoteRepository();
+
+ repo.setUrl( "http://localhost:" + repoServerPort );
+
+ service.addRemoteRepository( repo );
+
+ service.checkRemoteConnectivity( repo.getId() );
+ }
+ finally
+ {
+ service.deleteRemoteRepository( "id-new" );
+ FileUtils.deleteQuietly( tmpDir );
+ repoServer.stop();
+ }
+ }
+
+ protected Server buildStaticServer( File path )
+ {
+ Server repoServer = new Server( 0 );
+
+ ResourceHandler resourceHandler = new ResourceHandler();
+ resourceHandler.setDirectoriesListed( true );
+ resourceHandler.setWelcomeFiles( new String[]{ "index.html" } );
+ resourceHandler.setResourceBase( path.getAbsolutePath() );
+
+ HandlerList handlers = new HandlerList();
+ handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
+ repoServer.setHandler( handlers );
+
+ return repoServer;
+ }
+
+
+ RemoteRepository getRemoteRepository()
+ {
+ return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,
+ "cool repo" );
+ }
+
+}