You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/09/03 20:23:42 UTC
[19/51] [partial] maven-aether git commit: [MNG-6007] rename Aether
to Maven Artifact Resolver
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
deleted file mode 100644
index 169bb12..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
+++ /dev/null
@@ -1,651 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.IOException;
-import java.io.InputStream;
-import java.io.InterruptedIOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.params.AuthParams;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.HttpResponseException;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.methods.HttpOptions;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.utils.URIUtils;
-import org.apache.http.conn.params.ConnRouteParams;
-import org.apache.http.entity.AbstractHttpEntity;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.client.DecompressingHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.cookie.DateUtils;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.util.EntityUtils;
-import org.eclipse.aether.ConfigurationProperties;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.AuthenticationContext;
-import org.eclipse.aether.repository.Proxy;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.spi.connector.transport.AbstractTransporter;
-import org.eclipse.aether.spi.connector.transport.GetTask;
-import org.eclipse.aether.spi.connector.transport.PeekTask;
-import org.eclipse.aether.spi.connector.transport.PutTask;
-import org.eclipse.aether.spi.connector.transport.TransportTask;
-import org.eclipse.aether.spi.log.Logger;
-import org.eclipse.aether.transfer.NoTransporterException;
-import org.eclipse.aether.transfer.TransferCancelledException;
-import org.eclipse.aether.util.ConfigUtils;
-
-/**
- * A transporter for HTTP/HTTPS.
- */
-final class HttpTransporter
- extends AbstractTransporter
-{
-
- private static final Pattern CONTENT_RANGE_PATTERN =
- Pattern.compile( "\\s*bytes\\s+([0-9]+)\\s*-\\s*([0-9]+)\\s*/.*" );
-
- private static final Pattern HOST_SPLIT_PATTERN = Pattern.compile( "\\s*[,]\\s*" );
-
- private final Logger logger;
-
- private final AuthenticationContext repoAuthContext;
-
- private final AuthenticationContext proxyAuthContext;
-
- private final URI baseUri;
-
- private final HttpHost server;
-
- private final HttpHost proxy;
-
- private final HttpClient client;
-
- private final Map<?, ?> headers;
-
- private final LocalState state;
-
- public HttpTransporter( RemoteRepository repository, RepositorySystemSession session, Logger logger )
- throws NoTransporterException
- {
- if ( !"http".equalsIgnoreCase( repository.getProtocol() )
- && !"https".equalsIgnoreCase( repository.getProtocol() ) )
- {
- throw new NoTransporterException( repository );
- }
- this.logger = logger;
- try
- {
- baseUri = new URI( repository.getUrl() ).parseServerAuthority();
- if ( baseUri.isOpaque() )
- {
- throw new URISyntaxException( repository.getUrl(), "URL must not be opaque" );
- }
- server = URIUtils.extractHost( baseUri );
- if ( server == null )
- {
- throw new URISyntaxException( repository.getUrl(), "URL lacks host name" );
- }
- }
- catch ( URISyntaxException e )
- {
- throw new NoTransporterException( repository, e.getMessage(), e );
- }
- proxy = toHost( repository.getProxy() );
-
- repoAuthContext = AuthenticationContext.forRepository( session, repository );
- proxyAuthContext = AuthenticationContext.forProxy( session, repository );
-
- state = new LocalState( session, repository, new SslConfig( session, repoAuthContext ) );
-
- headers =
- ConfigUtils.getMap( session, Collections.emptyMap(), ConfigurationProperties.HTTP_HEADERS + "."
- + repository.getId(), ConfigurationProperties.HTTP_HEADERS );
-
- DefaultHttpClient client = new DefaultHttpClient( state.getConnectionManager() );
-
- configureClient( client.getParams(), session, repository, proxy );
-
- boolean redirectedAuth = getRedirectedAuth( session, repository, server );
- client.setCredentialsProvider( toCredentials( server, repoAuthContext, redirectedAuth, proxy, proxyAuthContext ) );
-
- this.client = new DecompressingHttpClient( client );
- }
-
- private static HttpHost toHost( Proxy proxy )
- {
- HttpHost host = null;
- if ( proxy != null )
- {
- host = new HttpHost( proxy.getHost(), proxy.getPort() );
- }
- return host;
- }
-
- private static void configureClient( HttpParams params, RepositorySystemSession session,
- RemoteRepository repository, HttpHost proxy )
- {
- AuthParams.setCredentialCharset( params,
- ConfigUtils.getString( session,
- ConfigurationProperties.DEFAULT_HTTP_CREDENTIAL_ENCODING,
- ConfigurationProperties.HTTP_CREDENTIAL_ENCODING + "."
- + repository.getId(),
- ConfigurationProperties.HTTP_CREDENTIAL_ENCODING ) );
- ConnRouteParams.setDefaultProxy( params, proxy );
- HttpConnectionParams.setConnectionTimeout( params,
- ConfigUtils.getInteger( session,
- ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT,
- ConfigurationProperties.CONNECT_TIMEOUT
- + "." + repository.getId(),
- ConfigurationProperties.CONNECT_TIMEOUT ) );
- HttpConnectionParams.setSoTimeout( params,
- ConfigUtils.getInteger( session,
- ConfigurationProperties.DEFAULT_REQUEST_TIMEOUT,
- ConfigurationProperties.REQUEST_TIMEOUT + "."
- + repository.getId(),
- ConfigurationProperties.REQUEST_TIMEOUT ) );
- HttpProtocolParams.setUserAgent( params, ConfigUtils.getString( session,
- ConfigurationProperties.DEFAULT_USER_AGENT,
- ConfigurationProperties.USER_AGENT ) );
- }
-
- private static boolean getRedirectedAuth( RepositorySystemSession session, RemoteRepository repo, HttpHost server )
- {
- String mode =
- ConfigUtils.getString( session, ConfigurationProperties.DEFAULT_HTTP_REDIRECTED_AUTHENTICATION,
- ConfigurationProperties.HTTP_REDIRECTED_AUTHENTICATION + '.' + repo.getId(),
- ConfigurationProperties.HTTP_REDIRECTED_AUTHENTICATION );
- if ( "false".equalsIgnoreCase( mode ) )
- {
- return false;
- }
- if ( "true".equalsIgnoreCase( mode ) )
- {
- return true;
- }
- String host = server.getHostName();
- for ( String allowed : HOST_SPLIT_PATTERN.split( mode.trim() ) )
- {
- if ( allowed.equalsIgnoreCase( host ) )
- {
- return true;
- }
- }
- return false;
- }
-
- private static CredentialsProvider toCredentials( HttpHost server, AuthenticationContext serverAuthCtx,
- boolean redirectedAuth, HttpHost proxy,
- AuthenticationContext proxyAuthCtx )
- {
- CredentialsProvider provider =
- toCredentials( redirectedAuth ? AuthScope.ANY_HOST : server.getHostName(), AuthScope.ANY_PORT,
- serverAuthCtx );
- if ( proxy != null )
- {
- CredentialsProvider p = toCredentials( proxy.getHostName(), proxy.getPort(), proxyAuthCtx );
- provider = new DemuxCredentialsProvider( provider, p, proxy );
- }
- return provider;
- }
-
- private static CredentialsProvider toCredentials( String host, int port, AuthenticationContext ctx )
- {
- DeferredCredentialsProvider provider = new DeferredCredentialsProvider();
- if ( ctx != null )
- {
- AuthScope basicScope = new AuthScope( host, port );
- provider.setCredentials( basicScope, new DeferredCredentialsProvider.BasicFactory( ctx ) );
-
- AuthScope ntlmScope = new AuthScope( host, port, AuthScope.ANY_REALM, "ntlm" );
- provider.setCredentials( ntlmScope, new DeferredCredentialsProvider.NtlmFactory( ctx ) );
- }
- return provider;
- }
-
- LocalState getState()
- {
- return state;
- }
-
- private URI resolve( TransportTask task )
- {
- return UriUtils.resolve( baseUri, task.getLocation() );
- }
-
- public int classify( Throwable error )
- {
- if ( error instanceof HttpResponseException
- && ( (HttpResponseException) error ).getStatusCode() == HttpStatus.SC_NOT_FOUND )
- {
- return ERROR_NOT_FOUND;
- }
- return ERROR_OTHER;
- }
-
- @Override
- protected void implPeek( PeekTask task )
- throws Exception
- {
- HttpHead request = commonHeaders( new HttpHead( resolve( task ) ) );
- execute( request, null );
- }
-
- @Override
- protected void implGet( GetTask task )
- throws Exception
- {
- EntityGetter getter = new EntityGetter( task );
- HttpGet request = commonHeaders( new HttpGet( resolve( task ) ) );
- resume( request, task );
- try
- {
- execute( request, getter );
- }
- catch ( HttpResponseException e )
- {
- if ( e.getStatusCode() == HttpStatus.SC_PRECONDITION_FAILED && request.containsHeader( HttpHeaders.RANGE ) )
- {
- request = commonHeaders( new HttpGet( request.getURI() ) );
- execute( request, getter );
- return;
- }
- throw e;
- }
- }
-
- @Override
- protected void implPut( PutTask task )
- throws Exception
- {
- PutTaskEntity entity = new PutTaskEntity( task );
- HttpPut request = commonHeaders( entity( new HttpPut( resolve( task ) ), entity ) );
- try
- {
- execute( request, null );
- }
- catch ( HttpResponseException e )
- {
- if ( e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED && request.containsHeader( HttpHeaders.EXPECT ) )
- {
- state.setExpectContinue( false );
- request = commonHeaders( entity( new HttpPut( request.getURI() ), entity ) );
- execute( request, null );
- return;
- }
- throw e;
- }
- }
-
- private void execute( HttpUriRequest request, EntityGetter getter )
- throws Exception
- {
- try
- {
- SharingHttpContext context = new SharingHttpContext( state );
- prepare( request, context );
- HttpResponse response = client.execute( server, request, context );
- try
- {
- context.close();
- handleStatus( response );
- if ( getter != null )
- {
- getter.handle( response );
- }
- }
- finally
- {
- EntityUtils.consumeQuietly( response.getEntity() );
- }
- }
- catch ( IOException e )
- {
- if ( e.getCause() instanceof TransferCancelledException )
- {
- throw (Exception) e.getCause();
- }
- throw e;
- }
- }
-
- private void prepare( HttpUriRequest request, SharingHttpContext context )
- {
- boolean put = HttpPut.METHOD_NAME.equalsIgnoreCase( request.getMethod() );
- if ( ( put || isPayloadPresent( request ) ) && !state.isProbed() )
- {
- synchronized ( state )
- {
- if ( !state.isProbed() )
- {
- probe( request, context );
- state.setProbed();
- }
- }
- }
- if ( put && state.isWebDav() )
- {
- mkdirs( request.getURI(), context );
- }
- }
-
- private void probe( HttpUriRequest request, SharingHttpContext context )
- {
- try
- {
- HttpOptions req = commonHeaders( new HttpOptions( request.getURI() ) );
- HttpResponse response = client.execute( server, req, context );
- state.setWebDav( isWebDav( response ) );
- EntityUtils.consumeQuietly( response.getEntity() );
- }
- catch ( IOException e )
- {
- logger.debug( "Failed to probe HTTP server", e );
- }
- }
-
- private boolean isWebDav( HttpResponse response )
- {
- return response.containsHeader( HttpHeaders.DAV ) && !isWebDavOptional( response );
- }
-
- private boolean isWebDavOptional( HttpResponse response )
- {
- Header header = response.getFirstHeader( HttpHeaders.SERVER );
- String server = ( header != null ) ? header.getValue() : null;
- // repository managers don't need webdav mode and work fine with straight puts
- return server != null && ( server.startsWith( "Artifactory/" ) || server.startsWith( "Nexus/" ) );
- }
-
- private void mkdirs( URI uri, SharingHttpContext context )
- {
- List<URI> dirs = UriUtils.getDirectories( baseUri, uri );
- int index = 0;
- for ( ; index < dirs.size(); index++ )
- {
- try
- {
- HttpResponse response =
- client.execute( server, commonHeaders( new HttpMkCol( dirs.get( index ) ) ), context );
- try
- {
- int status = response.getStatusLine().getStatusCode();
- if ( status < 300 || status == HttpStatus.SC_METHOD_NOT_ALLOWED )
- {
- // directory was created or already existed
- break;
- }
- else if ( status == HttpStatus.SC_CONFLICT )
- {
- // parent directory needs to be created first
- continue;
- }
- handleStatus( response );
- }
- finally
- {
- EntityUtils.consumeQuietly( response.getEntity() );
- }
- }
- catch ( IOException e )
- {
- logger.debug( "Failed to create parent directory " + dirs.get( index ), e );
- return;
- }
- }
- for ( index--; index >= 0; index-- )
- {
- try
- {
- HttpResponse response =
- client.execute( server, commonHeaders( new HttpMkCol( dirs.get( index ) ) ), context );
- try
- {
- handleStatus( response );
- }
- finally
- {
- EntityUtils.consumeQuietly( response.getEntity() );
- }
- }
- catch ( IOException e )
- {
- logger.debug( "Failed to create parent directory " + dirs.get( index ), e );
- return;
- }
- }
- }
-
- private <T extends HttpEntityEnclosingRequest> T entity( T request, HttpEntity entity )
- {
- request.setEntity( entity );
- return request;
- }
-
- private boolean isPayloadPresent( HttpUriRequest request )
- {
- if ( request instanceof HttpEntityEnclosingRequest )
- {
- HttpEntity entity = ( (HttpEntityEnclosingRequest) request ).getEntity();
- return entity != null && entity.getContentLength() != 0;
- }
- return false;
- }
-
- private <T extends HttpUriRequest> T commonHeaders( T request )
- {
- request.setHeader( HttpHeaders.CACHE_CONTROL, "no-cache, no-store" );
- request.setHeader( HttpHeaders.PRAGMA, "no-cache" );
-
- if ( state.isExpectContinue() && isPayloadPresent( request ) )
- {
- request.setHeader( HttpHeaders.EXPECT, "100-continue" );
- }
-
- for ( Map.Entry<?, ?> entry : headers.entrySet() )
- {
- if ( !( entry.getKey() instanceof String ) )
- {
- continue;
- }
- if ( entry.getValue() instanceof String )
- {
- request.setHeader( entry.getKey().toString(), entry.getValue().toString() );
- }
- else
- {
- request.removeHeaders( entry.getKey().toString() );
- }
- }
-
- if ( !state.isExpectContinue() )
- {
- request.removeHeaders( HttpHeaders.EXPECT );
- }
-
- return request;
- }
-
- private <T extends HttpUriRequest> T resume( T request, GetTask task )
- {
- long resumeOffset = task.getResumeOffset();
- if ( resumeOffset > 0 && task.getDataFile() != null )
- {
- request.setHeader( HttpHeaders.RANGE, "bytes=" + Long.toString( resumeOffset ) + '-' );
- request.setHeader( HttpHeaders.IF_UNMODIFIED_SINCE,
- DateUtils.formatDate( new Date( task.getDataFile().lastModified() - 60 * 1000 ) ) );
- request.setHeader( HttpHeaders.ACCEPT_ENCODING, "identity" );
- }
- return request;
- }
-
- private void handleStatus( HttpResponse response )
- throws HttpResponseException
- {
- int status = response.getStatusLine().getStatusCode();
- if ( status >= 300 )
- {
- throw new HttpResponseException( status, response.getStatusLine().getReasonPhrase() + " (" + status + ")" );
- }
- }
-
- @Override
- protected void implClose()
- {
- AuthenticationContext.close( repoAuthContext );
- AuthenticationContext.close( proxyAuthContext );
- state.close();
- }
-
- private class EntityGetter
- {
-
- private final GetTask task;
-
- public EntityGetter( GetTask task )
- {
- this.task = task;
- }
-
- public void handle( HttpResponse response )
- throws IOException, TransferCancelledException
- {
- HttpEntity entity = response.getEntity();
- if ( entity == null )
- {
- entity = new ByteArrayEntity( new byte[0] );
- }
-
- long offset = 0, length = entity.getContentLength();
- String range = getHeader( response, HttpHeaders.CONTENT_RANGE );
- if ( range != null )
- {
- Matcher m = CONTENT_RANGE_PATTERN.matcher( range );
- if ( !m.matches() )
- {
- throw new IOException( "Invalid Content-Range header for partial download: " + range );
- }
- offset = Long.parseLong( m.group( 1 ) );
- length = Long.parseLong( m.group( 2 ) ) + 1;
- if ( offset < 0 || offset >= length || ( offset > 0 && offset != task.getResumeOffset() ) )
- {
- throw new IOException( "Invalid Content-Range header for partial download from offset "
- + task.getResumeOffset() + ": " + range );
- }
- }
-
- InputStream is = entity.getContent();
- utilGet( task, is, true, length, offset > 0 );
- extractChecksums( response );
- }
-
- private void extractChecksums( HttpResponse response )
- {
- // Nexus-style, ETag: "{SHA1{d40d68ba1f88d8e9b0040f175a6ff41928abd5e7}}"
- String etag = getHeader( response, HttpHeaders.ETAG );
- if ( etag != null )
- {
- int start = etag.indexOf( "SHA1{" ), end = etag.indexOf( "}", start + 5 );
- if ( start >= 0 && end > start )
- {
- task.setChecksum( "SHA-1", etag.substring( start + 5, end ) );
- }
- }
- }
-
- private String getHeader( HttpResponse response, String name )
- {
- Header header = response.getFirstHeader( name );
- return ( header != null ) ? header.getValue() : null;
- }
-
- }
-
- private class PutTaskEntity
- extends AbstractHttpEntity
- {
-
- private final PutTask task;
-
- public PutTaskEntity( PutTask task )
- {
- this.task = task;
- }
-
- public boolean isRepeatable()
- {
- return true;
- }
-
- public boolean isStreaming()
- {
- return false;
- }
-
- public long getContentLength()
- {
- return task.getDataLength();
- }
-
- public InputStream getContent()
- throws IOException
- {
- return task.newInputStream();
- }
-
- public void writeTo( OutputStream os )
- throws IOException
- {
- try
- {
- utilPut( task, os, false );
- }
- catch ( TransferCancelledException e )
- {
- throw (IOException) new InterruptedIOException().initCause( e );
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporterFactory.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporterFactory.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporterFactory.java
deleted file mode 100644
index e9a9bfd..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporterFactory.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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 javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.spi.connector.transport.Transporter;
-import org.eclipse.aether.spi.connector.transport.TransporterFactory;
-import org.eclipse.aether.spi.locator.Service;
-import org.eclipse.aether.spi.locator.ServiceLocator;
-import org.eclipse.aether.spi.log.Logger;
-import org.eclipse.aether.spi.log.LoggerFactory;
-import org.eclipse.aether.spi.log.NullLoggerFactory;
-import org.eclipse.aether.transfer.NoTransporterException;
-
-/**
- * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters
- * support uploads to WebDAV servers and resumable downloads.
- */
-@Named( "http" )
-public final class HttpTransporterFactory
- implements TransporterFactory, Service
-{
-
- private Logger logger = NullLoggerFactory.LOGGER;
-
- private float priority = 5;
-
- /**
- * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
- * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
- * will occur.
- */
- public HttpTransporterFactory()
- {
- // enables default constructor
- }
-
- @Inject
- HttpTransporterFactory( LoggerFactory loggerFactory )
- {
- setLoggerFactory( loggerFactory );
- }
-
- public void initService( ServiceLocator locator )
- {
- setLoggerFactory( locator.getService( LoggerFactory.class ) );
- }
-
- /**
- * Sets the logger factory to use for this component.
- *
- * @param loggerFactory The logger factory to use, may be {@code null} to disable logging.
- * @return This component for chaining, never {@code null}.
- */
- public HttpTransporterFactory setLoggerFactory( LoggerFactory loggerFactory )
- {
- this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, HttpTransporter.class );
- return this;
- }
-
- public float getPriority()
- {
- return priority;
- }
-
- /**
- * Sets the priority of this component.
- *
- * @param priority The priority.
- * @return This component for chaining, never {@code null}.
- */
- public HttpTransporterFactory setPriority( float priority )
- {
- this.priority = priority;
- return this;
- }
-
- public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
- throws NoTransporterException
- {
- return new HttpTransporter( repository, session, logger );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/LocalState.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/LocalState.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/LocalState.java
deleted file mode 100644
index 176b895..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/LocalState.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.Closeable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScheme;
-import org.apache.http.conn.ClientConnectionManager;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.transport.http.GlobalState.CompoundKey;
-import org.eclipse.aether.util.ConfigUtils;
-
-/**
- * Container for HTTP-related state that can be shared across invocations of the transporter to optimize the
- * communication with server.
- */
-final class LocalState
- implements Closeable
-{
-
- private static final String CONFIG_PROP_WEBDAV = "aether.connector.http.webDav";
-
- private final GlobalState global;
-
- private final ClientConnectionManager connMgr;
-
- private final CompoundKey userTokenKey;
-
- private volatile Object userToken;
-
- private final CompoundKey expectContinueKey;
-
- private volatile boolean probed;
-
- private volatile Boolean expectContinue;
-
- private volatile Boolean webDav;
-
- private final ConcurrentMap<HttpHost, AuthSchemePool> authSchemePools;
-
- public LocalState( RepositorySystemSession session, RemoteRepository repo, SslConfig sslConfig )
- {
- global = GlobalState.get( session );
- userToken = this;
- if ( global == null )
- {
- connMgr = GlobalState.newConnectionManager( sslConfig );
- userTokenKey = null;
- expectContinueKey = null;
- authSchemePools = new ConcurrentHashMap<HttpHost, AuthSchemePool>();
- }
- else
- {
- connMgr = global.getConnectionManager( sslConfig );
- userTokenKey = new CompoundKey( repo.getId(), repo.getUrl(), repo.getAuthentication(), repo.getProxy() );
- expectContinueKey = new CompoundKey( repo.getUrl(), repo.getProxy() );
- authSchemePools = global.getAuthSchemePools();
- }
- if ( !ConfigUtils.getBoolean( session, true, CONFIG_PROP_WEBDAV + '.' + repo.getId(), CONFIG_PROP_WEBDAV ) )
- {
- webDav = false;
- }
- }
-
- public ClientConnectionManager getConnectionManager()
- {
- return connMgr;
- }
-
- public Object getUserToken()
- {
- if ( userToken == this )
- {
- userToken = ( global != null ) ? global.getUserToken( userTokenKey ) : null;
- }
- return userToken;
- }
-
- public void setUserToken( Object userToken )
- {
- this.userToken = userToken;
- if ( global != null )
- {
- global.setUserToken( userTokenKey, userToken );
- }
- }
-
- public boolean isProbed()
- {
- return probed;
- }
-
- public void setProbed()
- {
- probed = true;
- }
-
- public boolean isExpectContinue()
- {
- if ( expectContinue == null )
- {
- expectContinue =
- !Boolean.FALSE.equals( ( global != null ) ? global.getExpectContinue( expectContinueKey ) : null );
- }
- return expectContinue;
- }
-
- public void setExpectContinue( boolean enabled )
- {
- expectContinue = enabled;
- if ( global != null )
- {
- global.setExpectContinue( expectContinueKey, enabled );
- }
- }
-
- public boolean isWebDav()
- {
- return Boolean.TRUE.equals( webDav );
- }
-
- public void setWebDav( boolean webDav )
- {
- if ( this.webDav == null )
- {
- this.webDav = webDav;
- }
- }
-
- public AuthScheme getAuthScheme( HttpHost host )
- {
- AuthSchemePool pool = authSchemePools.get( host );
- if ( pool != null )
- {
- return pool.get();
- }
- return null;
- }
-
- public void setAuthScheme( HttpHost host, AuthScheme authScheme )
- {
- AuthSchemePool pool = authSchemePools.get( host );
- if ( pool == null )
- {
- AuthSchemePool p = new AuthSchemePool();
- pool = authSchemePools.putIfAbsent( host, p );
- if ( pool == null )
- {
- pool = p;
- }
- }
- pool.put( authScheme );
- }
-
- public void close()
- {
- if ( global == null )
- {
- connMgr.shutdown();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingAuthCache.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingAuthCache.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingAuthCache.java
deleted file mode 100644
index 1264d04..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingAuthCache.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.util.HashMap;
-import java.util.Map;
-
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScheme;
-import org.apache.http.client.AuthCache;
-
-/**
- * Auth scheme cache that upon clearing releases all cached schemes into a pool for future reuse by other requests,
- * thereby reducing challenge-response roundtrips.
- */
-final class SharingAuthCache
- implements AuthCache
-{
-
- private final LocalState state;
-
- private final Map<HttpHost, AuthScheme> authSchemes;
-
- public SharingAuthCache( LocalState state )
- {
- this.state = state;
- authSchemes = new HashMap<HttpHost, AuthScheme>();
- }
-
- private static HttpHost toKey( HttpHost host )
- {
- if ( host.getPort() <= 0 )
- {
- int port = host.getSchemeName().equalsIgnoreCase( "https" ) ? 443 : 80;
- return new HttpHost( host.getHostName(), port, host.getSchemeName() );
- }
- return host;
- }
-
- public AuthScheme get( HttpHost host )
- {
- host = toKey( host );
- AuthScheme authScheme = authSchemes.get( host );
- if ( authScheme == null )
- {
- authScheme = state.getAuthScheme( host );
- authSchemes.put( host, authScheme );
- }
- return authScheme;
- }
-
- public void put( HttpHost host, AuthScheme authScheme )
- {
- if ( authScheme != null )
- {
- authSchemes.put( toKey( host ), authScheme );
- }
- else
- {
- remove( host );
- }
- }
-
- public void remove( HttpHost host )
- {
- authSchemes.remove( toKey( host ) );
- }
-
- public void clear()
- {
- share();
- authSchemes.clear();
- }
-
- private void share()
- {
- for ( Map.Entry<HttpHost, AuthScheme> entry : authSchemes.entrySet() )
- {
- state.setAuthScheme( entry.getKey(), entry.getValue() );
- }
- }
-
- @Override
- public String toString()
- {
- return authSchemes.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingHttpContext.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingHttpContext.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingHttpContext.java
deleted file mode 100644
index 4464c26..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SharingHttpContext.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.Closeable;
-
-import org.apache.http.client.protocol.ClientContext;
-import org.apache.http.protocol.BasicHttpContext;
-
-/**
- * HTTP context that shares certain attributes among requests to optimize the communication with the server.
- *
- * @see <a href="http://hc.apache.org/httpcomponents-client-ga/tutorial/html/advanced.html#stateful_conn">Stateful HTTP
- * connections</a>
- */
-final class SharingHttpContext
- extends BasicHttpContext
- implements Closeable
-{
-
- private final LocalState state;
-
- private final SharingAuthCache authCache;
-
- public SharingHttpContext( LocalState state )
- {
- this.state = state;
- authCache = new SharingAuthCache( state );
- super.setAttribute( ClientContext.AUTH_CACHE, authCache );
- }
-
- @Override
- public Object getAttribute( String id )
- {
- if ( ClientContext.USER_TOKEN.equals( id ) )
- {
- return state.getUserToken();
- }
- return super.getAttribute( id );
- }
-
- @Override
- public void setAttribute( String id, Object obj )
- {
- if ( ClientContext.USER_TOKEN.equals( id ) )
- {
- state.setUserToken( obj );
- }
- else
- {
- super.setAttribute( id, obj );
- }
- }
-
- @Override
- public Object removeAttribute( String id )
- {
- if ( ClientContext.USER_TOKEN.equals( id ) )
- {
- state.setUserToken( null );
- return null;
- }
- return super.removeAttribute( id );
- }
-
- public void close()
- {
- authCache.clear();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslConfig.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslConfig.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslConfig.java
deleted file mode 100644
index d991796..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslConfig.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.util.Arrays;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.AuthenticationContext;
-import org.eclipse.aether.util.ConfigUtils;
-
-/**
- * SSL-related configuration and cache key for connection pools (whose scheme registries are derived from this config).
- */
-final class SslConfig
-{
-
- private static final String CIPHER_SUITES = "https.cipherSuites";
-
- private static final String PROTOCOLS = "https.protocols";
-
- final SSLContext context;
-
- final HostnameVerifier verifier;
-
- final String[] cipherSuites;
-
- final String[] protocols;
-
- public SslConfig( RepositorySystemSession session, AuthenticationContext authContext )
- {
- context =
- ( authContext != null ) ? authContext.get( AuthenticationContext.SSL_CONTEXT, SSLContext.class ) : null;
- verifier =
- ( authContext != null ) ? authContext.get( AuthenticationContext.SSL_HOSTNAME_VERIFIER,
- HostnameVerifier.class ) : null;
-
- cipherSuites = split( get( session, CIPHER_SUITES ) );
- protocols = split( get( session, PROTOCOLS ) );
- }
-
- private static String get( RepositorySystemSession session, String key )
- {
- String value = ConfigUtils.getString( session, null, "aether.connector." + key, key );
- if ( value == null )
- {
- value = System.getProperty( key );
- }
- return value;
- }
-
- private static String[] split( String value )
- {
- if ( value == null || value.length() <= 0 )
- {
- return null;
- }
- return value.split( ",+" );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- if ( obj == null || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
- SslConfig that = (SslConfig) obj;
- return eq( context, that.context ) && eq( verifier, that.verifier )
- && Arrays.equals( cipherSuites, that.cipherSuites ) && Arrays.equals( protocols, that.protocols );
- }
-
- private static <T> boolean eq( T s1, T s2 )
- {
- return s1 != null ? s1.equals( s2 ) : s2 == null;
- }
-
- @Override
- public int hashCode()
- {
- int hash = 17;
- hash = hash * 31 + hash( context );
- hash = hash * 31 + hash( verifier );
- hash = hash * 31 + Arrays.hashCode( cipherSuites );
- hash = hash * 31 + Arrays.hashCode( protocols );
- return hash;
- }
-
- private static int hash( Object obj )
- {
- return obj != null ? obj.hashCode() : 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslSocketFactory.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslSocketFactory.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslSocketFactory.java
deleted file mode 100644
index 5189c87..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/SslSocketFactory.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.IOException;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-
-import org.apache.http.conn.ssl.X509HostnameVerifier;
-
-/**
- * Specialized SSL socket factory to more closely resemble the JRE's HttpsClient and respect well-known SSL-related
- * configuration properties.
- *
- * @see <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#Customization">JSSE
- * Reference Guide, Customization</a>
- */
-final class SslSocketFactory
- extends org.apache.http.conn.ssl.SSLSocketFactory
-{
-
- private final String[] cipherSuites;
-
- private final String[] protocols;
-
- public SslSocketFactory( SslConfig config )
- {
- this( getSocketFactory( config.context ), getHostnameVerifier( config.verifier ), config.cipherSuites,
- config.protocols );
- }
-
- private static SSLSocketFactory getSocketFactory( SSLContext context )
- {
- return ( context != null ) ? context.getSocketFactory() : (SSLSocketFactory) SSLSocketFactory.getDefault();
- }
-
- private static X509HostnameVerifier getHostnameVerifier( HostnameVerifier verifier )
- {
- return ( verifier != null ) ? X509HostnameVerifierAdapter.adapt( verifier )
- : org.apache.http.conn.ssl.SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
- }
-
- private SslSocketFactory( SSLSocketFactory socketfactory, X509HostnameVerifier hostnameVerifier,
- String[] cipherSuites, String[] protocols )
- {
- super( socketfactory, hostnameVerifier );
-
- this.cipherSuites = cipherSuites;
- this.protocols = protocols;
- }
-
- @Override
- protected void prepareSocket( SSLSocket socket )
- throws IOException
- {
- super.prepareSocket( socket );
- if ( cipherSuites != null )
- {
- socket.setEnabledCipherSuites( cipherSuites );
- }
- if ( protocols != null )
- {
- socket.setEnabledProtocols( protocols );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/UriUtils.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/UriUtils.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/UriUtils.java
deleted file mode 100644
index 7bc19da..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/UriUtils.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.http.client.utils.URIUtils;
-
-/**
- * Helps to deal with URIs.
- */
-final class UriUtils
-{
-
- public static URI resolve( URI base, URI ref )
- {
- String path = ref.getRawPath();
- if ( path != null && path.length() > 0 )
- {
- path = base.getRawPath();
- if ( path == null || !path.endsWith( "/" ) )
- {
- try
- {
- base = new URI( base.getScheme(), base.getAuthority(), base.getPath() + '/', null, null );
- }
- catch ( URISyntaxException e )
- {
- throw new IllegalStateException( e );
- }
- }
- }
- return URIUtils.resolve( base, ref );
- }
-
- public static List<URI> getDirectories( URI base, URI uri )
- {
- List<URI> dirs = new ArrayList<URI>();
- for ( URI dir = uri.resolve( "." ); !isBase( base, dir ); dir = dir.resolve( ".." ) )
- {
- dirs.add( dir );
- }
- return dirs;
- }
-
- private static boolean isBase( URI base, URI uri )
- {
- String path = uri.getRawPath();
- if ( path == null || "/".equals( path ) )
- {
- return true;
- }
- if ( base != null )
- {
- URI rel = base.relativize( uri );
- if ( rel.getRawPath() == null || rel.getRawPath().length() <= 0 || rel.equals( uri ) )
- {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/X509HostnameVerifierAdapter.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/X509HostnameVerifierAdapter.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/X509HostnameVerifierAdapter.java
deleted file mode 100644
index 007f660..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/X509HostnameVerifierAdapter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.IOException;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-
-import org.apache.http.conn.ssl.X509HostnameVerifier;
-
-/**
- * Makes a standard hostname verifier compatible with Apache HttpClient's API.
- */
-final class X509HostnameVerifierAdapter
- implements X509HostnameVerifier
-{
-
- private final HostnameVerifier verifier;
-
- public static X509HostnameVerifier adapt( HostnameVerifier verifier )
- {
- if ( verifier instanceof X509HostnameVerifier )
- {
- return (X509HostnameVerifier) verifier;
- }
- return new X509HostnameVerifierAdapter( verifier );
- }
-
- private X509HostnameVerifierAdapter( HostnameVerifier verifier )
- {
- this.verifier = verifier;
- }
-
- public boolean verify( String hostname, SSLSession session )
- {
- return verifier.verify( hostname, session );
- }
-
- public void verify( String host, SSLSocket socket )
- throws IOException
- {
- if ( !verify( host, socket.getSession() ) )
- {
- throw new SSLException( "<" + host + "> does not pass hostname verification" );
- }
- }
-
- public void verify( String host, X509Certificate cert )
- throws SSLException
- {
- throw new UnsupportedOperationException();
- }
-
- public void verify( String host, String[] cns, String[] subjectAlts )
- throws SSLException
- {
- throw new UnsupportedOperationException();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/package-info.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/package-info.java b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/package-info.java
deleted file mode 100644
index 828299e..0000000
--- a/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// CHECKSTYLE_OFF: RegexpHeader
-/*
- * 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.
- */
-/**
- * Support for downloads/uploads via the HTTP and HTTPS protocols. The current implementation is backed by
- * <a href="http://hc.apache.org/httpcomponents-client-ga/" target="_blank">Apache HttpClient</a>.
- */
-package org.eclipse.aether.transport.http;
-
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/site/site.xml
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/site/site.xml b/aether-transport-http/src/site/site.xml
deleted file mode 100644
index 3a16bf9..0000000
--- a/aether-transport-http/src/site/site.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-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.
--->
-
-<project xmlns="http://maven.apache.org/DECORATION/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
- <body>
- <menu name="Overview">
- <item name="Introduction" href="index.html"/>
- <item name="JavaDocs" href="apidocs/index.html"/>
- <item name="Source Xref" href="xref/index.html"/>
- <!--item name="FAQ" href="faq.html"/-->
- </menu>
-
- <menu ref="parent"/>
- <menu ref="reports"/>
- </body>
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java
----------------------------------------------------------------------
diff --git a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java
deleted file mode 100644
index 71182b5..0000000
--- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java
+++ /dev/null
@@ -1,626 +0,0 @@
-package org.eclipse.aether.transport.http;
-
-/*
- * 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.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.aether.util.ChecksumUtils;
-import org.eclipse.jetty.http.HttpHeaders;
-import org.eclipse.jetty.http.HttpMethods;
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.server.handler.HandlerList;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
-import org.eclipse.jetty.util.B64Code;
-import org.eclipse.jetty.util.IO;
-import org.eclipse.jetty.util.StringUtil;
-import org.eclipse.jetty.util.URIUtil;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class HttpServer
-{
-
- public static class LogEntry
- {
-
- public final String method;
-
- public final String path;
-
- public final Map<String, String> headers;
-
- public LogEntry( String method, String path, Map<String, String> headers )
- {
- this.method = method;
- this.path = path;
- this.headers = headers;
- }
-
- @Override
- public String toString()
- {
- return method + " " + path;
- }
-
- }
-
- public enum WebDav
- {
- /** DAV header advertised, MKCOL required for missing parent directories */
- REQUIRED,
- /** DAV header advertised, MKCOL supported but not required */
- OPTIONAL
- }
-
- public enum ExpectContinue
- {
- /** reject request with "Expectation Failed" */
- FAIL,
- /** send "Continue" only if request made it past authentication */
- PROPER,
- /** send "Continue" before authentication has been checked */
- BROKEN
- }
-
- public enum ChecksumHeader
- {
- NEXUS
- }
-
- private static final Logger log = LoggerFactory.getLogger( HttpServer.class );
-
- private String serverHeader = "Dummy";
-
- private File repoDir;
-
- private boolean rangeSupport = true;
-
- private WebDav webDav;
-
- private ExpectContinue expectContinue = ExpectContinue.PROPER;
-
- private ChecksumHeader checksumHeader;
-
- private Server server;
-
- private Connector httpConnector;
-
- private Connector httpsConnector;
-
- private String credentialEncoding = StringUtil.__ISO_8859_1;
-
- private String username;
-
- private String password;
-
- private String proxyUsername;
-
- private String proxyPassword;
-
- private List<LogEntry> logEntries = Collections.synchronizedList( new ArrayList<LogEntry>() );
-
- public String getHost()
- {
- return "localhost";
- }
-
- public int getHttpPort()
- {
- return httpConnector != null ? httpConnector.getLocalPort() : -1;
- }
-
- public int getHttpsPort()
- {
- return httpsConnector != null ? httpsConnector.getLocalPort() : -1;
- }
-
- public String getHttpUrl()
- {
- return "http://" + getHost() + ":" + getHttpPort();
- }
-
- public String getHttpsUrl()
- {
- return "https://" + getHost() + ":" + getHttpsPort();
- }
-
- public HttpServer addSslConnector()
- {
- if ( httpsConnector == null )
- {
- SslContextFactory ssl = new SslContextFactory();
- ssl.setKeyStorePath( new File( "src/test/resources/ssl/server-store" ).getAbsolutePath() );
- ssl.setKeyStorePassword( "server-pwd" );
- ssl.setTrustStore( new File( "src/test/resources/ssl/client-store" ).getAbsolutePath() );
- ssl.setTrustStorePassword( "client-pwd" );
- ssl.setNeedClientAuth( true );
- httpsConnector = new SslSelectChannelConnector( ssl );
- if ( server != null )
- {
- server.addConnector( httpsConnector );
- try
- {
- httpsConnector.start();
- }
- catch ( Exception e )
- {
- throw new IllegalStateException( e );
- }
- }
- }
- return this;
- }
-
- public List<LogEntry> getLogEntries()
- {
- return logEntries;
- }
-
- public HttpServer setServer( String server )
- {
- this.serverHeader = server;
- return this;
- }
-
- public HttpServer setRepoDir( File repoDir )
- {
- this.repoDir = repoDir;
- return this;
- }
-
- public HttpServer setRangeSupport( boolean rangeSupport )
- {
- this.rangeSupport = rangeSupport;
- return this;
- }
-
- public HttpServer setWebDav( WebDav webDav )
- {
- this.webDav = webDav;
- return this;
- }
-
- public HttpServer setExpectSupport( ExpectContinue expectContinue )
- {
- this.expectContinue = expectContinue;
- return this;
- }
-
- public HttpServer setChecksumHeader( ChecksumHeader checksumHeader )
- {
- this.checksumHeader = checksumHeader;
- return this;
- }
-
- public HttpServer setCredentialEncoding( String credentialEncoding )
- {
- this.credentialEncoding = ( credentialEncoding != null ) ? credentialEncoding : StringUtil.__ISO_8859_1;
- return this;
- }
-
- public HttpServer setAuthentication( String username, String password )
- {
- this.username = username;
- this.password = password;
- return this;
- }
-
- public HttpServer setProxyAuthentication( String username, String password )
- {
- proxyUsername = username;
- proxyPassword = password;
- return this;
- }
-
- public HttpServer start()
- throws Exception
- {
- if ( server != null )
- {
- return this;
- }
-
- httpConnector = new SelectChannelConnector();
-
- HandlerList handlers = new HandlerList();
- handlers.addHandler( new CommonHandler() );
- handlers.addHandler( new LogHandler() );
- handlers.addHandler( new ProxyAuthHandler() );
- handlers.addHandler( new AuthHandler() );
- handlers.addHandler( new RedirectHandler() );
- handlers.addHandler( new RepoHandler() );
-
- server = new Server();
- server.addConnector( httpConnector );
- if ( httpsConnector != null )
- {
- server.addConnector( httpsConnector );
- }
- server.setHandler( handlers );
- server.start();
-
- return this;
- }
-
- public void stop()
- throws Exception
- {
- if ( server != null )
- {
- server.stop();
- server = null;
- httpConnector = null;
- httpsConnector = null;
- }
- }
-
- private class CommonHandler
- extends AbstractHandler
- {
-
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- response.setHeader( HttpHeaders.SERVER, serverHeader );
- }
-
- }
-
- private class LogHandler
- extends AbstractHandler
- {
-
- @SuppressWarnings( "unchecked" )
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- log.info( "{} {}{}", new Object[] { req.getMethod(), req.getRequestURL(),
- req.getQueryString() != null ? "?" + req.getQueryString() : "" } );
-
- Map<String, String> headers = new TreeMap<String, String>( String.CASE_INSENSITIVE_ORDER );
- for ( Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements(); )
- {
- String name = en.nextElement();
- StringBuilder buffer = new StringBuilder( 128 );
- for ( Enumeration<String> ien = req.getHeaders( name ); ien.hasMoreElements(); )
- {
- if ( buffer.length() > 0 )
- {
- buffer.append( ", " );
- }
- buffer.append( ien.nextElement() );
- }
- headers.put( name, buffer.toString() );
- }
- logEntries.add( new LogEntry( req.getMethod(), req.getPathInfo(), Collections.unmodifiableMap( headers ) ) );
- }
-
- }
-
- private class RepoHandler
- extends AbstractHandler
- {
-
- private final Pattern SIMPLE_RANGE = Pattern.compile( "bytes=([0-9])+-" );
-
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- String path = req.getPathInfo().substring( 1 );
-
- if ( !path.startsWith( "repo/" ) )
- {
- return;
- }
- req.setHandled( true );
-
- if ( ExpectContinue.FAIL.equals( expectContinue ) && request.getHeader( HttpHeaders.EXPECT ) != null )
- {
- response.setStatus( HttpServletResponse.SC_EXPECTATION_FAILED );
- return;
- }
-
- File file = new File( repoDir, path.substring( 5 ) );
- if ( HttpMethods.GET.equals( req.getMethod() ) || HttpMethods.HEAD.equals( req.getMethod() ) )
- {
- if ( !file.isFile() || path.endsWith( URIUtil.SLASH ) )
- {
- response.setStatus( HttpServletResponse.SC_NOT_FOUND );
- return;
- }
- long ifUnmodifiedSince = request.getDateHeader( HttpHeaders.IF_UNMODIFIED_SINCE );
- if ( ifUnmodifiedSince != -1 && file.lastModified() > ifUnmodifiedSince )
- {
- response.setStatus( HttpServletResponse.SC_PRECONDITION_FAILED );
- return;
- }
- long offset = 0;
- String range = request.getHeader( HttpHeaders.RANGE );
- if ( range != null && rangeSupport )
- {
- Matcher m = SIMPLE_RANGE.matcher( range );
- if ( m.matches() )
- {
- offset = Long.parseLong( m.group( 1 ) );
- if ( offset >= file.length() )
- {
- response.setStatus( HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE );
- return;
- }
- }
- String encoding = request.getHeader( HttpHeaders.ACCEPT_ENCODING );
- if ( ( encoding != null && !"identity".equals( encoding ) ) || ifUnmodifiedSince == -1 )
- {
- response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
- return;
- }
- }
- response.setStatus( ( offset > 0 ) ? HttpServletResponse.SC_PARTIAL_CONTENT : HttpServletResponse.SC_OK );
- response.setDateHeader( HttpHeaders.LAST_MODIFIED, file.lastModified() );
- response.setHeader( HttpHeaders.CONTENT_LENGTH, Long.toString( file.length() - offset ) );
- if ( offset > 0 )
- {
- response.setHeader( HttpHeaders.CONTENT_RANGE, "bytes " + offset + "-" + ( file.length() - 1 )
- + "/" + file.length() );
- }
- if ( checksumHeader != null )
- {
- Map<String, Object> checksums = ChecksumUtils.calc( file, Collections.singleton( "SHA-1" ) );
- switch ( checksumHeader )
- {
- case NEXUS:
- response.setHeader( HttpHeaders.ETAG, "{SHA1{" + checksums.get( "SHA-1" ) + "}}" );
- break;
- }
- }
- if ( HttpMethods.HEAD.equals( req.getMethod() ) )
- {
- return;
- }
- FileInputStream is = new FileInputStream( file );
- try
- {
- if ( offset > 0 )
- {
- long skipped = is.skip( offset );
- while ( skipped < offset && is.read() >= 0 )
- {
- skipped++;
- }
- }
- IO.copy( is, response.getOutputStream() );
- }
- finally
- {
- IO.close( is );
- }
- }
- else if ( HttpMethods.PUT.equals( req.getMethod() ) )
- {
- if ( !WebDav.REQUIRED.equals( webDav ) )
- {
- file.getParentFile().mkdirs();
- }
- if ( file.getParentFile().exists() )
- {
- try
- {
- FileOutputStream os = new FileOutputStream( file );
- try
- {
- IO.copy( request.getInputStream(), os );
- }
- finally
- {
- os.close();
- }
- }
- catch ( IOException e )
- {
- file.delete();
- throw e;
- }
- response.setStatus( HttpServletResponse.SC_NO_CONTENT );
- }
- else
- {
- response.setStatus( HttpServletResponse.SC_FORBIDDEN );
- }
- }
- else if ( HttpMethods.OPTIONS.equals( req.getMethod() ) )
- {
- if ( webDav != null )
- {
- response.setHeader( "DAV", "1,2" );
- }
- response.setHeader( HttpHeaders.ALLOW, "GET, PUT, HEAD, OPTIONS" );
- response.setStatus( HttpServletResponse.SC_OK );
- }
- else if ( webDav != null && "MKCOL".equals( req.getMethod() ) )
- {
- if ( file.exists() )
- {
- response.setStatus( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
- }
- else if ( file.mkdir() )
- {
- response.setStatus( HttpServletResponse.SC_CREATED );
- }
- else
- {
- response.setStatus( HttpServletResponse.SC_CONFLICT );
- }
- }
- else
- {
- response.setStatus( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
- }
- }
-
- }
-
- private class RedirectHandler
- extends AbstractHandler
- {
-
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- String path = req.getPathInfo();
- if ( !path.startsWith( "/redirect/" ) )
- {
- return;
- }
- req.setHandled( true );
- StringBuilder location = new StringBuilder( 128 );
- String scheme = req.getParameter( "scheme" );
- String host = req.getParameter( "host" );
- String port = req.getParameter( "port" );
- location.append( scheme != null ? scheme : req.getScheme() );
- location.append( "://" );
- location.append( host != null ? host : req.getServerName() );
- location.append( ":" );
- if ( port != null )
- {
- location.append( port );
- }
- else if ( "http".equalsIgnoreCase( scheme ) )
- {
- location.append( getHttpPort() );
- }
- else if ( "https".equalsIgnoreCase( scheme ) )
- {
- location.append( getHttpsPort() );
- }
- else
- {
- location.append( req.getServerPort() );
- }
- location.append( "/repo" ).append( path.substring( 9 ) );
- response.setStatus( HttpServletResponse.SC_MOVED_PERMANENTLY );
- response.setHeader( HttpHeaders.LOCATION, location.toString() );
- }
-
- }
-
- private class AuthHandler
- extends AbstractHandler
- {
-
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- if ( ExpectContinue.BROKEN.equals( expectContinue )
- && "100-continue".equalsIgnoreCase( request.getHeader( HttpHeaders.EXPECT ) ) )
- {
- request.getInputStream();
- }
-
- if ( username != null && password != null )
- {
- if ( checkBasicAuth( request.getHeader( HttpHeaders.AUTHORIZATION ), username, password ) )
- {
- return;
- }
- req.setHandled( true );
- response.setHeader( HttpHeaders.WWW_AUTHENTICATE, "basic realm=\"Test-Realm\"" );
- response.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
- }
- }
-
- }
-
- private class ProxyAuthHandler
- extends AbstractHandler
- {
-
- public void handle( String target, Request req, HttpServletRequest request, HttpServletResponse response )
- throws IOException
- {
- if ( proxyUsername != null && proxyPassword != null )
- {
- if ( checkBasicAuth( request.getHeader( HttpHeaders.PROXY_AUTHORIZATION ), proxyUsername, proxyPassword ) )
- {
- return;
- }
- req.setHandled( true );
- response.setHeader( HttpHeaders.PROXY_AUTHENTICATE, "basic realm=\"Test-Realm\"" );
- response.setStatus( HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED );
- }
- }
-
- }
-
- boolean checkBasicAuth( String credentials, String username, String password )
- {
- if ( credentials != null )
- {
- int space = credentials.indexOf( ' ' );
- if ( space > 0 )
- {
- String method = credentials.substring( 0, space );
- if ( "basic".equalsIgnoreCase( method ) )
- {
- credentials = credentials.substring( space + 1 );
- try
- {
- credentials = B64Code.decode( credentials, credentialEncoding );
- }
- catch ( UnsupportedEncodingException e )
- {
- throw new IllegalStateException( e );
- }
- int i = credentials.indexOf( ':' );
- if ( i > 0 )
- {
- String user = credentials.substring( 0, i );
- String pass = credentials.substring( i + 1 );
- if ( username.equals( user ) && password.equals( pass ) )
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
-}