Class GXConnection
java.lang.Object
org.gcube.common.gxhttp.reference.GXConnection
A remote connection for a
GXHTTPStringRequest.- Author:
- Manuele Simi (ISTI-CNR), Luca Frosini (ISTI-CNR)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringThe address of the remote service.protected StringThe path of the remote service.static final StringThe application/json;charset=UTF-8 content type.static final StringSystem property holding the default connect timeout, in milliseconds (0means infinite).static final intConnect timeout used when "gxhttp.connectTimeout" is not set, in milliseconds.static final intRead timeout used when "gxhttp.readTimeout" is not set, in milliseconds.protected static final org.slf4j.LoggerThe logger.static final StringThe parameter equals.static final StringThe parameter separator.static final StringThe parameter starter.protected StringThe path of the remote service.static final StringThe path separator.static final StringSystem property holding the default read timeout, in milliseconds (0means infinite).static final StringThe UTF-8 charset. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThe body of the request.voidaddBodyAsStream(InputStream bodyAsStream) protected voidAdds a path part to the connection.static intGets the default connect timeout: "gxhttp.connectTimeout" when set, otherwise 30000.static intGets the default read timeout: "gxhttp.readTimeout" when set, otherwise 300000.voidreset()Resets the connection.send(GXConnection.HTTPMETHOD method) Sends the request with the given methodprotected voidSets the agent for the connection.voidsetConnectTimeout(int connectTimeout) Sets the connect timeout of this connection.voidsetPathParameters(String parameters) Sets the path parameters for the connection.voidsetProperty(String name, String value) Adds a property as header.voidsetQueryParameters(String parameters) Sets the query parameters for the connection.voidsetReadTimeout(int readTimeout) Sets the read timeout of this connection.
-
Field Details
-
APPLICATION_JSON_CHARSET_UTF_8
The application/json;charset=UTF-8 content type.- See Also:
-
PATH_SEPARATOR
The path separator.- See Also:
-
PARAM_STARTER
The parameter starter.- See Also:
-
PARAM_EQUALS
The parameter equals.- See Also:
-
PARAM_SEPARATOR
The parameter separator.- See Also:
-
UTF8
The UTF-8 charset.- See Also:
-
logger
protected static final org.slf4j.Logger loggerThe logger. -
CONNECT_TIMEOUT_PROPERTY
System property holding the default connect timeout, in milliseconds (0means infinite).- See Also:
-
READ_TIMEOUT_PROPERTY
System property holding the default read timeout, in milliseconds (0means infinite).- See Also:
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUTConnect timeout used when "gxhttp.connectTimeout" is not set, in milliseconds.- See Also:
-
DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUTRead timeout used when "gxhttp.readTimeout" is not set, in milliseconds.- See Also:
-
address
The address of the remote service. -
path
The path of the remote service. -
agent
The path of the remote service.
-
-
Constructor Details
-
GXConnection
Creates a new connection.- Parameters:
address- the address of the remote service
-
-
Method Details
-
getDefaultConnectTimeout
public static int getDefaultConnectTimeout()Gets the default connect timeout: "gxhttp.connectTimeout" when set, otherwise 30000.- Returns:
- the timeout in milliseconds;
0means infinite
-
getDefaultReadTimeout
public static int getDefaultReadTimeout()Gets the default read timeout: "gxhttp.readTimeout" when set, otherwise 300000.- Returns:
- the timeout in milliseconds;
0means infinite
-
addPath
Adds a path part to the connection.- Parameters:
pathPart- the path part to add- Throws:
UnsupportedEncodingException- if the encoding is not supported
-
send
Sends the request with the given method- Parameters:
method- the HTTP method- Returns:
- the connection
- Throws:
GXResponseException- if the request was sent but no response status was received: the server may have processed itException- if an error occurs before the request reaches the server
-
setAgent
Sets the agent for the connection.- Parameters:
agent- the agent
-
setPathParameters
Sets the path parameters for the connection.- Parameters:
parameters- the parameters
-
setQueryParameters
Sets the query parameters for the connection.- Parameters:
parameters- the parameters
-
reset
public void reset()Resets the connection. -
addBody
The body of the request.- Parameters:
body- the body
-
addBodyAsStream
- Parameters:
bodyAsStream- the stream to set as input
-
setProperty
Adds a property as header.- Parameters:
name- the name of the propertyvalue- the value of the property
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) Sets the connect timeout of this connection.- Parameters:
connectTimeout- the timeout in milliseconds;0means infinite
-
setReadTimeout
public void setReadTimeout(int readTimeout) Sets the read timeout of this connection.- Parameters:
readTimeout- the timeout in milliseconds;0means infinite
-