Tabnine Logo
Proxy
Code IndexAdd Tabnine to your IDE (free)

How to use
Proxy
in
java.net

Best Java code snippets using java.net.Proxy (Showing top 20 results out of 4,185)

Refine searchRefine arrow

  • InetSocketAddress
  • URL
  • URI
  • ProxySelector
  • Socket
  • URLConnection
origin: stackoverflow.com

 //Proxy instance, proxy ip = 10.0.0.1 with port 8080
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.1", 8080));
conn = new URL(urlString).openConnection(proxy);
origin: stackoverflow.com

 System.setProperty("java.net.useSystemProxies", "true");
System.out.println("detecting proxies");
List l = null;
try {
  l = ProxySelector.getDefault().select(new URI("http://foo/bar"));
} 
catch (URISyntaxException e) {
  e.printStackTrace();
}
if (l != null) {
  for (Iterator iter = l.iterator(); iter.hasNext();) {
    java.net.Proxy proxy = (java.net.Proxy) iter.next();
    System.out.println("proxy type: " + proxy.type());

    InetSocketAddress addr = (InetSocketAddress) proxy.address();

    if (addr == null) {
      System.out.println("No Proxy");
    } else {
      System.out.println("proxy hostname: " + addr.getHostName());
      System.setProperty("http.proxyHost", addr.getHostName());
      System.out.println("proxy port: " + addr.getPort());
      System.setProperty("http.proxyPort", Integer.toString(addr.getPort()));
    }
  }
}
origin: square/okhttp

@Override public boolean equals(@Nullable Object other) {
 return other instanceof Route
   && ((Route) other).address.equals(address)
   && ((Route) other).proxy.equals(proxy)
   && ((Route) other).inetSocketAddress.equals(inetSocketAddress);
}
origin: square/okhttp

 private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException {
  return proxy.type() != Proxy.Type.DIRECT
    ? ((InetSocketAddress) proxy.address()).getAddress()
    : InetAddress.getByName(url.host());
 }
}
origin: SonarSource/sonarqube

@VisibleForTesting
static String getProxySynthesis(URI uri, ProxySelector proxySelector) {
 List<Proxy> proxies = proxySelector.select(uri);
 if (proxies.size() == 1 && proxies.get(0).type().equals(Proxy.Type.DIRECT)) {
  return "no proxy";
 }
 List<String> descriptions = Lists.newArrayList();
 for (Proxy proxy : proxies) {
  if (proxy.type() != Proxy.Type.DIRECT) {
   descriptions.add(proxy.type() + " proxy: " + proxy.address());
  }
 }
 return Joiner.on(", ").join(descriptions);
}
origin: AsyncHttpClient/async-http-client

