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 java.lang.String PREFIX_HTTP
          the prefix for request properties.
static java.lang.String PROP_DOWNLOAD
          the property name for the download url.
static java.lang.String PROP_SERVICE
          the property name for the servlet url.
static java.lang.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, NOPARAMETER, OBJ_SESSION, TYPE_CALL_ERROR, TYPE_CALL_RESULT, TYPE_CALLBACK_ERROR, TYPE_CALLBACK_RESULT, TYPE_CALLBACKRESULT_RESULT, TYPE_PROPERTY_RESULT
 
Constructor Summary
HttpConnection(ISerializer pSerializer, java.lang.String pServletURL)
          Creates a new instance of HttpConnection.
HttpConnection(java.util.Properties pProperties)
          Creates a new instance of HttpConnection with properties instead of many parameters.
HttpConnection(java.lang.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.
 int getConnectionTimeout()
          Gets the timeout for the connection establishment.
 long getContentLength(RemoteFileHandle pFileHandle)
          Gets the expected content length.
 java.lang.String getDownloadURL()
          Gets the download URL.
 java.io.InputStream getInputStream(ConnectionInfo pConnectionInfo)
          Gets the InputStream for reading the response from the server.
 java.io.OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
          Gets the OutputStream for submitting requests to the server.
 java.lang.String getServletURL()
          Gets the servlet URL to access the remote server.
 java.lang.String getUploadURL()
          Gets the upload URL.
protected  java.lang.Object initCall(ConnectionInfo pConnectionInfo)
          Will be invoked before a call starts.
protected  boolean isReadingMagicByteEnabled()
          Whether this connection should read the magic byte sequence.
protected  java.lang.Throwable prepareAfterRetryException(java.lang.Throwable pThrowable)
          Prepares the final exception after last retry.
protected  java.lang.Throwable prepareException(java.lang.Throwable pThrowable)
          Prepares the given exception if needed.
 java.io.InputStream readContent(RemoteFileHandle pFileHandle)
          Reads the content from the remote server as stream.
protected  void releaseCall(ConnectionInfo pConnectionInfo, java.lang.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(java.lang.String pURL)
          Sets the download URL.
 void setUploadURL(java.lang.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
addCallBackResultListener, addPropertyChangedListener, call, close, createSerializer, fillInStackTrace, finalize, getProperties, getProperty, getRetryCount, getRetryInterval, getSerializer, isAutoEOFEnabled, isCalling, isOpen, isRetryDuringAliveCheck, isRetryDuringClose, isRetryDuringOpen, isWritingMagicByteEnabled, open, openSub, removeCallBackResultListener, 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 java.lang.String PREFIX_HTTP
the prefix for request properties.

See Also:
Constant Field Values

PROP_SERVICE

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

See Also:
Constant Field Values

PROP_DOWNLOAD

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

See Also:
Constant Field Values

PROP_UPLOAD

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

See Also:
Constant Field Values
Constructor Detail

HttpConnection

public HttpConnection(java.util.Properties pProperties)
               throws java.net.MalformedURLException,
                      java.security.NoSuchAlgorithmException,
                      java.security.KeyManagementException,
                      java.lang.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:
java.net.MalformedURLException - if the servlet URL is not valid
java.security.NoSuchAlgorithmException - if the specified protocol is not available in the default provider package or any of the other provider packages that were searched.
java.lang.ClassNotFoundException - if the serializer is defined and could not be created
java.security.KeyManagementException - if ssl operation fails

HttpConnection

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

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

HttpConnection

public HttpConnection(ISerializer pSerializer,
                      java.lang.String pServletURL)
               throws java.net.MalformedURLException,
                      java.security.NoSuchAlgorithmException,
                      java.security.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:
java.net.MalformedURLException - if the servlet URL is not valid
java.security.NoSuchAlgorithmException - if the specified protocol is not available in the default provider package or any of the other provider packages that were searched.
java.security.KeyManagementException - if ssl operation fails
See Also:
AbstractSerializedConnection.AbstractSerializedConnection(ISerializer)
Method Detail

readContent

public java.io.InputStream readContent(RemoteFileHandle pFileHandle)
                                throws java.io.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:
java.io.IOException - if creating content stream failed

getContentLength

public long getContentLength(RemoteFileHandle pFileHandle)
                      throws java.io.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:
java.io.IOException - if getting content length failed

writeContent

public RemoteFileHandle writeContent(IFileHandle pFileHandle)
                              throws java.io.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:
java.io.IOException - if upload failed

getOutputStream

public java.io.OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
                                     throws java.io.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:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream(ConnectionInfo pConnectionInfo)
                                   throws java.io.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:
java.io.IOException

initCall

protected java.lang.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,
                           java.lang.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

prepareException

protected java.lang.Throwable prepareException(java.lang.Throwable pThrowable)
Prepares the given exception if needed. It's possible to change the stack trace or to create a completely new exception.

Overrides:
prepareException in class AbstractSerializedConnection
Parameters:
pThrowable - the original exception
Returns:
the exception to use

prepareAfterRetryException

protected java.lang.Throwable prepareAfterRetryException(java.lang.Throwable pThrowable)
Prepares the final exception after last retry. This methods forwards the exception to AbstractSerializedConnection.prepareException(Throwable).

Overrides:
prepareAfterRetryException in class AbstractSerializedConnection
Parameters:
pThrowable - the original exception
Returns:
the exception to use

getServletURL

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

Returns:
URL to the remote server

setDownloadURL

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

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

getDownloadURL

public java.lang.String getDownloadURL()
Gets the download URL.

Returns:
the URL to the download service

setUploadURL

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

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

getUploadURL

public java.lang.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

getConnectionTimeout

public int getConnectionTimeout()
Gets the timeout for the connection establishment.

Returns:
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.