View Javadoc
1   package org.apache.maven.wagon.providers.http;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.wagon.ConnectionException;
23  import org.apache.maven.wagon.authentication.AuthenticationException;
24  import org.apache.maven.wagon.proxy.ProxyInfo;
25  
26  /**
27   * LightweightHttpsWagon, using JDK's HttpURLConnection.
28   *
29   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
30   *
31   * 
32   * @plexus.component role="org.apache.maven.wagon.Wagon" 
33   *   role-hint="https"
34   *   instantiation-strategy="per-lookup"
35   */
36  public class LightweightHttpsWagon
37      extends LightweightHttpWagon
38  {
39      private String previousHttpsProxyHost;
40      
41      private String previousHttpsProxyPort;
42  
43      private String previousHttpsProxyExclusions;
44  
45      public LightweightHttpsWagon()
46      {
47          super();
48      }
49  
50      public void openConnection()
51          throws ConnectionException, AuthenticationException
52      {
53          previousHttpsProxyHost = System.getProperty( "https.proxyHost" );
54          previousHttpsProxyPort = System.getProperty( "https.proxyPort" );
55          previousHttpsProxyExclusions = System.getProperty( "https.nonProxyHosts" );
56          
57          final ProxyInfo proxyInfo = getProxyInfo( "https", getRepository().getHost() );
58          if ( proxyInfo != null )
59          {
60              setSystemProperty( "https.proxyHost", proxyInfo.getHost() );
61              setSystemProperty( "https.proxyPort", String.valueOf( proxyInfo.getPort() ) );
62              setSystemProperty( "https.nonProxyHosts", proxyInfo.getNonProxyHosts() );
63          }
64          else
65          {
66              setSystemProperty( "https.proxyHost", null );
67              setSystemProperty( "https.proxyPort", null );
68          }
69          
70          super.openConnection();
71      }
72  
73      public void closeConnection()
74          throws ConnectionException
75      {
76          super.closeConnection();
77  
78          setSystemProperty( "https.proxyHost", previousHttpsProxyHost );
79          setSystemProperty( "https.proxyPort", previousHttpsProxyPort );
80          setSystemProperty( "https.nonProxyHosts", previousHttpsProxyExclusions );
81      }
82  }