Skip to content

Commit 653f7b0

Browse files
committed
Add egressSites filter for proxySitesCache Save
1 parent 675bf72 commit 653f7b0

File tree

9 files changed

+40
-20
lines changed

9 files changed

+40
-20
lines changed

cdi-embedder/src/test/java/org/commonjava/maven/galley/embed/TestCDIProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public List<String> getAllowHttpJobTypes()
126126
{
127127
return new ArrayList<>();
128128
}
129+
130+
@Override
131+
public List<String> getEgressSites()
132+
{
133+
return new ArrayList<>();
134+
}
129135
};
130136

131137
@Inject

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<partylineVersion>1.16</partylineVersion>
5555
<pathmappedStorageVersion>2.5</pathmappedStorageVersion>
5656
<weftVersion>1.24</weftVersion>
57-
<jhttpcVersion>1.14</jhttpcVersion>
57+
<jhttpcVersion>1.15-SNAPSHOT</jhttpcVersion>
5858
<infinispanVersion>9.4.7.Final</infinispanVersion>
5959
<weldVersion>3.1.9.Final</weldVersion>
6060
<byteman.version>4.0.20</byteman.version>

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/HttpClientTransport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public DownloadJob createDownloadJob( final ConcreteResource resource, final Tra
122122
{
123123
return new HttpDownload( getUrl( resource ), getHttpLocation( resource.getLocation(), download ), target,
124124
transferSizes, eventMetadata, http, mapper, metricRegistry, metricConfig,
125-
proxySitesCache );
125+
globalProxyConfig.getEgressSites(), proxySitesCache );
126126
}
127127

128128
@Override
@@ -165,7 +165,8 @@ public ListingJob createListingJob( final ConcreteResource resource, final Trans
165165
{
166166
return new HttpListing( getUrl( resource ),
167167
new ConcreteResource( getHttpLocation( resource.getLocation(), listing ),
168-
resource.getPath() ), http, proxySitesCache );
168+
resource.getPath() ), http, globalProxyConfig.getEgressSites(),
169+
proxySitesCache );
169170
}
170171

171172
private HttpLocation getHttpLocation( final Location repository, HttpJobType httpJobType )
@@ -189,7 +190,7 @@ public ExistenceJob createExistenceJob( final ConcreteResource resource, final T
189190
throws TransferException
190191
{
191192
return new HttpExistence( getUrl( resource ), getHttpLocation( resource.getLocation(), existence ), target,
192-
http, mapper, proxySitesCache );
193+
http, mapper, globalProxyConfig.getEgressSites(), proxySitesCache );
193194
}
194195

195196
private String getUrl( final ConcreteResource resource )

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/conf/GlobalProxyConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public interface GlobalProxyConfig
2727
String getUser();
2828

2929
List<String> getAllowHttpJobTypes();
30+
31+
List<String> getEgressSites();
3032
}

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/internal/AbstractHttpJob.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.Arrays;
4949
import java.util.Collection;
5050
import java.util.Collections;
51+
import java.util.List;
5152

5253
import static org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan;
5354

@@ -73,14 +74,18 @@ public abstract class AbstractHttpJob
7374

7475
protected boolean success;
7576

77+
private final List<String> egressSites;
78+
7679
private final ProxySitesCache proxySitesCache;
7780

7881
protected AbstractHttpJob( final String url, final HttpLocation location, final Http http,
79-
ProxySitesCache proxySitesCache, final Integer... successStatuses )
82+
final List<String> egressSites, ProxySitesCache proxySitesCache,
83+
final Integer... successStatuses )
8084
{
8185
this.url = url;
8286
this.location = location;
8387
this.http = http;
88+
this.egressSites = egressSites;
8489
this.proxySitesCache = proxySitesCache;
8590

8691
if ( successStatuses.length < 1 )
@@ -158,7 +163,7 @@ else if ( !doProxy ) // never do with proxy, retry with proxy
158163
{
159164
tries = 1;
160165
doProxy = true;
161-
if ( proxySitesCache != null )
166+
if ( proxySitesCache != null && ( egressSites == null || !egressSites.contains( site ) ) )
162167
{
163168
proxySitesCache.saveProxySite( site );
164169
}

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/internal/HttpDownload.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.IOException;
3939
import java.io.InputStream;
4040
import java.io.OutputStream;
41+
import java.util.List;
4142
import java.util.Map;
4243

4344
import static org.apache.commons.io.IOUtils.closeQuietly;
@@ -68,7 +69,7 @@ public HttpDownload( final String url, final HttpLocation location, final Transf
6869
final Map<Transfer, Long> transferSizes, final EventMetadata eventMetadata, final Http http,
6970
final ObjectMapper mapper )
7071
{
71-
this( url, location, target, transferSizes, eventMetadata, http, mapper, true, null, null, null );
72+
this( url, location, target, transferSizes, eventMetadata, http, mapper, true, null, null, null, null );
7273
}
7374

7475
public HttpDownload( final String url, final HttpLocation location, final Transfer target,
@@ -77,25 +78,27 @@ public HttpDownload( final String url, final HttpLocation location, final Transf
7778
final TransportMetricConfig transportMetricConfig )
7879
{
7980
this( url, location, target, transferSizes, eventMetadata, http, mapper, true, metricRegistry,
80-
transportMetricConfig, null );
81+
transportMetricConfig, null, null );
8182
}
8283

8384
public HttpDownload( final String url, final HttpLocation location, final Transfer target,
8485
final Map<Transfer, Long> transferSizes, final EventMetadata eventMetadata, final Http http,
8586
final ObjectMapper mapper, final MetricRegistry metricRegistry,
86-
final TransportMetricConfig transportMetricConfig, ProxySitesCache proxySitesCache )
87+
final TransportMetricConfig transportMetricConfig, final List<String> egressSites,
88+
ProxySitesCache proxySitesCache )
8789
{
8890
this( url, location, target, transferSizes, eventMetadata, http, mapper, true, metricRegistry,
89-
transportMetricConfig, proxySitesCache );
91+
transportMetricConfig, egressSites, proxySitesCache );
9092
}
9193

