com.gridsystems.innergrid.api
Class WrapperConnection

java.lang.Object
  extended by com.gridsystems.innergrid.api.WrapperConnection
All Implemented Interfaces:
Connection

public class WrapperConnection
extends java.lang.Object
implements Connection

Connection implementation that wraps another connection, optionally changing one of its fields.

Author:
Rodrigo Ruiz

Field Summary
 
Fields inherited from interface com.gridsystems.innergrid.api.Connection
DEFAULT_TIMEOUT, DIME, MIME, MTOM
 
Constructor Summary
WrapperConnection(Connection con, Credentials cred)
          Creates a new wrapper that will use alternative credentials.
WrapperConnection(Connection con, java.lang.String h, int p, boolean secure)
          Creates a wrapper around the specified connection, and changes the URL.
 
Method Summary
 void checkConnection()
          Checks that the connection is directed to an open port with the proper protocol.
 void close()
          Disposes the object and releases kept resources.
 java.lang.String getAttachmentFormat()
          Gets the attachment format (DIME, MIME or MTOM).
 java.lang.String getContextPath()
          Gets the connection context path.
 Credentials getCredentials()
          Gets the credentials for the connection.
 java.lang.String getHost()
          Gets the Host to connect to.
 int getPort()
          Gets the port to connect to.
 int getTimeout()
          Gets the connection timeout.
 java.net.URL getUrl(java.lang.String apiName)
          Gets a target URL to the SOAP service for the specified API (Internal use only).
 boolean isChunkedTransferEnabled()
          Gets the value of the chunked transfer control flag.
 boolean isKeepAliveEnabled()
          Gets the keep-alive control flag value.
 boolean isSecured()
          Checks if the connection is done through SSL.
 void manageException(KernelException ke, int retry)
          Manages exceptions (Internal use only).
 void setAttachmentFormat(java.lang.String format)
          Sets the attachment format (DIME, MIME or MTOM).
 void setChunkedTransferEnabled(boolean enabled)
          Enables or disables chunked transfer encoding (it is enabled by default).
 void setKeepAliveEnabled(boolean enabled)
          Sets the keep-alive control flag value.
 void setTimeout(int timeout)
          Sets the connection timeout.
 void success()
          Notifies to the Connection instance that the target API has been reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrapperConnection

public WrapperConnection(Connection con,
                         java.lang.String h,
                         int p,
                         boolean secure)
                  throws KernelException
Creates a wrapper around the specified connection, and changes the URL.

Parameters:
con - the connection to wrap
h - a string with the remote Server host name or address of the wrapper
p - the remote Server port of the wrapper
secure - a boolean set to true if a secure protocol(HTTPS) must be used; false otherwise
Throws:
KernelException - CLT011 if the connection is null
KernelException - CLT012 if the URL is null

WrapperConnection

public WrapperConnection(Connection con,
                         Credentials cred)
                  throws KernelException
Creates a new wrapper that will use alternative credentials.

Parameters:
con - a connection to wrap
cred - credentials to use
Throws:
KernelException - CLT011 if the connection is null
Method Detail

getHost

public java.lang.String getHost()
Gets the Host to connect to.

Specified by:
getHost in interface Connection
Returns:
a string with the host to connect to

getPort

public int getPort()
Gets the port to connect to.

Specified by:
getPort in interface Connection
Returns:
the port to connect to

isSecured

public boolean isSecured()
Checks if the connection is done through SSL.

Specified by:
isSecured in interface Connection
Returns:
a boolean set to true if this connection uses SSL.

getAttachmentFormat

public java.lang.String getAttachmentFormat()
Gets the attachment format (DIME, MIME or MTOM).

Specified by:
getAttachmentFormat in interface Connection
Returns:
The attachment format to use

getContextPath

public java.lang.String getContextPath()
Gets the connection context path.

By default, Kernel services are located in /kernel/api.

Specified by:
getContextPath in interface Connection
Returns:
The connection base context path

getTimeout

public int getTimeout()
Gets the connection timeout.

Specified by:
getTimeout in interface Connection
Returns:
The connection timeout in milliseconds

isChunkedTransferEnabled

public boolean isChunkedTransferEnabled()
Gets the value of the chunked transfer control flag.

This flag is set to true by default.

Specified by:
isChunkedTransferEnabled in interface Connection
Returns:
The current transfer control flag value

isKeepAliveEnabled

public boolean isKeepAliveEnabled()
Gets the keep-alive control flag value.

Specified by:
isKeepAliveEnabled in interface Connection
Returns:
The current flag value

setAttachmentFormat

public void setAttachmentFormat(java.lang.String format)
Sets the attachment format (DIME, MIME or MTOM). By default, the format is automatically selected through the Service deployment meta-data. By setting this value, the user can override these default values.

Specified by:
setAttachmentFormat in interface Connection
Parameters:
format - The attachment format to use

setChunkedTransferEnabled

public void setChunkedTransferEnabled(boolean enabled)
Enables or disables chunked transfer encoding (it is enabled by default).

This flag must be set to false when connecting to servers that do not support this transfer encoding. In particular, simple servers used by MUSE for event notification require this flag to be disabled.

Embedded servers used during unit tests will usually require this encoding to be disabled too.

Specified by:
setChunkedTransferEnabled in interface Connection
Parameters:
enabled - The new flag value

setKeepAliveEnabled

public void setKeepAliveEnabled(boolean enabled)
Sets the keep-alive control flag value.

Keep-alive is disabled by default for scalability reasons. However, if several calls must be performed in a short time period, enabling it can drastically improve the performance.

Specified by:
setKeepAliveEnabled in interface Connection
Parameters:
enabled - The new flag value

setTimeout

public void setTimeout(int timeout)
Sets the connection timeout. By default, it is 30 seconds.

Specified by:
setTimeout in interface Connection
Parameters:
timeout - The connection timeout in milliseconds

getUrl

public java.net.URL getUrl(java.lang.String apiName)
                    throws KernelException
Gets a target URL to the SOAP service for the specified API (Internal use only).

Specified by:
getUrl in interface Connection
Parameters:
apiName - the name of the API
Returns:
the target URL to apiName
Throws:
KernelException - CLT008 if the resulting URL is invalid

getCredentials

public Credentials getCredentials()
Gets the credentials for the connection.

Specified by:
getCredentials in interface Connection
Returns:
the needed Credentials. They can be null.

manageException

public void manageException(KernelException ke,
                            int retry)
                     throws KernelException
Manages exceptions (Internal use only).

Specified by:
manageException in interface Connection
Parameters:
ke - KernelException captured
retry - number of retries
Throws:
KernelException - the ke exception if it passes along the exception without managing

checkConnection

public void checkConnection()
                     throws KernelException
Checks that the connection is directed to an open port with the proper protocol.

Specified by:
checkConnection in interface Connection
Throws:
KernelException - CLT060 if the port cannot be reached.

close

public void close()
Description copied from interface: Connection
Disposes the object and releases kept resources.

Specified by:
close in interface Connection
See Also:
Connection.close()

success

public void success()
Description copied from interface: Connection
Notifies to the Connection instance that the target API has been reached.

Specified by:
success in interface Connection
See Also:
Connection.success()


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.