Package org.hcjf.io.net.http
Class HttpClient
- java.lang.Object
-
- org.hcjf.io.net.NetServiceConsumer<S,D>
-
- org.hcjf.io.net.NetClient<HttpSession,HttpPackage>
-
- org.hcjf.io.net.http.HttpClient
-
- All Implemented Interfaces:
ServiceConsumer
public class HttpClient extends NetClient<HttpSession,HttpPackage>
Client to invoke some http server.- Author:
- javaito
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hcjf.io.net.NetServiceConsumer
NetServiceConsumer.DecoupledAction
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHTTP_CLIENT_LOG_TAG
-
Constructor Summary
Constructors Constructor Description HttpClient(java.net.URL url)
-
Method Summary
Modifier and Type Method Description voidaddHttpHeader(java.lang.String header)Add header to request.voidaddHttpHeader(HttpHeader header)Add header to request.voidaddPath(java.lang.String... paths)Add path over base context of the constructor URI.HttpSessioncheckSession(HttpSession session, HttpPackage payLoad, NetPackage netPackage)Check the channel session.protected HttpPackagedecode(NetPackage netPackage)This method decode the net package to obtain the implementation datavoiddestroySession(NetSession session)Destroy the session.protected byte[]encode(HttpPackage payLoad)This method decode the implementation data.java.lang.LonggetConnectTimeout()Return the connection timeout value.java.lang.LonggetReadTimeout()Return the read timeout value.HttpSessiongetSession()This method return the object that represent the client's session.protected javax.net.ssl.SSLEnginegetSSLEngine()Creates the SSL engine.java.lang.LonggetWriteTimeout()Return the write timeout value.java.lang.BooleanisHttpsInsecureConnection()Returns if the https connection is insecure or not.protected voidonConnect(HttpSession session, HttpPackage payLoad, NetPackage netPackage)Method that must be implemented by the custom implementation to know when a session is connectedprotected voidonRead(HttpSession session, HttpPackage payLoad, NetPackage netPackage)When the net service receive data, this method is called to process the package.HttpResponserequest()This method execute all the steps to do a http request.voidreset()Return all the internal fields to the default values in order to reuse this client.voidsetBody(byte[] body)Set the request body.voidsetConnectTimeout(java.lang.Long connectTimeout)Set the connection timeout value.voidsetHttpMethod(HttpMethod method)Set the http method to request.voidsetHttpsInsecureConnection(java.lang.Boolean httpsInsecureConnection)Set if the https connection is insecure of not.voidsetReadTimeout(java.lang.Long readTimeout)Set the read timeout value.voidsetWriteTimeout(java.lang.Long writeTimeout)Set the write timeout value.-
Methods inherited from class org.hcjf.io.net.NetClient
connect, getHost, onConnectFail
-
Methods inherited from class org.hcjf.io.net.NetServiceConsumer
addDecoupledAction, decoupleIoAction, disconnect, getName, getPort, getProtocol, getService, getShutdownFrame, getShutdownPackage, getSocketOptions, getWriteWaitForTimeout, isDecoupledIoAction, onCheckSessionError, onConnect, onDisconnect, onDisconnect, onRead, onWrite, onWrite, setService, setWriteWaitForTimeout, write, write
-
-
-
-
Field Detail
-
HTTP_CLIENT_LOG_TAG
public static final java.lang.String HTTP_CLIENT_LOG_TAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getConnectTimeout
public final java.lang.Long getConnectTimeout()
Return the connection timeout value.- Returns:
- Connection timeout vaue.
-
setConnectTimeout
public final void setConnectTimeout(java.lang.Long connectTimeout)
Set the connection timeout value.- Parameters:
connectTimeout- Connection timeout value.
-
getWriteTimeout
public final java.lang.Long getWriteTimeout()
Return the write timeout value.- Returns:
- Write timeout value.
-
setWriteTimeout
public final void setWriteTimeout(java.lang.Long writeTimeout)
Set the write timeout value.- Parameters:
writeTimeout- Write timeout value.
-
getReadTimeout
public final java.lang.Long getReadTimeout()
Return the read timeout value.- Returns:
- Read timeout value.
-
setReadTimeout
public final void setReadTimeout(java.lang.Long readTimeout)
Set the read timeout value.- Parameters:
readTimeout- Read timeout value.
-
addPath
public void addPath(java.lang.String... paths)
Add path over base context of the constructor URI.- Parameters:
paths- Adding paths.
-
reset
public final void reset()
Return all the internal fields to the default values in order to reuse this client.
-
setBody
public void setBody(byte[] body)
Set the request body.- Parameters:
body- Request body.
-
setHttpMethod
public final void setHttpMethod(HttpMethod method)
Set the http method to request.- Parameters:
method- Http method.
-
addHttpHeader
public final void addHttpHeader(java.lang.String header)
Add header to request.- Parameters:
header- Http header.
-
addHttpHeader
public final void addHttpHeader(HttpHeader header)
Add header to request.- Parameters:
header- Http header.
-
isHttpsInsecureConnection
public java.lang.Boolean isHttpsInsecureConnection()
Returns if the https connection is insecure or not.- Returns:
- Secure https connection
-
setHttpsInsecureConnection
public void setHttpsInsecureConnection(java.lang.Boolean httpsInsecureConnection)
Set if the https connection is insecure of not.- Parameters:
httpsInsecureConnection- Secure https connection.
-
getSSLEngine
protected javax.net.ssl.SSLEngine getSSLEngine()
Creates the SSL engine.- Overrides:
getSSLEnginein classNetServiceConsumer<HttpSession,HttpPackage>- Returns:
- SSL engine instance.
-
getSession
public HttpSession getSession()
This method return the object that represent the client's session.- Specified by:
getSessionin classNetClient<HttpSession,HttpPackage>- Returns:
- Client's session.
-
checkSession
public HttpSession checkSession(HttpSession session, HttpPackage payLoad, NetPackage netPackage)
Description copied from class:NetServiceConsumerCheck the channel session.- Specified by:
checkSessionin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Created session.payLoad- Decoded package.netPackage- Net package.- Returns:
- Updated session.
-
encode
protected byte[] encode(HttpPackage payLoad)
This method decode the implementation data.- Specified by:
encodein classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
payLoad- Implementation data.- Returns:
- Implementation data encoded.
-
decode
protected HttpPackage decode(NetPackage netPackage)
This method decode the net package to obtain the implementation data- Specified by:
decodein classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
netPackage- Net package.- Returns:
- Return the implementation data.
-
destroySession
public void destroySession(NetSession session)
Destroy the session.- Specified by:
destroySessionin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session to be destroyed
-
onConnect
protected void onConnect(HttpSession session, HttpPackage payLoad, NetPackage netPackage)
Description copied from class:NetServiceConsumerMethod that must be implemented by the custom implementation to know when a session is connected- Overrides:
onConnectin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Connected session.payLoad- Decoded package payload.netPackage- Original package.
-
onRead
protected final void onRead(HttpSession session, HttpPackage payLoad, NetPackage netPackage)
Description copied from class:NetServiceConsumerWhen the net service receive data, this method is called to process the package.- Overrides:
onReadin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session.payLoad- Net package decodednetPackage- Net package.
-
request
public final HttpResponse request()
This method execute all the steps to do a http request. Creates the connection, sends the request package and reads the response, then this response is returned as a method response.- Returns:
- Http response package.
-
-