de.fhg.igd.atlas.lsp
Class LSPReply

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.ArrayList
              extended bycodec.asn1.ASN1AbstractCollection
                  extended bycodec.asn1.ASN1Sequence
                      extended byde.fhg.igd.atlas.lsp.LSPReply
All Implemented Interfaces:
ASN1Collection, ASN1Type, Cloneable, Collection, List, RandomAccess, Resolver, Serializable

public class LSPReply
extends ASN1Sequence
implements Resolver

Represents an LSP_Reply structure of the Location Service Protocol (LSP). This class encapsulates a reply of the LSP as message body with additional information about the corresponding message type, the result state and the used protocol version.

The ASN.1 structure of the reply is as follows

 LSP_Reply := SEQUENCE
 {
   version   INTEGER {lspVer1(1)} (lspVer1),
 
   replyType   INTEGER
   {
     stateOnly(0),
     lookup(1)
     refresh(5),
     list(6),
   },
 
   replyState   INTEGER
   {
     -- Success
     acknowledge('0100'H),
     implicitNameNotFound('0101'H),
             
     -- Redirection
     someImplicitNamesNotPresent('0200'H),
             
     -- Client Error
     cookieInvalid('0400'H),
     contactAddressNotExistent('0401'H),
     notAuthorized('0402'H),
     implicitNameNotPresent('0403'H),
             
     -- Server Error
     wrongVersion('0800'H),
     requestTypeInvalid('0801'H),
     encodingNotSupported('0802'H),
     encryptingNotSupported('0803'H),
             
     -- IO Error
     ioError('01000'H),
     internalClientError('1001'H),
     requestBodyInvalid('1002'H),
     encodedDataInvalid('1003'H),
     encryptedDataInvalid('1004'H),
             
     -- Error Flags
     clientErrorFlag('010000'H),
     proxyErrorFlag('020000'H),
     serverErrorFlag('040000'H)
   },
 
   replyBody   ANY DEFINED BY replyType OPTIONAL
 }
 
The Location Service Server (LSServer) respectively the Location Service Proxy (LSProxy) can create an instance of this class by calling the public constructor, encode it by calling getEncoded and send it to the Location Service Client (LSClient) as reply to a corresponding request. The LSClient can decode the reply by calling createReply.

Version:
"$Id: LSPReply.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Jan Peters
See Also:
LSPRequest, LSPLookupResult, LSPRefreshResult, LSPListResult, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.AbstractList
 
Field Summary
static int ACKNOWLEDGE
          Success reply state (see SUCCESS_MASK) for the following case: The corresponding request has been handled successfully.
protected  ASN1Type body_
          The reply body.
static int CLIENT_ERROR_FLAG
          Error flag for the following case: An error has occured on client side.
static int CLIENT_ERROR_MASK
          Mask for all client error codes.
static int CONTACT_ADDRESS_NOT_EXISTENT
          Client error reply state (see CLIENT_ERROR_MASK) for the following case: The contact address of the corresponding LSPRegister request is not existent.
static int COOKIE_INVALID
          Client error reply state (see CLIENT_ERROR_MASK) for the following case: The current cookie of the corresponding LSPRegister request is invalid.
static int ENCODED_DATA_INVALID
          IO error reply state (see IO_ERROR_MASK) for the following case: The content of the corresponding LSPRegisterEncoded request is invalid.
static int ENCODING_NOT_SUPPORTED
          Server error reply state (see SERVER_ERROR_MASK) for the following case: The LSServer respectively the LSProxy, which received the corresponding LSPRegisterEncoded request does not support encoded register requests.
static int ENCRYPTED_DATA_INVALID
          IO error reply state (see IO_ERROR_MASK) for the following case: The content of the corresponding LSPRegisterEncrypted request is invalid.
static int ENCRYPTING_NOT_SUPPORTED
          Server error reply state (see SERVER_ERROR_MASK) for the following case: The LSServer respectively the LSProxy, which received the corresponding LSPRegisterEncrypted request does not support encrypted register requests.
