Jumpi v1.2.0

org.jumpi.impl.connector.midp10.http
Class HttpConnector

java.lang.Object
  |
  +--org.jumpi.impl.connector.midp10.http.HttpConnector
All Implemented Interfaces:
Component, Configurable, Connector, Manageable

public class HttpConnector
extends java.lang.Object
implements Connector

The HttpConnector allows synchronous message sending and receiving via a Midp10 HttpConnection using HTTP-POST. A message format sent and received is a Hashtable of String key-value pairs. Hashtable messages are translated into HTTP-POST requests where the content is UTF-8 encoded plain text, where each key and value are separated by a linefeed ( 0x0a ). The Hashtable values should not contain linefeeds since no linefeed escaping is used. The synchronous response message to the HTTP-POST is expected also to be UTF-8 encoded plain text, where each key and value are separated by a linefeed. The response is converted to a Hashtable and is made availible for the receive call by the Midlet.

The syntax of a HttpDestination is:

<protocolname>://<uri>


Field Summary
protected  Controller controller_
          Parent Controller instance.
protected  Jumpi jumpi_
          The reverse link to the Jumpi instance at the root of the component tree.
protected  java.lang.String name_
          The fully qualified component name.
protected  java.lang.String protocol_
          The protocol part of Url's which are to be handled by the Connector.
protected  Transformer recvTransformer_
          Transformer for messages being received from the network layer.
protected  Transformer sendTransformer_
          Transformer for messages being sent by the Controller.
protected  boolean started_
          Whether the instance has been started.
protected  boolean stopping_
          Whether the instance is shutting down.
protected  java.lang.String url_format_
          The format of Url's which are supported.
protected  java.lang.String url_prefix_
          The protocol suffixed with the protocol separator.
 
Constructor Summary
HttpConnector()
           
 
Method Summary
 void cancelRecv(Envelope env)
          Does nothing.
 void cancelSend(Envelope env)
          Does nothing.
 void configure(java.lang.String name, Properties props)
          Configure the HttpConnector.
 Destination getDestination(java.lang.String url, java.util.Hashtable clientProps)
          Get the Destination corresponding to the Url provided.
static java.lang.String getLineFromBuffer(java.lang.StringBuffer buffer)
          Return and remove a single line from the buffer.
 java.lang.String getName()
          Get the fully qualified name of the instance.
 void manage(Component root, Component parent, java.lang.String operation, java.util.Hashtable parameters)
          Does nothing.
protected  boolean onRecv(Envelope env)
           Receive a message from a HttpDestination.
protected  boolean onSend(Envelope env)
           Send a message to an HttpDestination.
 void recv(Envelope env)
          Perform the recv synchronously.
 void send(Envelope env)
          Perform the send synchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jumpi_

protected Jumpi jumpi_
The reverse link to the Jumpi instance at the root of the component tree.


controller_

protected Controller controller_
Parent Controller instance.


protocol_

protected java.lang.String protocol_
The protocol part of Url's which are to be handled by the Connector.


name_

protected java.lang.String name_
The fully qualified component name.


sendTransformer_

protected Transformer sendTransformer_
Transformer for messages being sent by the Controller.


recvTransformer_

protected Transformer recvTransformer_
Transformer for messages being received from the network layer.


url_prefix_

protected java.lang.String url_prefix_
The protocol suffixed with the protocol separator.


url_format_

protected java.lang.String url_format_
The format of Url's which are supported.


started_

protected boolean started_
Whether the instance has been started.


stopping_

protected boolean stopping_
Whether the instance is shutting down.

Constructor Detail

HttpConnector

public HttpConnector()
Method Detail

configure

public void configure(java.lang.String name,
                      Properties props)
               throws java.lang.Exception
Configure the HttpConnector.

The following configuration attributes are defined:

Specified by:
configure in interface Configurable
Parameters:
name - the fully qualified instance name.
props - the read-only properties to configure the instance with.
Throws:
java.lang.Exception - when configuration is unsuccessful.
java.lang.IllegalArgumentException - if parameters are missing.

manage

public void manage(Component root,
                   Component parent,
                   java.lang.String operation,
                   java.util.Hashtable parameters)
            throws java.lang.Exception
Does nothing.

Specified by:
manage in interface Manageable
Parameters:
root - the Jumpi instance at the root of the component tree.
parent - the immediate parent of the component.
operation - the operation.
parameters - the operation parameters.
Throws:
java.lang.Exception - if any failure to perform management occurs.
java.lang.IllegalArgumentException - if parameters are missing.

