Proxy
Stay organized with collections
Save and categorize content based on your preferences.
This class represents a proxy setting, typically a type (http, socks) and
a socket address.
A Proxy
is an immutable object.
Field Summary
public
static
final
Proxy |
NO_PROXY |
A proxy setting that represents a DIRECT connection,
basically telling the protocol handler not to use any proxying. |
Public Constructor Summary
Public Method Summary
SocketAddress
|
address()
Returns the socket address of the proxy, or
null if its a direct connection.
|
final
boolean
|
equals( Object obj)
Compares this object against the specified object.
|
final
int
|
hashCode()
Returns a hashcode for this Proxy.
|
String
|
toString()
Constructs a string representation of this Proxy.
|
Proxy.Type
|
type()
Returns the proxy type.
|
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Fields
public
static
final
Proxy
NO_PROXY
A proxy setting that represents a DIRECT
connection,
basically telling the protocol handler not to use any proxying.
Used, for instance, to create sockets bypassing any other global
proxy settings (like SOCKS):
Socket s = new Socket(Proxy.NO_PROXY);
Public Constructors
Creates an entry representing a PROXY connection.
Certain combinations are illegal. For instance, for types Http, and
Socks, a SocketAddress must be provided.
Use the Proxy.NO_PROXY
constant
for representing a direct connection.
Parameters
type |
the Type of the proxy |
sa |
the SocketAddress for that proxy |
Public Methods
Returns the socket address of the proxy, or
null
if its a direct connection.
Returns
- a
SocketAddress
representing the socket end
point of the proxy
public
final
boolean
equals
(Object obj)
Compares this object against the specified object.
The result is true
if and only if the argument is
not null
and it represents the same proxy as
this object.
Two instances of Proxy
represent the same
address if both the SocketAddresses and type are equal.
Parameters
obj |
the object to compare against. |
Returns
true
if the objects are the same;
false
otherwise.
public
final
int
hashCode
()
Returns a hashcode for this Proxy.
Returns
- a hash code value for this Proxy.
public
String
toString
()
Constructs a string representation of this Proxy.
This String is constructed by calling toString() on its type
and concatenating " @ " and the toString() result from its address
if its type is not DIRECT
.
Returns
- a string representation of this object.
Returns
- a Type representing the proxy type
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eProxy\u003c/code\u003e class represents a proxy setting, typically a type (http, socks) and a socket address, and is immutable.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eProxy.NO_PROXY\u003c/code\u003e represents a direct connection, instructing the protocol handler to bypass proxying.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eProxy\u003c/code\u003e instance is created using a \u003ccode\u003eProxy.Type\u003c/code\u003e and a \u003ccode\u003eSocketAddress\u003c/code\u003e, with specific types requiring a valid address.\u003c/p\u003e\n"],["\u003cp\u003eMethods like \u003ccode\u003eaddress()\u003c/code\u003e, \u003ccode\u003etype()\u003c/code\u003e, \u003ccode\u003eequals()\u003c/code\u003e, \u003ccode\u003ehashCode()\u003c/code\u003e, and \u003ccode\u003etoString()\u003c/code\u003e provide information and functionality related to the proxy settings.\u003c/p\u003e\n"],["\u003cp\u003eDirect connections can be established using \u003ccode\u003eProxy.NO_PROXY\u003c/code\u003e to circumvent global proxy settings.\u003c/p\u003e\n"]]],["The `Proxy` class represents a proxy setting with a type (e.g., HTTP, SOCKS) and a socket address. It's immutable and can be created using its constructor, providing a `Proxy.Type` and `SocketAddress`. Key actions include retrieving the proxy's socket address, checking for equality with another proxy object, generating a hash code, getting a string representation of the object and checking the proxy type. `NO_PROXY` indicates a direct connection without proxying.\n"],null,["# Proxy\n\npublic class **Proxy** extends [Object](../../../reference/java/lang/Object.html) \nThis class represents a proxy setting, typically a type (http, socks) and\na socket address.\nA `Proxy` is an immutable object. \n\n##### See Also\n\n- [ProxySelector](../../../reference/java/net/ProxySelector.html) \n\n### Nested Class Summary\n\n|------|---|---|----------------------------|\n| enum | [Proxy.Type](../../../reference/java/net/Proxy.Type.html) || Represents the proxy type. |\n\n### Field Summary\n\n|---------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|\n| public static final [Proxy](../../../reference/java/net/Proxy.html) | [NO_PROXY](../../../reference/java/net/Proxy.html#NO_PROXY) | A proxy setting that represents a `DIRECT` connection, basically telling the protocol handler not to use any proxying. |\n\n### Public Constructor Summary\n\n|---|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Proxy](../../../reference/java/net/Proxy.html#Proxy(java.net.Proxy.Type,%20java.net.SocketAddress))([Proxy.Type](../../../reference/java/net/Proxy.Type.html) type, [SocketAddress](../../../reference/java/net/SocketAddress.html) sa) Creates an entry representing a PROXY connection. |\n\n### Public Method Summary\n\n|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [SocketAddress](../../../reference/java/net/SocketAddress.html) | [address](../../../reference/java/net/Proxy.html#address())() Returns the socket address of the proxy, or `null` if its a direct connection. |\n| final boolean | [equals](../../../reference/java/net/Proxy.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this object against the specified object. |\n| final int | [hashCode](../../../reference/java/net/Proxy.html#hashCode())() Returns a hashcode for this Proxy. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/net/Proxy.html#toString())() Constructs a string representation of this Proxy. |\n| [Proxy.Type](../../../reference/java/net/Proxy.Type.html) | [type](../../../reference/java/net/Proxy.html#type())() Returns the proxy type. |\n\n### Inherited Method Summary\n\nFrom class [java.lang.Object](../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../reference/java/lang/Object.html) | [clone](../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nFields\n------\n\n#### public static final Proxy\n**NO_PROXY**\n\nA proxy setting that represents a `DIRECT` connection,\nbasically telling the protocol handler not to use any proxying.\nUsed, for instance, to create sockets bypassing any other global\nproxy settings (like SOCKS):\n\n\n`Socket s = new Socket(Proxy.NO_PROXY);`\n\nPublic Constructors\n-------------------\n\n#### public\n**Proxy**\n([Proxy.Type](../../../reference/java/net/Proxy.Type.html) type, [SocketAddress](../../../reference/java/net/SocketAddress.html) sa)\n\nCreates an entry representing a PROXY connection.\nCertain combinations are illegal. For instance, for types Http, and\nSocks, a SocketAddress **must** be provided.\n\n\nUse the `Proxy.NO_PROXY` constant\nfor representing a direct connection. \n\n##### Parameters\n\n| type | the `Type` of the proxy |\n| sa | the `SocketAddress` for that proxy |\n|------|------------------------------------|\n\n##### Throws\n\n| [IllegalArgumentException](../../../reference/java/lang/IllegalArgumentException.html) | when the type and the address are incompatible |\n|----------------------------------------------------------------------------------------|------------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public [SocketAddress](../../../reference/java/net/SocketAddress.html)\n**address**\n()\n\nReturns the socket address of the proxy, or\n`null` if its a direct connection. \n\n##### Returns\n\n- a `SocketAddress` representing the socket end point of the proxy \n\n#### public final boolean\n**equals**\n([Object](../../../reference/java/lang/Object.html) obj)\n\nCompares this object against the specified object.\nThe result is `true` if and only if the argument is\nnot `null` and it represents the same proxy as\nthis object.\n\n\nTwo instances of `Proxy` represent the same\naddress if both the SocketAddresses and type are equal. \n\n##### Parameters\n\n| obj | the object to compare against. |\n|-----|--------------------------------|\n\n##### Returns\n\n- `true` if the objects are the same; `false` otherwise. \n\n##### See Also\n\n- [InetSocketAddress.equals(java.lang.Object)](../../../reference/java/net/InetSocketAddress.html#equals(java.lang.Object)) \n\n#### public final int\n**hashCode**\n()\n\nReturns a hashcode for this Proxy. \n\n##### Returns\n\n- a hash code value for this Proxy. \n\n#### public [String](../../../reference/java/lang/String.html)\n**toString**\n()\n\nConstructs a string representation of this Proxy.\nThis String is constructed by calling toString() on its type\nand concatenating \" @ \" and the toString() result from its address\nif its type is not `DIRECT`. \n\n##### Returns\n\n- a string representation of this object. \n\n#### public [Proxy.Type](../../../reference/java/net/Proxy.Type.html)\n**type**\n()\n\nReturns the proxy type. \n\n##### Returns\n\n- a Type representing the proxy type"]]