URI javaUri = uri.toJavaNetURI();
List<Proxy> proxies = proxySelector.select(javaUri);
if (proxies != null) {
  switch (proxy.type()) {
   case HTTP:
    if (!(proxy.address() instanceof InetSocketAddress)) {
     logger.warn("Don't know how to connect to address " + proxy.address());
     return null;
    } else {
     InetSocketAddress address = (InetSocketAddress) proxy.address();
     return proxyServer(address.getHostName(), address.getPort()).build();
    logger.warn("ProxySelector returned proxy type that we don't know how to use: " + proxy.type());
    break;
origin: stackoverflow.com

 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.10.100.100", 80));
HttpURLConnection connection =(HttpURLConnection)new URL("http://abc.abcd.com").openConnection(proxy);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Accept", "text/xml, application/xml");
connection.setRequestMethod("POST");
origin: magefree/mage

  PreferencesDialog.saveValue(KEY_CONNECTION_URL_SERVER_LIST, serverUrl);
URL serverListURL = new URL(serverUrl);
if (p == null || !p.equals(Proxy.NO_PROXY)) {
  try {
    String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
    Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
    p = new Proxy(type, new InetSocketAddress(address, port));
  } catch (Exception ex) {
    throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
  in = new BufferedReader(new InputStreamReader(serverListURL.openConnection(p).getInputStream()));
} catch (SocketTimeoutException | FileNotFoundException | UnknownHostException ex) {
  logger.warn("Could not read serverlist from: " + serverListURL.toString());
  File f = new File("serverlist.txt");
  if (f.exists() && !f.isDirectory()) {
origin: org.apache.poi/poi-ooxml

URL proxyUrl = new URL(signatureConfig.getProxyUrl());
String host = proxyUrl.getHost();
int port = proxyUrl.getPort();
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName(host), (port == -1 ? 80 : port)));
origin: jclouds/legacy-jclouds

@Test
public void testUseProxyForSocketsSettingShouldntAffectHTTP() throws Exception {
 ProxyConfig config = new MyProxyConfig(false, Proxy.Type.HTTP, hostAndPort, creds);
 ProxyForURI proxy = new ProxyForURI(config);
 Field useProxyForSockets = proxy.getClass().getDeclaredField("useProxyForSockets");
 useProxyForSockets.setAccessible(true);
 useProxyForSockets.setBoolean(proxy, false);
 URI uri = new URI("http://example.com/file");
 assertEquals(proxy.apply(uri), new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)));
}
origin: jmxtrans/jmxtrans

this.url = MoreObjects.firstNonNull(
    url,
    new URL(MoreObjects.firstNonNull(
        (String) this.getSettings().get(SETTING_URL),
        DEFAULT_LIBRATO_API_URL)));
this.proxyPort = proxyPort != null ? proxyPort : Settings.getIntegerSetting(getSettings(), SETTING_PROXY_PORT, null);
if (this.proxyHost != null && this.proxyPort != null) {
  this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.proxyHost, this.proxyPort));
} else {
  this.proxy = null;
origin: nutzam/nutz

      Socket socket = null;
      try {
        socket = new Socket();
        socket.connect(proxy.address(), connTime); // 5 * 1000
        OutputStream out = socket.getOutputStream();
        out.write('\n');
        out.flush();
    conn = (HttpURLConnection) request.getUrl().openConnection(proxy);
    conn.setConnectTimeout(connTime);
    conn.setInstanceFollowRedirects(followRedirects);
String host = url.getHost();
conn = (HttpURLConnection) url.openConnection();
if (conn instanceof HttpsURLConnection) {
  HttpsURLConnection httpsc = (HttpsURLConnection)conn;
origin: elastic/elasticsearch-hadoop

public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params)
    throws IOException, UnknownHostException, ConnectTimeoutException {
  InetSocketAddress socksAddr = new InetSocketAddress(socksHost, socksPort);
  Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksAddr);
  int timeout = params.getConnectionTimeout();
  Socket socket = new Socket(proxy);
  socket.setSoTimeout(timeout);
  SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
  SocketAddress remoteaddr = new InetSocketAddress(host, port);
  socket.bind(localaddr);
  socket.connect(remoteaddr, timeout);
  return socket;
}
origin: robovm/robovm

private void connectInternal() throws IOException {
  int port = url.getPort();
  int connectTimeout = getConnectTimeout();
  if (port <= 0) {
    port = FTP_PORT;
  if (currentProxy == null || Proxy.Type.HTTP == currentProxy.type()) {
    controlSocket = new Socket();
  } else {
    controlSocket = new Socket(currentProxy);
  InetSocketAddress addr = new InetSocketAddress(hostName, port);
  controlSocket.connect(addr, connectTimeout);
  connected = true;
  ctrlOutput = controlSocket.getOutputStream();
origin: prestodb/presto

private static TTransport createRaw(HostAndPort address, Optional<SSLContext> sslContext, Optional<HostAndPort> socksProxy, int timeoutMillis)
    throws TTransportException
{
  Proxy proxy = socksProxy
      .map(socksAddress -> new Proxy(SOCKS, InetSocketAddress.createUnresolved(socksAddress.getHost(), socksAddress.getPort())))
      .orElse(Proxy.NO_PROXY);
  Socket socket = new Socket(proxy);
  try {
    socket.connect(new InetSocketAddress(address.getHost(), address.getPort()), timeoutMillis);
    socket.setSoTimeout(timeoutMillis);
    if (sslContext.isPresent()) {
      // SSL will connect to the SOCKS address when present
      HostAndPort sslConnectAddress = socksProxy.orElse(address);
      socket = sslContext.get().getSocketFactory().createSocket(socket, sslConnectAddress.getHost(), sslConnectAddress.getPort(), true);
    }
    return new TSocket(socket);
  }
  catch (Throwable t) {
    // something went wrong, close the socket and rethrow
    try {
      socket.close();
    }
    catch (IOException e) {
      t.addSuppressed(e);
    }
    throw new TTransportException(t);
  }
}
origin: Graylog2/graylog2-server

final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyUri.getHost(), httpProxyUri.getPort()));
final ProxySelector proxySelector = new ProxySelector() {
  @Override
if (!isNullOrEmpty(httpProxyUri.getUserInfo())) {
  final List<String> list = Splitter.on(":")
      .limit(2)
origin: square/okhttp

@Override public Permission getPermission() throws IOException {
 URL url = getURL();
 String hostname = url.getHost();
 int hostPort = url.getPort() != -1
   ? url.getPort()
   : HttpUrl.defaultPort(url.getProtocol());
 if (usingProxy()) {
  InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address();
  hostname = proxyAddress.getHostName();
  hostPort = proxyAddress.getPort();
 }
 return new SocketPermission(hostname + ":" + hostPort, "connect, resolve");
}
origin: foxinmy/weixin4j

  InetSocketAddress address = params != null
      && params.getProxy() != null ? (InetSocketAddress) params
      .getProxy().address() : new InetSocketAddress(
      InetAddress.getByName(uri.getHost()), getPort(uri));
  bootstrap.connect(address).addListener(listener);
  response = future.get();
  throw new HttpClientException("I/O error on "
      + request.getMethod().name() + " request for \""
      + request.getURI().toString(), e);
} catch (InterruptedException e) {
  throw new HttpClientException("Execute error on "
      + request.getMethod().name() + " request for \""
      + request.getURI().toString(), e);
} catch (ExecutionException e) {
  throw new HttpClientException("Execute error on "
origin: javax.mail/com.springsource.javax.mail

  public static Socket getSocket(String host, int port) {
  if (host == null || host.length() == 0)
    return new Socket(Proxy.NO_PROXY);
  else
    return new Socket(new Proxy(Proxy.Type.SOCKS,
        new InetSocketAddress(host, port)));
  }
}
origin: jeremylong/DependencyCheck

if (proxyHost != null && !matchNonProxy(url)) {
  final int proxyPort = settings.getInt(Settings.KEYS.PROXY_PORT);
  final SocketAddress address = new InetSocketAddress(proxyHost, proxyPort);
  final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
  conn = (HttpURLConnection) url.openConnection(proxy);
} else {
  conn = (HttpURLConnection) url.openConnection();
java.netProxy

Javadoc

This class represents proxy server settings. A created instance of Proxy stores a type and an address and is immutable. There are three types of proxies:
  • DIRECT
  • HTTP
  • SOCKS

Most used methods

  • <init>
    Creates a new Proxy instance. SocketAddress must NOT be null when type is either Proxy.Type.HTTP or
  • address
    Gets the address of this Proxy instance.
  • type
    Gets the type of this Proxy instance.
  • equals
    Compares the specified obj to this Proxy instance and returns whether they are equal or not. The giv
  • hashCode
    Gets the hashcode for this Proxy instance.
  • toString
    Gets a textual representation of this Proxy instance. The string includes the two parts type.toStrin
  • setFtpProxy
  • setHttpProxy
  • setProxyAutoconfigUrl
  • setProxyType
  • setSslProxy
  • setSslProxy

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • requestLocationUpdates (LocationManager)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • JFileChooser (javax.swing)
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now