001package org.apache.maven.wagon.providers.http;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.wagon.ConnectionException;
023import org.apache.maven.wagon.authentication.AuthenticationException;
024import org.apache.maven.wagon.proxy.ProxyInfo;
025
026/**
027 * LightweightHttpsWagon, using JDK's HttpURLConnection.
028 *
029 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
030 *
031 * 
032 * @plexus.component role="org.apache.maven.wagon.Wagon" 
033 *   role-hint="https"
034 *   instantiation-strategy="per-lookup"
035 */
036public class LightweightHttpsWagon
037    extends LightweightHttpWagon
038{
039    private String previousHttpsProxyHost;
040    
041    private String previousHttpsProxyPort;
042
043    private String previousHttpsProxyExclusions;
044
045    public LightweightHttpsWagon()
046    {
047        super();
048    }
049
050    public void openConnection()
051        throws ConnectionException, AuthenticationException
052    {
053        previousHttpsProxyHost = System.getProperty( "https.proxyHost" );
054        previousHttpsProxyPort = System.getProperty( "https.proxyPort" );
055        previousHttpsProxyExclusions = System.getProperty( "https.nonProxyHosts" );
056        
057        final ProxyInfo proxyInfo = getProxyInfo( "https", getRepository().getHost() );
058        if ( proxyInfo != null )
059        {
060            setSystemProperty( "https.proxyHost", proxyInfo.getHost() );
061            setSystemProperty( "https.proxyPort", String.valueOf( proxyInfo.getPort() ) );
062            setSystemProperty( "https.nonProxyHosts", proxyInfo.getNonProxyHosts() );
063        }
064        else
065        {
066            setSystemProperty( "https.proxyHost", null );
067            setSystemProperty( "https.proxyPort", null );
068        }
069        
070        super.openConnection();
071    }
072
073    public void closeConnection()
074        throws ConnectionException
075    {
076        super.closeConnection();
077
078        setSystemProperty( "https.proxyHost", previousHttpsProxyHost );
079        setSystemProperty( "https.proxyPort", previousHttpsProxyPort );
080        setSystemProperty( "https.nonProxyHosts", previousHttpsProxyExclusions );
081    }
082}