static int ERROR_FLAGS
          Mask for all error flags.
static int IMPLICIT_NAME_NOT_FOUND
          Success reply state (see SUCCESS_MASK) for the following case: The implicit name of the corresponding LSPLookup request has not been found.
static int IMPLICIT_NAME_NOT_PRESENT
          Client error reply state (see CLIENT_ERROR_MASK) for the following case: The implicit name of the corresponding LSPProxyInvalidate or LSPRegister request is not present.
static int INTERNAL_CLIENT_ERROR
          IO error reply state (see IO_ERROR_MASK) for the following case: An internal client error occured.
static int IO_ERROR
          IO error reply state (see IO_ERROR_MASK) for the following case: The request could not be sent due to an IO error.
static int IO_ERROR_MASK
          Mask for all IO error codes.
static int LIST
          Message type for a LSPList reply.
static int LOOKUP
          Message type for a LSPLookup reply.
static int NOT_AUTHORIZED
          Client error reply state (see CLIENT_ERROR_MASK) for the following case: The corresponding LSPList request has not been authorized.
static int PROXY_ERROR_FLAG
          Error flag for the following case: An error has occured on proxy side.
static int REDIRECTION_MASK
          Mask for status codes which indicate that further action needs to be taken by client in order to fulfill the request.
static int REFRESH
          Message type for a LSPRefresh reply.
static int REQUEST_BODY_INVALID
          IO error reply state (see IO_ERROR_MASK) for the following case: The request body of the corresponding request is invalid.
static int REQUEST_TYPE_INVALID
          Server error reply state (see SERVER_ERROR_MASK) for the following case: The request type of the corresponding request is invalid.
static int SERVER_ERROR_FLAG
          Error flag for the following case: An error has occured on server side.
static int SERVER_ERROR_MASK
          Mask for all server error codes.
static int SOME_IMPLICIT_NAMES_NOT_PRESENT
          Redirection reply state (see REDIRECTION_MASK) for the following case: Some of the implicit names of the corresponding LSPRefresh request are not present.
protected  ASN1Integer state_
          The reply state.
protected static int STATE_MASK
          Mask for all status codes.
static int STATE_ONLY
          Message type for a reply wihtout message body.
static int SUCCESS_MASK
          Mask for all status codes corresponding to requests which have been sucessfully received, understood and processed.
protected  ASN1Integer type_
          The reply type.
static int VERSION
          The current version of the Location Service Protocol supported by this class.
protected  ASN1Integer version_
          The version number of this reply.
static int WRONG_VERSION
          Server error reply state (see SERVER_ERROR_MASK) for the following case: The protocol version of the corresponding request has not been accepted.
 
Fields inherited from class codec.asn1.ASN1AbstractCollection
 
Fields inherited from class java.util.ArrayList
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
private LSPReply()
          Creates an instance ready for decoding.
  LSPReply(int type, int state, ASN1Type body)
          Creates an reply instance of the given type with the given body and the given state.
 
Method Summary
 boolean checkClientError()
          Checks the type of the reply state (see CLIENT_ERROR_MASK).
 boolean checkErrorFlags()
          Checks error flags (see ERROR_FLAGS).
 boolean checkIOError()
          Checks the type of the reply state (see IO_ERROR_MASK).
 boolean checkRedirection()
          Checks the type of the reply state (see REDIRECTION_MASK).
 boolean checkServerError()
          Checks the type of the reply state (see SERVER_ERROR_MASK).
 boolean checkSuccess()
          Checks the type of the reply state (see SUCCESS_MASK).
static LSPReply createReply(byte[] code)
          Creates a new reply from the given encoded reply.