9294
public HttpDownload( final String url, final HttpLocation location, final Transfer target,
9395
final Map<Transfer, Long> transferSizes, final EventMetadata eventMetadata, final Http http,
9496
final ObjectMapper mapper, final boolean deleteFilesOnPath,
9597
final MetricRegistry metricRegistry, final TransportMetricConfig transportMetricConfig,
96-
ProxySitesCache proxySitesCache )
98+
final List<String> egressSites, ProxySitesCache proxySitesCache )
9799
{
98-
super( url, location, http, proxySitesCache );
100+
101+
super( url, location, http, egressSites, proxySitesCache );
99102
this.request = new HttpGet( url );
100103
this.target = target;
101104
this.transferSizes = transferSizes;

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/internal/HttpExistence.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.commonjava.maven.galley.transport.htcli.Http;
2525
import org.commonjava.maven.galley.transport.htcli.model.HttpLocation;
2626

27+
import java.util.List;
28+
2729
import static org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan;
2830

2931
public final class HttpExistence
@@ -38,13 +40,13 @@ public final class HttpExistence
3840
public HttpExistence( final String url, final HttpLocation location, final Transfer transfer, final Http http,
3941
final ObjectMapper mapper )
4042
{
41-
this( url, location, transfer, http, mapper, null );
43+
this( url, location, transfer, http, mapper, null, null );
4244
}
4345

4446
public HttpExistence( final String url, final HttpLocation location, final Transfer transfer, final Http http,
45-
final ObjectMapper mapper, ProxySitesCache proxySitesCache )
47+
final ObjectMapper mapper, final List<String> egressSites, ProxySitesCache proxySitesCache )
4648
{
47-
super( url, location, http, proxySitesCache );
49+
super( url, location, http, egressSites, proxySitesCache );
4850
this.transfer = transfer;
4951
this.mapper = mapper;
5052
}

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/internal/HttpListing.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.nio.charset.Charset;
3838
import java.util.ArrayList;
3939
import java.util.HashSet;
40+
import java.util.List;
4041
import java.util.Set;
4142

4243
import static org.apache.commons.io.IOUtils.closeQuietly;
@@ -60,13 +61,13 @@ public class HttpListing
6061

6162
public HttpListing( final String url, final ConcreteResource resource, final Http http )
6263
{
63-
this( url, resource, http, null );
64+
this( url, resource, http, null, null );
6465
}
6566

6667
public HttpListing( final String url, final ConcreteResource resource, final Http http,
67-
ProxySitesCache proxySitesCache )
68+
final List<String> egressSites, ProxySitesCache proxySitesCache )
6869
{
69-
super( url, (HttpLocation) resource.getLocation(), http, proxySitesCache );
70+
super( url, (HttpLocation) resource.getLocation(), http, egressSites, proxySitesCache );
7071
this.resource = resource;
7172
}
7273

transports/httpclient/src/main/java/org/commonjava/maven/galley/transport/htcli/internal/HttpPublish.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import org.apache.http.entity.ContentType;
2121
import org.apache.http.entity.InputStreamEntity;
2222
import org.commonjava.maven.galley.TransferException;
23-
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache;
2423
import org.commonjava.maven.galley.spi.transport.PublishJob;
2524
import org.commonjava.maven.galley.transport.htcli.Http;
2625
import org.commonjava.maven.galley.transport.htcli.model.HttpLocation;
2726
import org.commonjava.maven.galley.util.ContentTypeUtils;
2827

2928
import java.io.InputStream;
29+
import java.util.ArrayList;
3030

3131
import static org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan;
3232

@@ -46,7 +46,7 @@ public final class HttpPublish
4646
public HttpPublish( final String url, final HttpLocation location, final InputStream stream, final long length,
4747
final String contentType, final Http http )
4848
{
49-
super( url, location, http, null, HttpStatus.SC_OK, HttpStatus.SC_CREATED );
49+
super( url, location, http, null, null, HttpStatus.SC_OK, HttpStatus.SC_CREATED );
5050
this.stream = stream;
5151
this.length = length;
5252
this.contentType = contentType == null ? ContentTypeUtils.detectContent( url ) : contentType;

0 commit comments

Comments
 (0)