com.sibvisions.rad.remote.http
Class HttpConnection

java.lang.Object
  extended by com.sibvisions.rad.remote.AbstractSerializedConnection
      extended by com.sibvisions.rad.remote.http.HttpConnection
All Implemented Interfaces:
IDownloadExecutor, IUploadExecutor, IConnection

public class HttpConnection
extends AbstractSerializedConnection
implements IDownloadExecutor, IUploadExecutor

The HttpConnection communicates with the remote server via http protocol.


Field Summary
static String PREFIX_HTTP
          the prefix for request properties.
static String PROP_DOWNLOAD
          the property name for the download url.
static String PROP_SERVICE
          the property name for the servlet url.
static String PROP_UPLOAD
          the property name for the upload url.
 
Fields inherited from class com.sibvisions.rad.remote.AbstractSerializedConnection
PROP_SERIALIZER
 
Fields inherited from interface javax.rad.remote.IConnection
COMPRESSION_BYTES, FLAG_ACKNOWLEDGE, FLAG_BROKEN, FLAG_ESTABLISHED, MET_SESSION_CREATE, MET_SESSION_DESTROY, MET_SESSION_GET_PROPERTIES, MET_SESSION_GET_PROPERTY, MET_SESSION_SET_NEW_PASSWORD, MET_SESSION_SET_PROPERTY, MET_SESSION_SETCHECKALIVE, MET_SESSION_SUBSESSION_CREATE, MODE_COMPRESSED, MODE_UNCOMPRESSED, OBJ_SESSION, TYPE_CALL_ERROR, TYPE_CALL_RESULT, TYPE_CALLBACK_ERROR, TYPE_CALLBACK_RESULT, TYPE_PROPERTY_RESULT
 
Constructor Summary
HttpConnection(ISerializer pSerializer, String pServletURL)
          Creates a new instance of HttpConnection.
HttpConnection(Properties pProperties)
          Creates a new instance of HttpConnection with properties instead of many parameters.
HttpConnection(String pServletURL)
          Creates a new instance of HttpConnection with the default serializer.
 
Method Summary
 RemoteFileHandle createRemoteFileHandle()
          Creates a new "empty" remote file handle prepared for downloading content.
 long getContentLength(RemoteFileHandle pFileHandle)
          Gets the expected content length.
 String getDownloadURL()
          Gets the download URL.
 InputStream getInputStream(ConnectionInfo pConnectionInfo)
          Gets the InputStream for reading the response from the server.
 OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
          Gets the OutputStream for submitting requests to the server.
 String getServletURL()
          Gets the servlet URL to access the remote server.
 String getUploadURL()
          Gets the upload URL.
protected  Object initCall(ConnectionInfo pConnectionInfo)
          Will be invoked before a call starts.
protected  boolean isReadingMagicByteEnabled()
          Whether this connection should read the magic byte sequence.
 InputStream readContent(RemoteFileHandle pFileHandle)
          Reads the content from the remote server as stream.
protected  void releaseCall(ConnectionInfo pConnectionInfo, Object pInit)
          Will be invoked after a call was executed, if AbstractSerializedConnection.initCall(ConnectionInfo) was successfully invoked.
 void setConnectionTimeout(int pTimeout)
          Sets the timeout for the connection establishment.
 void setDownloadURL(String pURL)
          Sets the download URL.
 void setUploadURL(String pURL)
          Sets the upload URL.
 RemoteFileHandle writeContent(IFileHandle pFileHandle)
          Writes the given file handle to a remote server.
 
Methods inherited from class com.sibvisions.rad.remote.AbstractSerializedConnection
addPropertyChangedListener, call, close, createSerializer, finalize, getProperties, getProperty, getRetryCount, getRetryInterval, getSerializer, isAutoEOFEnabled, isCalling, isOpen, isRetryDuringAliveCheck, isRetryDuringClose, isRetryDuringOpen, isWritingMagicByteEnabled, open, openSub, removePropertyChangedListener, setAndCheckAlive, setNewPassword, setProperty, setRetryCount, setRetryDuringAliveCheck, setRetryDuringClose, setRetryDuringOpen, setRetryInterval
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFIX_HTTP

public static final String PREFIX_HTTP
the prefix for request properties.

See Also:
Constant Field Values

PROP_SERVICE

public static final String PROP_SERVICE
the property name for the servlet url.

See Also:
Constant Field Values

PROP_DOWNLOAD

public static final String PROP_DOWNLOAD
the property name for the download url.

See Also:
Constant Field Values

PROP_UPLOAD

public static final String PROP_UPLOAD
the property name for the upload url.

See Also:
Constant Field Values
Constructor Detail

HttpConnection

public HttpConnection(Properties pProperties)
               throws MalformedURLException,
                      NoSuchAlgorithmException,
                      KeyManagementException,
                      ClassNotFoundException
Creates a new instance of HttpConnection with properties instead of many parameters. The supported property keys are:

