infoservice.japforwarding
Class ServerVerifier

java.lang.Object
  extended by infoservice.japforwarding.ServerVerifier

public final class ServerVerifier
extends java.lang.Object

This class is used for verifying a JAP forwarding server (whether it is accessable from the outside world).


Field Summary
private  java.net.InetAddress m_serverAddress
          Stores the internet address of a JAP forwarding server.
private  int m_serverPort
          Stores the port of a JAP forwarding server.
private static int MAXIMUM_PROTOCOLMESSAGE_SIZE
          This is the maximum net size of a protocol message in bytes.
private static byte[] MESSAGE_END_SIGNATURE
          This is the end signature of every protocol message.
private static byte[] MESSAGE_START_SIGNATURE
          This is the start signature of every protocol message.
private static long ms_lastServerVerifierThreadID
          Stores the thread number of the ServerVerifiy-Thread...*
 
Constructor Summary
ServerVerifier(java.net.InetAddress a_serverAddress, int a_serverPort)
          Creates a new ServerVerifier.
 
Method Summary
private  boolean checkSignature(byte[] a_signature1, byte[] a_signature2)
          This method checks, whether to byte arrays have identical content or not.
private  byte[] createProtocolPacket(byte[] a_data)
          Creates a protocol packet from byte array with data.
private  org.w3c.dom.Document generateConnectionVerify()
          Creates an verify request message for the verifying the JAP forwarding server.
private  org.w3c.dom.Document parseXmlData(byte[] a_xmlData)
          Parses a byte-array with XML data.
private  byte[] readProtocolMessage(java.net.Socket a_connection)
          Reads a message from the associated network connection.
private  void sendProtocolMessage(byte[] a_message, java.net.Socket a_connection)
          Sends a message to the associated network connection.
 boolean verifyServer()
          Verifies the connection to the JAP forwarding server.
private  byte[] xmlToProtocolPacket(org.w3c.dom.Document a_doc)
          Creates a protocol packet from an XML structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_START_SIGNATURE

private static final byte[] MESSAGE_START_SIGNATURE
This is the start signature of every protocol message.


MESSAGE_END_SIGNATURE

private static final byte[] MESSAGE_END_SIGNATURE
This is the end signature of every protocol message.


MAXIMUM_PROTOCOLMESSAGE_SIZE

private static final int MAXIMUM_PROTOCOLMESSAGE_SIZE
This is the maximum net size of a protocol message in bytes. Bigger messages are not accepted and causes an exception.

See Also:
Constant Field Values

m_serverAddress

private java.net.InetAddress m_serverAddress
Stores the internet address of a JAP forwarding server.


m_serverPort

private int m_serverPort
Stores the port of a JAP forwarding server.


ms_lastServerVerifierThreadID

private static long ms_lastServerVerifierThreadID
Stores the thread number of the ServerVerifiy-Thread...*

Constructor Detail

ServerVerifier

public ServerVerifier(java.net.InetAddress a_serverAddress,
                      int a_serverPort)
Creates a new ServerVerifier. It can verify the JAP forwarding server specified by the address and port parameters.

Parameters:
a_serverAddress - The internet address of the JAP forwarding server.
a_serverPort - The port of the JAP forwarding server.
Method Detail

verifyServer

public boolean verifyServer()
Verifies the connection to the JAP forwarding server.


checkSignature

private boolean checkSignature(byte[] a_signature1,
                               byte[] a_signature2)
This method checks, whether to byte arrays have identical content or not.

Parameters:
a_signature1 - The first byte array.
a_signature2 - The second byte array.
Returns:
True, if both byte arrays are not null and have the same content, else the result is false.

readProtocolMessage

private byte[] readProtocolMessage(java.net.Socket a_connection)
                            throws java.lang.Exception
Reads a message from the associated network connection. Header and trailer of the protocol message are removed. If there is a connection or protocol error, an exception is thrown.

Parameters:
a_connection - The connection to read from;
Returns:
The message read from the connection.
Throws:
java.lang.Exception

sendProtocolMessage

private void sendProtocolMessage(byte[] a_message,
                                 java.net.Socket a_connection)
                          throws java.io.IOException
Sends a message to the associated network connection. The message must be in the protocol message format (with header and trailer).

Parameters:
a_message - The message to send.
a_connection - The connection for writing the message.
Throws:
java.io.IOException

generateConnectionVerify

private org.w3c.dom.Document generateConnectionVerify()
                                               throws java.lang.Exception
Creates an verify request message for the verifying the JAP forwarding server. If we get the correct answer, we know that the JAP forwarding server works and is accessable from the outside.

Returns:
The connection verify XML structure.
Throws:
java.lang.Exception

xmlToProtocolPacket

private byte[] xmlToProtocolPacket(org.w3c.dom.Document a_doc)
                            throws java.lang.Exception
Creates a protocol packet from an XML structure.

Parameters:
doc - The XML structure which shall be transformed in a protocol packet.
Returns:
The protocol packet with the XML structure inside.
Throws:
java.lang.Exception

createProtocolPacket

private byte[] createProtocolPacket(byte[] a_data)
Creates a protocol packet from byte array with data. This method adds header and trailer to the data and returns the whole packet.

Parameters:
a_data - The bytes to put in the protocol packet.
Returns:
The protocol packet with data, header and trailer.

parseXmlData

private org.w3c.dom.Document parseXmlData(byte[] a_xmlData)
                                   throws java.lang.Exception
Parses a byte-array with XML data.

Parameters:
a_xmlData - A byte-array with XML data.
Returns:
A parsed XML document.
Throws:
java.lang.Exception