static LSPReply createReply(InputStream in, int limit)
          Creates a new reply from the encoded reply, which will be read from the specified input stream.
 ASN1Type getBody()
          Returns the reply body, or null, if the current reply type is STATE_ONLY.
 byte[] getEncoded()
          Returns the DER encoded reply.
 int getErrorFlags()
          Retruns the error flags (see ERROR_FLAGS)
 int getState()
          Returns the reply state.
 String getStateString()
          Returns the string representation of the reply state
 int getType()
          Returns the reply type.
 String getTypeString()
          Returns the string representation of the reply type.
 int getVersion()
          Returns the reply version.
 ASN1Type resolve(ASN1Type caller)
          Returns the supposed ASN1Type of the reply body, corresponding to the current reply type, or null, if the current reply type is STATE_ONLY.
 void setClientErrorFlag(boolean flag)
          Sets the client error flag if flag is true, deletes this flag if flag is false (see CLIENT_ERROR_FLAG).
 void setErrorFlags(int flags)
          Deletes all current error flags and sets the new flags (see ERROR_FLAGS).
 void setProxyErrorFlag(boolean flag)
          Sets the proxy error flag if flag is true, deletes this flag if flag is false (see PROXY_ERROR_FLAG).
 void setServerErrorFlag(boolean flag)
          Sets the server error flag if flag is true, deletes this flag if flag is false (see SERVER_ERROR_FLAG).
 String toString()
          Returns the string representation of this reply.
 
Methods inherited from class codec.asn1.ASN1Sequence
getTag
 
Methods inherited from class codec.asn1.ASN1AbstractCollection
checkConstraints, decode, encode, getCollection, getConstraint, getTagClass, getValue, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Field Detail

VERSION

public static final int VERSION
The current version of the Location Service Protocol supported by this class.

See Also:
Constant Field Values

STATE_ONLY

public static final int STATE_ONLY
Message type for a reply wihtout message body.

See Also:
Constant Field Values

LOOKUP

public static final int LOOKUP
Message type for a LSPLookup reply.

See Also:
Constant Field Values

REFRESH

public static final int REFRESH
Message type for a LSPRefresh reply.

See Also:
Constant Field Values

LIST

public static final int LIST
Message type for a LSPList reply.

See Also:
Constant Field Values

STATE_MASK

protected static final int STATE_MASK
Mask for all status codes.

See Also:
Constant Field Values

SUCCESS_MASK

public static final int SUCCESS_MASK
Mask for all status codes corresponding to requests which have been sucessfully received, understood and processed. (See ACKNOWLEDGE, IMPLICIT_NAME_NOT_FOUND)

See Also:
Constant Field Values

ACKNOWLEDGE

public static final int ACKNOWLEDGE
Success reply state (see SUCCESS_MASK) for the following case: The corresponding request has been handled successfully. (Corresponding HTTP Error Code: 200 - OK (Success))

See Also:
Constant Field Values

IMPLICIT_NAME_NOT_FOUND

public static final int IMPLICIT_NAME_NOT_FOUND
Success reply state (see SUCCESS_MASK) for the following case: The implicit name of the corresponding LSPLookup request has not been found. (Corresponding HTTP Error Code: 404 - Not Found (Client Error))

See Also:
Constant Field Values

REDIRECTION_MASK

public static final int REDIRECTION_MASK
Mask for status codes which indicate that further action needs to be taken by client in order to fulfill the request. (See SOME_IMPLICIT_NAMES_NOT_PRESENT)

See Also:
Constant Field Values

SOME_IMPLICIT_NAMES_NOT_PRESENT

public static final int SOME_IMPLICIT_NAMES_NOT_PRESENT
Redirection reply state (see REDIRECTION_MASK) for the following case: Some of the implicit names of the corresponding LSPRefresh request are not present. (Corresponding HTTP Error Code: 404 - Not Found (Client Error))

See Also:
Constant Field Values

CLIENT_ERROR_MASK

public static final int CLIENT_ERROR_MASK
Mask for all client error codes. The corresponding request has been received and understood, but the client seems to have erred. (See COOKIE_INVALID, CONTACT_ADDRESS_NOT_EXISTENT, NOT_AUTHORIZED, IMPLICIT_NAME_NOT_PRESENT)

