http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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 2e6e8ba..0000000 --- a/aether-transport-http/src/site/site.xml +++ /dev/null @@ -1,37 +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" - name="Transport HTTP"> - <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-resolver/blob/3a1b8ae0/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 8c80bbd..0000000 --- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java +++ /dev/null @@ -1,571 +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 ExpectContinue - { - FAIL, PROPER, BROKEN - } - - public enum ChecksumHeader - { - NEXUS - } - - private static final Logger log = LoggerFactory.getLogger( HttpServer.class ); - - private File repoDir; - - private boolean rangeSupport = true; - - private boolean webDav; - - private ExpectContinue expectContinue = ExpectContinue.PROPER; - - private ChecksumHeader checksumHeader; - - private Server server; - - private Connector httpConnector; - - private Connector httpsConnector; - - 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 ); - server.addConnector( httpsConnector ); - try - { - httpsConnector.start(); - } - catch ( Exception e ) - { - throw new IllegalStateException( e ); - } - } - return this; - } - - public List<LogEntry> getLogEntries() - { - return logEntries; - } - - public HttpServer setRepoDir( File repoDir ) - { - this.repoDir = repoDir; - return this; - } - - public HttpServer setRangeSupport( boolean rangeSupport ) - { - this.rangeSupport = rangeSupport; - return this; - } - - public HttpServer setWebDav( boolean 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 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 LogHandler() ); - handlers.addHandler( new ProxyAuthHandler() ); - handlers.addHandler( new AuthHandler() ); - handlers.addHandler( new RedirectHandler() ); - handlers.addHandler( new RepoHandler() ); - - server = new Server(); - server.addConnector( httpConnector ); - 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 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 ) - { - 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 ) - { - response.setHeader( "DAV", "1,2" ); - } - response.setHeader( HttpHeaders.ALLOW, "GET, PUT, HEAD, OPTIONS" ); - response.setStatus( HttpServletResponse.SC_OK ); - } - else if ( webDav && "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" ); - location.append( scheme != null ? scheme : req.getScheme() ); - location.append( "://" ); - location.append( req.getServerName() ); - location.append( ":" ); - 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 ); - } - } - - } - - static 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, StringUtil.__ISO_8859_1 ); - } - 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; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java ---------------------------------------------------------------------- diff --git a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java deleted file mode 100644 index b1ba731..0000000 --- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java +++ /dev/null @@ -1,1162 +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 static org.junit.Assert.*; - -import java.io.File; -import java.io.FileNotFoundException; -import java.net.ConnectException; -import java.net.ServerSocket; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.http.client.HttpResponseException; -import org.apache.http.conn.ConnectTimeoutException; -import org.apache.http.pool.ConnPoolControl; -import org.apache.http.pool.PoolStats; -import org.eclipse.aether.ConfigurationProperties; -import org.eclipse.aether.DefaultRepositoryCache; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.internal.test.util.TestFileUtils; -import org.eclipse.aether.internal.test.util.TestLoggerFactory; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.RemoteRepository; -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.Transporter; -import org.eclipse.aether.spi.connector.transport.TransporterFactory; -import org.eclipse.aether.transfer.NoTransporterException; -import org.eclipse.aether.transfer.TransferCancelledException; -import org.eclipse.aether.util.repository.AuthenticationBuilder; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -/** - */ -public class HttpTransporterTest -{ - - static - { - System.setProperty( "javax.net.ssl.trustStore", - new File( "src/test/resources/ssl/server-store" ).getAbsolutePath() ); - System.setProperty( "javax.net.ssl.trustStorePassword", "server-pwd" ); - System.setProperty( "javax.net.ssl.keyStore", - new File( "src/test/resources/ssl/client-store" ).getAbsolutePath() ); - System.setProperty( "javax.net.ssl.keyStorePassword", "client-pwd" ); - } - - @Rule - public TestName testName = new TestName(); - - private DefaultRepositorySystemSession session; - - private TransporterFactory factory; - - private Transporter transporter; - - private File repoDir; - - private HttpServer httpServer; - - private Authentication auth; - - private Proxy proxy; - - private RemoteRepository newRepo( String url ) - { - return new RemoteRepository.Builder( "test", "default", url ).setAuthentication( auth ).setProxy( proxy ).build(); - } - - private void newTransporter( String url ) - throws Exception - { - if ( transporter != null ) - { - transporter.close(); - transporter = null; - } - transporter = factory.newInstance( session, newRepo( url ) ); - } - - @Before - public void setUp() - throws Exception - { - System.out.println( "=== " + testName.getMethodName() + " ===" ); - session = TestUtils.newSession(); - factory = new HttpTransporterFactory( new TestLoggerFactory() ); - repoDir = TestFileUtils.createTempDir(); - TestFileUtils.writeString( new File( repoDir, "file.txt" ), "test" ); - TestFileUtils.writeString( new File( repoDir, "dir/file.txt" ), "test" ); - TestFileUtils.writeString( new File( repoDir, "empty.txt" ), "" ); - TestFileUtils.writeString( new File( repoDir, "some space.txt" ), "space" ); - File resumable = new File( repoDir, "resume.txt" ); - TestFileUtils.writeString( resumable, "resumable" ); - resumable.setLastModified( System.currentTimeMillis() - 90 * 1000 ); - httpServer = new HttpServer().setRepoDir( repoDir ).start(); - newTransporter( httpServer.getHttpUrl() ); - } - - @After - public void tearDown() - throws Exception - { - if ( transporter != null ) - { - transporter.close(); - transporter = null; - } - if ( httpServer != null ) - { - httpServer.stop(); - httpServer = null; - } - factory = null; - session = null; - } - - @Test - public void testClassify() - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( new FileNotFoundException() ) ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( new HttpResponseException( 403, "Forbidden" ) ) ); - assertEquals( Transporter.ERROR_NOT_FOUND, transporter.classify( new HttpResponseException( 404, "Not Found" ) ) ); - } - - @Test - public void testPeek() - throws Exception - { - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - } - - @Test - public void testPeek_NotFound() - throws Exception - { - try - { - transporter.peek( new PeekTask( URI.create( "repo/missing.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 404, e.getStatusCode() ); - assertEquals( Transporter.ERROR_NOT_FOUND, transporter.classify( e ) ); - } - } - - @Test - public void testPeek_Closed() - throws Exception - { - transporter.close(); - try - { - transporter.peek( new PeekTask( URI.create( "repo/missing.txt" ) ) ); - fail( "Expected error" ); - } - catch ( IllegalStateException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testPeek_Authenticated() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - } - - @Test - public void testPeek_Unauthenticated() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - try - { - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 401, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testPeek_ProxyAuthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth ); - newTransporter( "http://bad.localhost:1/" ); - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - } - - @Test - public void testPeek_ProxyUnauthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort() ); - newTransporter( "http://bad.localhost:1/" ); - try - { - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 407, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testPeek_SSL() - throws Exception - { - httpServer.addSslConnector(); - newTransporter( httpServer.getHttpsUrl() ); - transporter.peek( new PeekTask( URI.create( "repo/file.txt" ) ) ); - } - - @Test - public void testPeek_Redirect() - throws Exception - { - httpServer.addSslConnector(); - transporter.peek( new PeekTask( URI.create( "redirect/file.txt" ) ) ); - transporter.peek( new PeekTask( URI.create( "redirect/file.txt?scheme=https" ) ) ); - } - - @Test - public void testGet_ToMemory() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_ToFile() - throws Exception - { - File file = TestFileUtils.createTempFile( "failure" ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setDataFile( file ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", TestFileUtils.readString( file ) ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "test", listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_EmptyResource() - throws Exception - { - File file = TestFileUtils.createTempFile( "failure" ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/empty.txt" ) ).setDataFile( file ).setListener( listener ); - transporter.get( task ); - assertEquals( "", TestFileUtils.readString( file ) ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 0, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - assertEquals( "", listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_EncodedResourcePath() - throws Exception - { - GetTask task = new GetTask( URI.create( "repo/some%20space.txt" ) ); - transporter.get( task ); - assertEquals( "space", task.getDataString() ); - } - - @Test - public void testGet_Authenticated() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_Unauthenticated() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 401, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testGet_ProxyAuthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - Authentication auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth ); - newTransporter( "http://bad.localhost:1/" ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_ProxyUnauthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort() ); - newTransporter( "http://bad.localhost:1/" ); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 407, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testGet_SSL() - throws Exception - { - httpServer.addSslConnector(); - newTransporter( httpServer.getHttpsUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_WebDav() - throws Exception - { - httpServer.setWebDav( true ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/dir/file.txt" ) ).setListener( listener ); - ( (HttpTransporter) transporter ).getState().setWebDav( true ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - assertEquals( httpServer.getLogEntries().toString(), 1, httpServer.getLogEntries().size() ); - } - - @Test - public void testGet_Redirect() - throws Exception - { - httpServer.addSslConnector(); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "redirect/file.txt?scheme=https" ) ).setListener( listener ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_Resume() - throws Exception - { - File file = TestFileUtils.createTempFile( "re" ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/resume.txt" ) ).setDataFile( file, true ).setListener( listener ); - transporter.get( task ); - assertEquals( "resumable", TestFileUtils.readString( file ) ); - assertEquals( 1, listener.startedCount ); - assertEquals( 2, listener.dataOffset ); - assertEquals( 9, listener.dataLength ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "sumable", listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_ResumeLocalContentsOutdated() - throws Exception - { - File file = TestFileUtils.createTempFile( "re" ); - file.setLastModified( System.currentTimeMillis() - 5 * 60 * 1000 ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/resume.txt" ) ).setDataFile( file, true ).setListener( listener ); - transporter.get( task ); - assertEquals( "resumable", TestFileUtils.readString( file ) ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 9, listener.dataLength ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "resumable", listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_ResumeRangesNotSupportedByServer() - throws Exception - { - httpServer.setRangeSupport( false ); - File file = TestFileUtils.createTempFile( "re" ); - RecordingTransportListener listener = new RecordingTransportListener(); - GetTask task = new GetTask( URI.create( "repo/resume.txt" ) ).setDataFile( file, true ).setListener( listener ); - transporter.get( task ); - assertEquals( "resumable", TestFileUtils.readString( file ) ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 9, listener.dataLength ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "resumable", listener.baos.toString( "UTF-8" ) ); - } - - @Test - public void testGet_Checksums_Nexus() - throws Exception - { - httpServer.setChecksumHeader( HttpServer.ChecksumHeader.NEXUS ); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", task.getChecksums().get( "SHA-1" ) ); - } - - @Test - public void testGet_FileHandleLeak() - throws Exception - { - for ( int i = 0; i < 100; i++ ) - { - File file = TestFileUtils.createTempFile( "failure" ); - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ).setDataFile( file ) ); - assertTrue( i + ", " + file.getAbsolutePath(), file.delete() ); - } - } - - @Test - public void testGet_NotFound() - throws Exception - { - try - { - transporter.get( new GetTask( URI.create( "repo/missing.txt" ) ) ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 404, e.getStatusCode() ); - assertEquals( Transporter.ERROR_NOT_FOUND, transporter.classify( e ) ); - } - } - - @Test - public void testGet_Closed() - throws Exception - { - transporter.close(); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( IllegalStateException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testGet_StartCancelled() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - listener.cancelStart = true; - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - try - { - transporter.get( task ); - fail( "Expected error" ); - } - catch ( TransferCancelledException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - } - - @Test - public void testGet_ProgressCancelled() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - listener.cancelProgress = true; - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - try - { - transporter.get( task ); - fail( "Expected error" ); - } - catch ( TransferCancelledException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.dataOffset ); - assertEquals( 4, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 1, listener.progressedCount ); - } - - @Test - public void testPut_FromMemory() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_FromFile() - throws Exception - { - File file = TestFileUtils.createTempFile( "upload" ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataFile( file ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_EmptyResource() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 0, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - assertEquals( "", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_EncodedResourcePath() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = - new PutTask( URI.create( "repo/some%20space.txt" ) ).setListener( listener ).setDataString( "OK" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 2, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "OK", TestFileUtils.readString( new File( repoDir, "some space.txt" ) ) ); - } - - @Test - public void testPut_Authenticated_ExpectContinue() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_Authenticated_ExpectContinueBroken() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - httpServer.setExpectSupport( HttpServer.ExpectContinue.BROKEN ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_Authenticated_ExpectContinueRejected() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - httpServer.setExpectSupport( HttpServer.ExpectContinue.FAIL ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_Authenticated_ExpectContinueRejected_ExplicitlyConfiguredHeader() - throws Exception - { - Map<String, String> headers = new HashMap<String, String>(); - headers.put( "Expect", "100-continue" ); - session.setConfigProperty( ConfigurationProperties.HTTP_HEADERS + ".test", headers ); - httpServer.setAuthentication( "testuser", "testpass" ); - httpServer.setExpectSupport( HttpServer.ExpectContinue.FAIL ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_Unauthenticated() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - try - { - transporter.put( task ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 401, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - } - - @Test - public void testPut_ProxyAuthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - Authentication auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth ); - newTransporter( "http://bad.localhost:1/" ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_ProxyUnauthenticated() - throws Exception - { - httpServer.setProxyAuthentication( "testuser", "testpass" ); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort() ); - newTransporter( "http://bad.localhost:1/" ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - try - { - transporter.put( task ); - fail( "Expected error" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 407, e.getStatusCode() ); - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - } - - @Test - public void testPut_SSL() - throws Exception - { - httpServer.addSslConnector(); - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpsUrl() ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "file.txt" ) ) ); - } - - @Test - public void testPut_WebDav() - throws Exception - { - httpServer.setWebDav( true ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = - new PutTask( URI.create( "repo/dir1/dir2/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "upload", TestFileUtils.readString( new File( repoDir, "dir1/dir2/file.txt" ) ) ); - - assertEquals( 5, httpServer.getLogEntries().size() ); - assertEquals( "OPTIONS", httpServer.getLogEntries().get( 0 ).method ); - assertEquals( "MKCOL", httpServer.getLogEntries().get( 1 ).method ); - assertEquals( "/repo/dir1/dir2/", httpServer.getLogEntries().get( 1 ).path ); - assertEquals( "MKCOL", httpServer.getLogEntries().get( 2 ).method ); - assertEquals( "/repo/dir1/", httpServer.getLogEntries().get( 2 ).path ); - assertEquals( "MKCOL", httpServer.getLogEntries().get( 3 ).method ); - assertEquals( "/repo/dir1/dir2/", httpServer.getLogEntries().get( 3 ).path ); - assertEquals( "PUT", httpServer.getLogEntries().get( 4 ).method ); - } - - @Test - public void testPut_FileHandleLeak() - throws Exception - { - for ( int i = 0; i < 100; i++ ) - { - File src = TestFileUtils.createTempFile( "upload" ); - File dst = new File( repoDir, "file.txt" ); - transporter.put( new PutTask( URI.create( "repo/file.txt" ) ).setDataFile( src ) ); - assertTrue( i + ", " + src.getAbsolutePath(), src.delete() ); - assertTrue( i + ", " + dst.getAbsolutePath(), dst.delete() ); - } - } - - @Test - public void testPut_Closed() - throws Exception - { - transporter.close(); - try - { - transporter.put( new PutTask( URI.create( "repo/missing.txt" ) ) ); - fail( "Expected error" ); - } - catch ( IllegalStateException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test - public void testPut_StartCancelled() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - listener.cancelStart = true; - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - try - { - transporter.put( task ); - fail( "Expected error" ); - } - catch ( TransferCancelledException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 0, listener.progressedCount ); - } - - @Test - public void testPut_ProgressCancelled() - throws Exception - { - RecordingTransportListener listener = new RecordingTransportListener(); - listener.cancelProgress = true; - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - try - { - transporter.put( task ); - fail( "Expected error" ); - } - catch ( TransferCancelledException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - assertEquals( 0, listener.dataOffset ); - assertEquals( 6, listener.dataLength ); - assertEquals( 1, listener.startedCount ); - assertEquals( 1, listener.progressedCount ); - } - - @Test - public void testGetPut_AuthCache() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - GetTask get = new GetTask( URI.create( "repo/file.txt" ) ); - transporter.get( get ); - RecordingTransportListener listener = new RecordingTransportListener(); - PutTask task = new PutTask( URI.create( "repo/file.txt" ) ).setListener( listener ).setDataString( "upload" ); - transporter.put( task ); - assertEquals( 1, listener.startedCount ); - } - - @Test( timeout = 10000 ) - public void testConcurrency() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - newTransporter( httpServer.getHttpUrl() ); - final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); - Thread threads[] = new Thread[20]; - for ( int i = 0; i < threads.length; i++ ) - { - final String path = "repo/file.txt?i=" + i; - threads[i] = new Thread() - { - @Override - public void run() - { - try - { - for ( int j = 0; j < 100; j++ ) - { - GetTask task = new GetTask( URI.create( path ) ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - } - } - catch ( Throwable t ) - { - error.compareAndSet( null, t ); - System.err.println( path ); - t.printStackTrace(); - } - } - }; - threads[i].setName( "Task-" + i ); - } - for ( Thread thread : threads ) - { - thread.start(); - } - for ( Thread thread : threads ) - { - thread.join(); - } - assertNull( String.valueOf( error.get() ), error.get() ); - } - - @Test( timeout = 1000 ) - public void testConnectTimeout() - throws Exception - { - session.setConfigProperty( ConfigurationProperties.CONNECT_TIMEOUT, 100 ); - int port = 1; - newTransporter( "http://localhost:" + port ); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( ConnectTimeoutException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - catch ( ConnectException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - - @Test( timeout = 1000 ) - public void testRequestTimeout() - throws Exception - { - session.setConfigProperty( ConfigurationProperties.REQUEST_TIMEOUT, 100 ); - ServerSocket server = new ServerSocket( 0 ); - newTransporter( "http://localhost:" + server.getLocalPort() ); - try - { - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Expected error" ); - } - catch ( SocketTimeoutException e ) - { - assertEquals( Transporter.ERROR_OTHER, transporter.classify( e ) ); - } - } - finally - { - server.close(); - } - } - - @Test - public void testUserAgent() - throws Exception - { - session.setConfigProperty( ConfigurationProperties.USER_AGENT, "SomeTest/1.0" ); - newTransporter( httpServer.getHttpUrl() ); - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - assertEquals( 1, httpServer.getLogEntries().size() ); - for ( HttpServer.LogEntry log : httpServer.getLogEntries() ) - { - assertEquals( "SomeTest/1.0", log.headers.get( "User-Agent" ) ); - } - } - - @Test - public void testCustomHeaders() - throws Exception - { - Map<String, String> headers = new HashMap<String, String>(); - headers.put( "User-Agent", "Custom/1.0" ); - headers.put( "X-CustomHeader", "Custom-Value" ); - session.setConfigProperty( ConfigurationProperties.USER_AGENT, "SomeTest/1.0" ); - session.setConfigProperty( ConfigurationProperties.HTTP_HEADERS + ".test", headers ); - newTransporter( httpServer.getHttpUrl() ); - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - assertEquals( 1, httpServer.getLogEntries().size() ); - for ( HttpServer.LogEntry log : httpServer.getLogEntries() ) - { - for ( Map.Entry<String, String> entry : headers.entrySet() ) - { - assertEquals( entry.getKey(), entry.getValue(), log.headers.get( entry.getKey() ) ); - } - } - } - - @Test - public void testServerAuthScope_NotUsedForProxy() - throws Exception - { - String username = "testuser", password = "testpass"; - httpServer.setProxyAuthentication( username, password ); - auth = new AuthenticationBuilder().addUsername( username ).addPassword( password ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort() ); - newTransporter( "http://" + httpServer.getHost() + ":12/" ); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Server auth must not be used as proxy auth" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 407, e.getStatusCode() ); - } - } - - @Test - public void testProxyAuthScope_NotUsedForServer() - throws Exception - { - String username = "testuser", password = "testpass"; - httpServer.setAuthentication( username, password ); - Authentication auth = new AuthenticationBuilder().addUsername( username ).addPassword( password ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth ); - newTransporter( "http://" + httpServer.getHost() + ":12/" ); - try - { - transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); - fail( "Proxy auth must not be used as server auth" ); - } - catch ( HttpResponseException e ) - { - assertEquals( 401, e.getStatusCode() ); - } - } - - @Test - public void testAuthSchemeReuse() - throws Exception - { - httpServer.setAuthentication( "testuser", "testpass" ); - httpServer.setProxyAuthentication( "proxyuser", "proxypass" ); - session.setCache( new DefaultRepositoryCache() ); - auth = new AuthenticationBuilder().addUsername( "testuser" ).addPassword( "testpass" ).build(); - Authentication auth = new AuthenticationBuilder().addUsername( "proxyuser" ).addPassword( "proxypass" ).build(); - proxy = new Proxy( Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth ); - newTransporter( "http://bad.localhost:1/" ); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 3, httpServer.getLogEntries().size() ); - httpServer.getLogEntries().clear(); - newTransporter( "http://bad.localhost:1/" ); - task = new GetTask( URI.create( "repo/file.txt" ) ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - assertEquals( 1, httpServer.getLogEntries().size() ); - assertNotNull( httpServer.getLogEntries().get( 0 ).headers.get( "Authorization" ) ); - assertNotNull( httpServer.getLogEntries().get( 0 ).headers.get( "Proxy-Authorization" ) ); - } - - @Test - public void testConnectionReuse() - throws Exception - { - httpServer.addSslConnector(); - session.setCache( new DefaultRepositoryCache() ); - for ( int i = 0; i < 3; i++ ) - { - newTransporter( httpServer.getHttpsUrl() ); - GetTask task = new GetTask( URI.create( "repo/file.txt" ) ); - transporter.get( task ); - assertEquals( "test", task.getDataString() ); - } - PoolStats stats = - ( (ConnPoolControl<?>) ( (HttpTransporter) transporter ).getState().getConnectionManager() ).getTotalStats(); - assertEquals( stats.toString(), 1, stats.getAvailable() ); - } - - @Test( expected = NoTransporterException.class ) - public void testInit_BadProtocol() - throws Exception - { - newTransporter( "bad:/void" ); - } - - @Test( expected = NoTransporterException.class ) - public void testInit_BadUrl() - throws Exception - { - newTransporter( "http://localhost:NaN" ); - } - - @Test - public void testInit_CaseInsensitiveProtocol() - throws Exception - { - newTransporter( "http://localhost" ); - newTransporter( "HTTP://localhost" ); - newTransporter( "Http://localhost" ); - newTransporter( "https://localhost" ); - newTransporter( "HTTPS://localhost" ); - newTransporter( "HttpS://localhost" ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/RecordingTransportListener.java ---------------------------------------------------------------------- diff --git a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/RecordingTransportListener.java b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/RecordingTransportListener.java deleted file mode 100644 index d88a320..0000000 --- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/RecordingTransportListener.java +++ /dev/null @@ -1,73 +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.ByteArrayOutputStream; -import java.nio.ByteBuffer; - -import org.eclipse.aether.spi.connector.transport.TransportListener; -import org.eclipse.aether.transfer.TransferCancelledException; - -class RecordingTransportListener - extends TransportListener -{ - - public final ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 ); - - public long dataOffset; - - public long dataLength; - - public int startedCount; - - public int progressedCount; - - public boolean cancelStart; - - public boolean cancelProgress; - - @Override - public void transportStarted( long dataOffset, long dataLength ) - throws TransferCancelledException - { - startedCount++; - progressedCount = 0; - this.dataLength = dataLength; - this.dataOffset = dataOffset; - baos.reset(); - if ( cancelStart ) - { - throw new TransferCancelledException(); - } - } - - @Override - public void transportProgressed( ByteBuffer data ) - throws TransferCancelledException - { - progressedCount++; - baos.write( data.array(), data.arrayOffset() + data.position(), data.remaining() ); - if ( cancelProgress ) - { - throw new TransferCancelledException(); - } - } - -}