* @author Olivier Lamy
* @since 1.4-M1
*/
-@Path( "/remoteRepositoriesService/" )
+@Path("/remoteRepositoriesService/")
public interface RemoteRepositoriesService
{
- @Path( "getRemoteRepositories" )
+ @Path("getRemoteRepositories")
@GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
List<RemoteRepository> getRemoteRepositories()
throws ArchivaRestServiceException;
- @Path( "getRemoteRepository/{repositoryId}" )
+ @Path("getRemoteRepository/{repositoryId}")
@GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- RemoteRepository getRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+ RemoteRepository getRemoteRepository( @PathParam("repositoryId") String repositoryId )
throws ArchivaRestServiceException;
- @Path( "deleteRemoteRepository/{repositoryId}" )
+ @Path("deleteRemoteRepository/{repositoryId}")
@GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean deleteRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
- throws Exception;
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+ Boolean deleteRemoteRepository( @PathParam("repositoryId") String repositoryId )
+ throws ArchivaRestServiceException;
- @Path( "addRemoteRepository" )
+ @Path("addRemoteRepository")
@POST
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
Boolean addRemoteRepository( RemoteRepository remoteRepository )
- throws Exception;
+ throws ArchivaRestServiceException;
- @Path( "updateRemoteRepository" )
+ @Path("updateRemoteRepository")
@POST
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
Boolean updateRemoteRepository( RemoteRepository remoteRepository )
- throws Exception;
-
+ throws ArchivaRestServiceException;
+ @Path("checkRemoteConnectivity/{repositoryId}")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+ Boolean checkRemoteConnectivity( @PathParam( "repositoryId" ) String repositoryId )
+ throws ArchivaRestServiceException;
}
*/
import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.NetworkProxy;
import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
+import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.StreamWagon;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+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.springframework.stereotype.Service;
import javax.inject.Inject;
+import javax.ws.rs.core.Response;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collections;
import java.util.List;
* @author Olivier Lamy
* @since 1.4-M1
*/
-@Service ("remoteRepositoriesService#rest")
+@Service( "remoteRepositoriesService#rest" )
public class DefaultRemoteRepositoriesService
extends AbstractRestService
implements RemoteRepositoriesService
@Inject
private RemoteRepositoryAdmin remoteRepositoryAdmin;
+ @Inject
+ private WagonFactory wagonFactory;
+
+
+ @Inject
+ private NetworkProxyAdmin networkProxyAdmin;
+
public List<RemoteRepository> getRemoteRepositories()
throws ArchivaRestServiceException
{
}
public Boolean deleteRemoteRepository( String repositoryId )
- throws Exception
+ throws ArchivaRestServiceException
{
try
{
}
public Boolean addRemoteRepository( RemoteRepository remoteRepository )
- throws Exception
+ throws ArchivaRestServiceException
{
try
{
}
public Boolean updateRemoteRepository( RemoteRepository remoteRepository )
- throws Exception
+ throws ArchivaRestServiceException
{
try
{
}
}
+ @Override
+ public Boolean checkRemoteConnectivity( String repositoryId )
+ throws ArchivaRestServiceException
+ {
+ try
+ {
+ RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository( repositoryId );
+ if ( remoteRepository == null )
+ {
+ log.warn( "ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId );
+ return Boolean.FALSE;
+ }
+ NetworkProxy networkProxy = null;
+ if ( StringUtils.isNotBlank( remoteRepository.getRemoteDownloadNetworkProxyId() ) )
+ {
+ networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId() );
+ if ( networkProxy == null )
+ {
+ log.warn(
+ "your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
+ remoteRepository.getRemoteDownloadNetworkProxyId() );
+ }
+ }
+
+ String wagonProtocol = new URL( remoteRepository.getUrl() ).getProtocol();
+
+ final Wagon wagon = wagonFactory.getWagon(
+ new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders() ).networkProxy(
+ networkProxy ) );
+ wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
+ wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
+
+ if ( wagon instanceof AbstractHttpClientWagon )
+ {
+ HttpConfiguration httpConfiguration = new HttpConfiguration();
+ HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
+ httpMethodConfiguration.setUsePreemptive( true );
+ httpMethodConfiguration.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
+ httpConfiguration.setGet( httpMethodConfiguration );
+ AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
+ }
+
+ // 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 )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+ }
+
+ }
}