See Also:
Constant Field Values

COOKIE_INVALID

public static final int COOKIE_INVALID
Client error reply state (see CLIENT_ERROR_MASK) for the following case: The current cookie of the corresponding LSPRegister request is invalid. (Corresponding HTTP Error Code: 401 - Unauthorized (Client Error))

See Also:
Constant Field Values

CONTACT_ADDRESS_NOT_EXISTENT

public static final int CONTACT_ADDRESS_NOT_EXISTENT
Client error reply state (see CLIENT_ERROR_MASK) for the following case: The contact address of the corresponding LSPRegister request is not existent. (Corresponding HTTP Error Code: 403 - Forbidden (Client Error))

See Also:
Constant Field Values

NOT_AUTHORIZED

public static final int NOT_AUTHORIZED
Client error reply state (see CLIENT_ERROR_MASK) for the following case: The corresponding LSPList request has not been authorized. (Corresponding HTTP Error Code: 401 - Unauthorized (Client Error))

See Also:
Constant Field Values

IMPLICIT_NAME_NOT_PRESENT

public static final int IMPLICIT_NAME_NOT_PRESENT
Client error reply state (see CLIENT_ERROR_MASK) for the following case: The implicit name of the corresponding LSPProxyInvalidate or LSPRegister request is not present. (Corresponding HTTP Error Code: 404 - Not Found (Client Error))

See Also:
Constant Field Values

SERVER_ERROR_MASK

public static final int SERVER_ERROR_MASK
Mask for all server error codes. The corresponding request has been received and understood, but the server encountered an unexpected condition which prevented it from fulfilling the request. (See WRONG_VERSION, REQUEST_TYPE_INVALID, ENCODING_NOT_SUPPORTED, ENCRYPTING_NOT_SUPPORTED)

See Also:
Constant Field Values

WRONG_VERSION

public static final int WRONG_VERSION
Server error reply state (see SERVER_ERROR_MASK) for the following case: The protocol version of the corresponding request has not been accepted. (Corresponding HTTP Error Code: 505 - Version not supported (Server Error))

See Also:
Constant Field Values

REQUEST_TYPE_INVALID

public static final int REQUEST_TYPE_INVALID
Server error reply state (see SERVER_ERROR_MASK) for the following case: The request type of the corresponding request is invalid. (Corresponding HTTP Error Code: 501 - Not Implemented (Server Error))

See Also:
Constant Field Values

ENCODING_NOT_SUPPORTED

public static final int ENCODING_NOT_SUPPORTED
Server error reply state (see SERVER_ERROR_MASK) for the following case: The LSServer respectively the LSProxy, which received the corresponding LSPRegisterEncoded request does not support encoded register requests. (Corresponding HTTP Error Code: 501 - Not Implemented (Server Error))

See Also:
Constant Field Values

ENCRYPTING_NOT_SUPPORTED

public static final int ENCRYPTING_NOT_SUPPORTED
Server error reply state (see SERVER_ERROR_MASK) for the following case: The LSServer respectively the LSProxy, which received the corresponding LSPRegisterEncrypted request does not support encrypted register requests. (Corresponding HTTP Error Code: 501 - Not Implemented (Server Error))

See Also:
Constant Field Values

IO_ERROR_MASK

public static final int IO_ERROR_MASK
Mask for all IO error codes. The corresponding request has not been received or understood, because an error occured during transmission, encoding or decoding. (See IO_ERROR, INTERNAL_CLIENT_ERROR, REQUEST_BODY_INVALID, ENCODED_DATA_INVALID, ENCRYPTED_DATA_INVALID).

See Also:
Constant Field Values

IO_ERROR

public static final int IO_ERROR
IO error reply state (see IO_ERROR_MASK) for the following case: The request could not be sent due to an IO error. (Corresponding HTTP Error Code: 504 - Gateway timeout (Server Error))