Parameters:
pProperties - the properties for the connection
Throws:
MalformedURLException - if the servlet URL is not valid
NoSuchAlgorithmException - if the specified protocol is not available in the default provider package or any of the other provider packages that were searched.
ClassNotFoundException - if the serializer is defined and could not be created
KeyManagementException - if ssl operation fails

HttpConnection

public HttpConnection(String pServletURL)
               throws MalformedURLException,
                      NoSuchAlgorithmException,
                      KeyManagementException
Creates a new instance of HttpConnection with the default serializer.

Parameters:
pServletURL - URL to the remote server
Throws:
MalformedURLException - if the servlet URL is not valid
NoSuchAlgorithmException - if the specified protocol is not available in the default provider package or any of the other provider packages that were searched.
KeyManagementException - if ssl operation fails
See Also:
AbstractSerializedConnection.AbstractSerializedConnection(ISerializer)

HttpConnection

public HttpConnection(ISerializer pSerializer,
                      String pServletURL)
               throws MalformedURLException,
                      NoSuchAlgorithmException,
                      KeyManagementException
Creates a new instance of HttpConnection.

Parameters:
pSerializer - the serializer for the communication between client and server
pServletURL - URL to the remote server
Throws:
MalformedURLException - if the servlet URL is not valid
NoSuchAlgorithmException - if the specified protocol is not available in the default provider package or any of the other provider packages that were searched.
KeyManagementException - if ssl operation fails
See Also:
AbstractSerializedConnection.AbstractSerializedConnection(ISerializer)
Method Detail

readContent

public InputStream readContent(RemoteFileHandle pFileHandle)
                        throws IOException
Reads the content from the remote server as stream.

Specified by:
readContent in interface IDownloadExecutor
Parameters:
pFileHandle - the file handle
Returns:
the content stream
Throws:
IOException - if creating content stream failed

getContentLength

public long getContentLength(RemoteFileHandle pFileHandle)
                      throws IOException
Gets the expected content length.

Specified by:
getContentLength in interface IDownloadExecutor
Parameters:
pFileHandle - the file handle
Returns:
the content length, -1 if unknown
Throws:
IOException - if getting content length failed

writeContent

public RemoteFileHandle writeContent(IFileHandle pFileHandle)
                              throws IOException
Writes the given file handle to a remote server.

Specified by:
writeContent in interface IUploadExecutor
Parameters:
pFileHandle - the file handle
Returns:
the RemoteFileHandle
Throws:
IOException - if upload failed

getOutputStream

public OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
                             throws IOException
Gets the OutputStream for submitting requests to the server.

Specified by:
getOutputStream in class AbstractSerializedConnection
Parameters:
pConnectionInfo - the connection information
Returns:
output stream
Throws:
IOException

getInputStream

public InputStream getInputStream(ConnectionInfo pConnectionInfo)
                           throws IOException
Gets the InputStream for reading the response from the server.

Specified by:
getInputStream in class AbstractSerializedConnection
Parameters:
pConnectionInfo - the connection information
Returns:
input stream
Throws:
IOException

initCall

protected Object initCall(ConnectionInfo pConnectionInfo)
Will be invoked before a call starts.

Overrides:
initCall in class AbstractSerializedConnection
Parameters:
pConnectionInfo - the connection info
Returns:
a custom object that will be used as parameter for -AbstractSerializedConnection.releaseCall(ConnectionInfo, Object)

releaseCall

protected void releaseCall(ConnectionInfo pConnectionInfo,
                           Object pInit)
Will be invoked after a call was executed, if AbstractSerializedConnection.initCall(ConnectionInfo) was successfully invoked.

Overrides:
releaseCall in class AbstractSerializedConnection
Parameters:
pConnectionInfo - the connection info
pInit - the object whic was created in AbstractSerializedConnection.initCall(ConnectionInfo)

isReadingMagicByteEnabled

protected boolean isReadingMagicByteEnabled()
Whether this connection should read the magic byte sequence.

Overrides:
isReadingMagicByteEnabled in class AbstractSerializedConnection
Returns:
false because it's not needed for http connections

getServletURL

public String getServletURL()
Gets the servlet URL to access the remote server.

Returns:
URL to the remote server

setDownloadURL

public void setDownloadURL(String pURL)
                    throws MalformedURLException
Sets the download URL.

Parameters:
pURL - the URL to the download service
Throws:
MalformedURLException - if URL isn't valid

getDownloadURL

public String getDownloadURL()
Gets the download URL.

Returns:
the URL to the download service

setUploadURL

public void setUploadURL(String pURL)
                  throws MalformedURLException
Sets the upload URL.

Parameters:
pURL - the URL to the upload service
Throws:
MalformedURLException - if URL isn't valid

getUploadURL

public String getUploadURL()
Gets the upload URL.

Returns:
the URL to the upload service

setConnectionTimeout

public void setConnectionTimeout(int pTimeout)
Sets the timeout for the connection establishment.

Parameters:
pTimeout - the timeout in millis or -1 for the default timeout

createRemoteFileHandle

public RemoteFileHandle createRemoteFileHandle()
Creates a new "empty" remote file handle prepared for downloading content.

Returns:
the file handle


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.