org.jcoderz.commons.connector.http
Class HttpConnectionHelper

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

public final class HttpConnectionHelper
extends Object
implements HttpConnection

Implementation of the HttpConnection interface. This class will be used by the client as connection handle (supports retries).


Constructor Summary
HttpConnectionHelper(HttpConnectionFactory cf, HttpConnectionSpec cs)
          Constructor.
 
Method Summary
 void close()
          Initiates close of the connection handle at the application level.
 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

HttpConnectionHelper

public HttpConnectionHelper(HttpConnectionFactory cf,
                            HttpConnectionSpec cs)
Constructor. Gets the connection spec and the connection factory to establish new connections for retries if necessary.

Parameters:
cf - the connection factory for establishing connections
cs - the connection spec identifying the connection target
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

setEventListener

public void setEventListener(HttpConnectorEventListener listener,
                             ConnectorContext context)
                      throws ResourceException
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
Throws:
ResourceException - if appserver fails performing the call on the managed connection

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

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


Copyright 2007 The jCoderZ Project.