See Also:
Constant Field Values

INTERNAL_CLIENT_ERROR

public static final int INTERNAL_CLIENT_ERROR
IO error reply state (see IO_ERROR_MASK) for the following case: An internal client error occured. (Corresponding HTTP Error Code: 409 - Conflict (Client Error))

See Also:
Constant Field Values

REQUEST_BODY_INVALID

public static final int REQUEST_BODY_INVALID
IO error reply state (see IO_ERROR_MASK) for the following case: The request body of the corresponding request is invalid. (Corresponding HTTP Error Code: 400 - Bad Request (Client Error))

See Also:
Constant Field Values

ENCODED_DATA_INVALID

public static final int ENCODED_DATA_INVALID
IO error reply state (see IO_ERROR_MASK) for the following case: The content of the corresponding LSPRegisterEncoded request is invalid. (Corresponding HTTP Error Code: 400 - Bad Request (Client Error))

See Also:
Constant Field Values

ENCRYPTED_DATA_INVALID

public static final int ENCRYPTED_DATA_INVALID
IO error reply state (see IO_ERROR_MASK) for the following case: The content of the corresponding LSPRegisterEncrypted request is invalid. (Corresponding HTTP Error Code: 400 - Bad Request (Client Error))

See Also:
Constant Field Values

ERROR_FLAGS

public static final int ERROR_FLAGS
Mask for all error flags. (These error flags can be set in addition to the normal status codes above to indicate that the request has only been fulfilled partly, because there have been errors occured on client, proxy or server side)

See Also:
Constant Field Values

CLIENT_ERROR_FLAG

public static final int CLIENT_ERROR_FLAG
Error flag for the following case: An error has occured on client side.

See Also:
Constant Field Values

PROXY_ERROR_FLAG

public static final int PROXY_ERROR_FLAG
Error flag for the following case: An error has occured on proxy side.

See Also:
Constant Field Values

SERVER_ERROR_FLAG

public static final int SERVER_ERROR_FLAG
Error flag for the following case: An error has occured on server side.

See Also:
Constant Field Values

version_

protected ASN1Integer version_
The version number of this reply.


type_

protected ASN1Integer type_
The reply type.


state_

protected ASN1Integer state_
The reply state.


body_

protected ASN1Type body_
The reply body.

Constructor Detail

LSPReply

private LSPReply()
Creates an instance ready for decoding. This can only be built within the createReply method to decode a given encoded reply.


LSPReply

public LSPReply(int type,
                int state,
                ASN1Type body)
         throws InvalidMessageTypeException,
                NullPointerException
Creates an reply instance of the given type with the given body and the given state.

Parameters:
type - The reply type.
state - The reply state.
body - The reply body.
Throws:
InvalidMessageTypeException - if the given reply type is not supported (RuntimeException).
NullPointerException - if body is null and state is not STATE_ONLY (RuntimeException).
Method Detail

createReply

public static LSPReply createReply(byte[] code)
                            throws CorruptedCodeException,
                                   WrongProtocolVersionException,
                                   InvalidMessageTypeException,
                                   IllegalStateException,
                                   NullPointerException
Creates a new reply from the given encoded reply.

Parameters:
code - The encoded reply.
Returns:
The decoded reply.
Throws:
CorruptedCodeException - if the code is bad.
WrongProtocolVersionException - if the protocol version does not match with the expected one (RuntimeException).
InvalidMessageTypeException - if the message type of the reply is not supported (RuntimeException).
IllegalStateException - if an error occurs while decoding with DERDecoder (RuntimeException).
NullPointerException - if code is null (RuntimeException).

createReply

public static LSPReply createReply(InputStream in,
                                   int limit)
                            throws CorruptedCodeException,
                                   WrongProtocolVersionException,
                                   InvalidMessageTypeException,
                                   IllegalStateException,
                                   NullPointerException