getDestination

public Destination getDestination(java.lang.String url,
                                  java.util.Hashtable clientProps)
Get the Destination corresponding to the Url provided.

Specified by:
getDestination in interface Connector
Parameters:
url - the Url of a JMS Topic or Queue.
clientProps - not used.
Returns:
a Destination if the Url corresponds to a valid JMS Destination, otherwise null.
Throws:
java.lang.IllegalArgumentException - when url is null.

onSend

protected boolean onSend(Envelope env)
                  throws java.lang.Exception

Send a message to an HttpDestination. A HttpConnection is established for each message sent. The message data is POSTed as line separated plain text to the HttpDestination's URL. The message response is received synchronously after the send, although a Jumpi client application must use recv() to get the response which is buffered. The buffered response is overwritten on each send() and cleared on recv().

The message format expected is a Hashtable of String key-value pairs. The values should not contain linefeeds, since linefeeds are used in the line encoding of the HTTP POST data, to separate keys and values. If a send transformer is used, the transformation must result in a Hashtable.

Allows only one send/recv operation at a time regardless of Destination. A send operation must be followed by a receive operation to the same Destination in order to pickup the synchronous response.

The Mipd10 HttpConnection establishment and POST request and response are synchronous, blocking as long as connection establishment is underway and waiting on the response.

Parameters:
env - the Envelope containing the Destination to send to and the message.
Returns:
true on success, else false on managed failure.
Throws:
java.lang.Exception - if a failure condition occurs.

send

public void send(Envelope env)
          throws java.lang.Exception
Perform the send synchronously.

Specified by:
send in interface Connector
Parameters:
env - the Envelope which gives the Destination to send to and the message itself.
Throws:
java.lang.Exception - if any failure condition occurs during the send method.
java.lang.IllegalArgumentException - when env is null.
java.lang.IllegalStateException - when not started or stopping.
See Also:
Controller.callbackSend(org.jumpi.spi.Envelope, boolean, java.lang.String)

cancelSend

public void cancelSend(Envelope env)
Does nothing.

Specified by:
cancelSend in interface Connector
Parameters:
env - the send operation's Envelope to cancel.
See Also:
Controller.cancelSend(org.jumpi.spi.Destination, org.jumpi.spi.Handle)

onRecv

protected boolean onRecv(Envelope env)
                  throws java.lang.Exception

Receive a message from a HttpDestination. The synchronous response from a send() operation is retrieved. The HttpDestination must match the previous send() operation's HttpDestination in order to return a valid response.

The receive operation delivers a Hashtable of String key-value pairs to the caller. The HTTP POST response is assumed to be UTF-8 encoded plain text, where each line pair represents a key-value pair.

Only a single send/recv operation pair can be performed concurrently.

The receive operation is simply picking up a response which has already been read as part of the send operation, so it is non blocking.

Parameters:
env - the Envelope containing the Destination to receive from.
Returns:
true on success, or false on a managed failure, i.e. read timeout.
Throws:
java.lang.Exception - if a failure condition occurs.

getLineFromBuffer

public static java.lang.String getLineFromBuffer(java.lang.StringBuffer buffer)
Return and remove a single line from the buffer.

Parameters:
buffer - the string buffer.
Returns:
a single line from the buffer and removes it from the buffer.

recv

public void recv(Envelope env)
          throws java.lang.Exception
Perform the recv synchronously.

Specified by:
recv in interface Connector
Parameters:
env - the Envelope which gives the Destination to receive from and where the received message is eventually placed with the sender.
Throws:
java.lang.Exception - if any failure condition occurs during the recv method.
java.lang.IllegalArgumentException - when env is null.
java.lang.IllegalStateException - when not started or stopping.
See Also:
Controller.callbackRecv(org.jumpi.spi.Envelope, boolean, java.lang.String)

cancelRecv

public void cancelRecv(Envelope env)
Does nothing.

Specified by:
cancelRecv in interface Connector
Parameters:
env - the recv operation's Envelope to cancel.
See Also:
Controller.cancelRecv(org.jumpi.spi.Destination, org.jumpi.spi.Handle)

getName

public java.lang.String getName()
Get the fully qualified name of the instance. Identical to the name used in configure.

Specified by:
getName in interface Configurable
Returns:
the fully qualified name of the instance.
See Also:
configure(java.lang.String, org.jumpi.spi.Properties)

Jumpi v1.2.0

Copyright 2003, Peter Jonathan Klauser.