Ich habe Anforderung, HTTPs Aufrufe einer bestimmten URL über Proxy und Ruhe direkt übergeben. Ich habe meine eigene benutzerdefinierte Proxy-Implementierung mit ProxySelector von java.net geschrieben. Es funktioniert gut für HTTP-Aufrufe (Ich sehe in Proxy-Zugriffsprotokolle in diesem Fall), aber im Falle von HTTPS-Aufrufe scheint es, dass es nicht Proxy verwendet. Am ich etwas hier fehlt. Der Proxy-Server ist ordnungsgemäß konfiguriert und sein Zugriffsprotokoll wird aktualisiert, wenn einige HTTPS-Aufrufe vom Browser mit Proxy übergeben werden.Verwenden von Proxy für bestimmte HTTPS-Anfrage in Java
package com.blabla.proxy;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.vuclip.pubsub.logging.PubSubUtil;
import com.vuclip.pubsub.logging.client.GooglePubSubClient;
public class CustomProxySelector extends ProxySelector {
private static final Logger LOGGER = LogManager.getLogger(PubSubUtil.class);
private final ProxySelector def;
private final String PUB_SUB_URL = "pubsub.googleapis.com";
List<Proxy> proxyList = new ArrayList<Proxy>();
private Proxy proxy=null;
public CustomProxySelector(ProxySelector aDefault) {
this.def = aDefault;
}
@Override
public void connectFailed(URI arg0, SocketAddress soc, IOException ex) {
LOGGER.error("Error in connecting to proxcy "+soc +" for pubsub :"+ ex);
}
@Override
public List<Proxy> select(URI uri) {
if ("https".equalsIgnoreCase(uri.getScheme()) && uri.getHost().startsWith(PUB_SUB_URL)
&& GooglePubSubClient.isProxyEnabled()) {
synchronized (this) {
if (proxy == null) {
proxy = new Proxy(Proxy.Type.SOCKS,
new InetSocketAddress(GooglePubSubClient.getProxyHost(), GooglePubSubClient.getProxyPort()));
}
}
proxyList.add(proxy);
LOGGER.debug("ProxyList:" + proxyList);
return proxyList;
}
proxyList = def.select(uri);
LOGGER.debug("Default proxy list : " + proxyList);
return proxyList;
}
}
Sind Sie sicher, dass GooglePubSubClient.isProxyEnabled() true zurückgibt? – StephaneM
Ja. Ich habe im Debug-Modus eingecheckt. Es hat einen wahren Wert. –