Creates a new reply from the encoded reply, which will be read from the specified input stream. If the encoded reply is longer than the specified limit of bytes, an IllegalStateException will be thrown.

Returns:
The decoded reply.
Throws:
CorruptedCodeException - if the code is bad.
WrongProtocolVersionException - if the protocol version does not match with the expected one (RuntimeException).
InvalidMessageTypeException - if the message type of the reply is not supported (RuntimeException).
IllegalStateException - if an error occurs while decoding with DERDecoder (RuntimeException).
NullPointerException - if code is null (RuntimeException).

setClientErrorFlag

public void setClientErrorFlag(boolean flag)
Sets the client error flag if flag is true, deletes this flag if flag is false (see CLIENT_ERROR_FLAG).

Parameters:
flag - The client error flag.

setProxyErrorFlag

public void setProxyErrorFlag(boolean flag)
Sets the proxy error flag if flag is true, deletes this flag if flag is false (see PROXY_ERROR_FLAG).

Parameters:
flag - The proxy error flag.

setServerErrorFlag

public void setServerErrorFlag(boolean flag)
Sets the server error flag if flag is true, deletes this flag if flag is false (see SERVER_ERROR_FLAG).

Parameters:
flag - The client error flag.

setErrorFlags

public void setErrorFlags(int flags)
Deletes all current error flags and sets the new flags (see ERROR_FLAGS).

Parameters:
flags - The error flags.

resolve

public ASN1Type resolve(ASN1Type caller)
                 throws ResolverException
Returns the supposed ASN1Type of the reply body, corresponding to the current reply type, or null, if the current reply type is STATE_ONLY.

Specified by:
resolve in interface Resolver
Parameters:
caller - The caller of this method.
Returns:
The ASN1Type of the reply body.
Throws:
ResoverException - if the current reply type is not supported.
ResolverException

getVersion

public int getVersion()
Returns the reply version.

Returns:
The reply version.

getType

public int getType()
Returns the reply type.

Returns:
The reply type.

getState

public int getState()
Returns the reply state.

Returns:
The reply state.

getBody

public ASN1Type getBody()
Returns the reply body, or null, if the current reply type is STATE_ONLY.

Returns:
The reply body.

getErrorFlags

public int getErrorFlags()
Retruns the error flags (see ERROR_FLAGS)

Returns:
The error flags.

checkSuccess

public boolean checkSuccess()
Checks the type of the reply state (see SUCCESS_MASK).

Returns:
true if reply state is a success code, false otherwise.

checkRedirection

public boolean checkRedirection()
Checks the type of the reply state (see REDIRECTION_MASK).

Returns:
true if reply state is a redirection code, false otherwise.

checkClientError

public boolean checkClientError()
Checks the type of the reply state (see CLIENT_ERROR_MASK).

Returns:
true if reply state is a client error, false otherwise.

checkServerError

public boolean checkServerError()
Checks the type of the reply state (see SERVER_ERROR_MASK).

Returns:
true if reply state is a server error, false otherwise.

checkIOError

public boolean checkIOError()
Checks the type of the reply state (see IO_ERROR_MASK).

Returns:
true if reply state is an IO error, false otherwise.

checkErrorFlags

public boolean checkErrorFlags()
Checks error flags (see ERROR_FLAGS).

Returns:
true if any error flags are set, false otherwise.

getEncoded

public byte[] getEncoded()
                  throws IllegalStateException
Returns the DER encoded reply.

Returns:
The encoded reply.
Throws:
IllegalStateException - if an exception occures during ASN1 encoding (RuntimeException).

getTypeString

public String getTypeString()
Returns the string representation of the reply type.

Returns:
The string representation.

getStateString

public String getStateString()
Returns the string representation of the reply state

Returns:
The string representation.

toString

public String toString()
Returns the string representation of this reply. This is done in following manner
 ASN1StructureName {
 Property  : Value
 }
 

Returns:
The string representation.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.