org.jcoderz.commons.connector.http
Class HttpConnectionImpl

java.lang.Object
  extended by org.jcoderz.commons.connector.http.HttpConnectionImpl
All Implemented Interfaces:
HttpConnection, HttpConnectionExtended

public final class HttpConnectionImpl
extends Object
implements HttpConnectionExtended

Implementation of the HttpConnectionExtended interface. The implemented methods call the respective methods on the ManagedHttpConnection class.


Constructor Summary
HttpConnectionImpl(HttpManagedConnectionImpl mc)
          Constructor.
 
Method Summary
protected  void associateManagedConnection(HttpManagedConnectionImpl mc)
          Associate a different physical connection to this user-level connection.
 void close()
          Initiates close of the connection handle at the application level.
 void disassociateManagedConnection(boolean closedByManagedConnection)
          Disassociate this connection handle by forgetting to which ManagedConnection we belong.
protected  HttpManagedConnectionImpl getManagedConnection()
          Gets the associated ManagedConnection.
 int getRequiredDelayForRetries()
          Gets the time in milli seconds required if another retry will be performed.
 boolean isRetryRequired()
          Gets the flag indicating that a retry is required if max number of retries is not exceeded.
 byte[] sendAndReceive(byte[] message)
          Send a http message using retries to the peer associated with the connection in use and afterwards receive a response from it.
 void setEventListener(HttpConnectorEventListener listener, ConnectorContext context)
          Sets the listener for http connector events like request send and response received.
 void setRequestResponseHeader(HttpRequestResponseHeader header)
          Sets http request header values used whilst sending the request and http response header validated whilst receiveing the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpConnectionImpl

public HttpConnectionImpl(HttpManagedConnectionImpl mc)
Constructor. Sets the calling ManagedPaymentProtocolConnection object.

Parameters:
mc - the managed connection creating this object
Method Detail

sendAndReceive

public byte[] sendAndReceive(byte[] message)
                      throws ResourceException,
                             ConnectorException
Send a http message using retries to the peer associated with the connection in use and afterwards receive a response from it.

Specified by:
sendAndReceive in interface HttpConnection
Parameters:
message - the request message that have to be send to the peer.
Returns:
byte array containing the received http response from the peer.
Throws:
ResourceException - indicating an error while sending a request and receiving a response detected by the application server
ConnectorException - in case of a failure on transport level whilst sending/receiving the request/response

setRequestResponseHeader

public void setRequestResponseHeader(HttpRequestResponseHeader header)
                              throws ResourceException
Sets http request header values used whilst sending the request and http response header validated whilst receiveing the response.

Specified by:
setRequestResponseHeader in interface HttpConnection
Parameters:
header - contains request header to set and response header to validate
Throws:
ResourceException - in case of appserver failure

setEventListener

public void setEventListener(HttpConnectorEventListener listener,
                             ConnectorContext context)
Sets the listener for http connector events like request send and response received.

Specified by:
setEventListener in interface HttpConnection
Parameters:
listener - the listener providing callback methods used by the connector
context - used whilst callbacks

close

public void close()
Initiates close of the connection handle at the application level. A connection client is required to call this method after the connection is no more in use. The physical connection will be still open afterwards.

Specified by:
close in interface HttpConnection

getManagedConnection

protected HttpManagedConnectionImpl getManagedConnection()
                                                  throws IllegalStateException
Gets the associated ManagedConnection.

Returns:
the HttpManagedConnectionImpl
Throws:
IllegalStateException - - if the managed connection handle is not set

associateManagedConnection

protected void associateManagedConnection(HttpManagedConnectionImpl mc)

Associate a different physical connection to this user-level connection.

Called by the AbstractManagedConnection if transaction boundaries are crossed.

Parameters:
mc - new physical connection instance
Throws:
ResourceException - - like defined in the interface

disassociateManagedConnection

public void disassociateManagedConnection(boolean closedByManagedConnection)
Disassociate this connection handle by forgetting to which ManagedConnection we belong. This connection handle is now invalid.

Parameters:
closedByManagedConnection - flag indicates if this managed connnection is closed by itself

getRequiredDelayForRetries

public int getRequiredDelayForRetries()
Gets the time in milli seconds required if another retry will be performed.

Specified by:
getRequiredDelayForRetries in interface HttpConnectionExtended
Returns:
int the delay to use in HttpConnecionImpl

isRetryRequired

public boolean isRetryRequired()
Gets the flag indicating that a retry is required if max number of retries is not exceeded.

Specified by:
isRetryRequired in interface HttpConnectionExtended
Returns:
boolean if true perform retry - else not


Copyright 2007 The jCoderZ Project.