FileDocCategorySizeDatePackage
MessageChannel.javaAPI DocphoneME MR2 API (J2ME)10113Wed May 02 18:00:42 BST 2007gov.nist.siplite.stack

MessageChannel

public abstract class MessageChannel extends Object
Message channel abstraction for the SIP stack. This code is in the public domain.

Fields Summary
protected MessageProcessor
messageProcessor
Message processor to whom I belong (if set).
Constructors Summary
Methods Summary
public abstract voidclose()
Closes the message channel.

public java.lang.StringgetHost()
Gets the host of this message channel.

return
host of this messsage channel.

        return this.getSIPStack().getHostAddress();
    
public HostPortgetHostPort()
Gets the hostport structure of this message channel.

return
the host and port

        HostPort retval = new HostPort();
        retval.setHost(new Host(this.getHost()));
        retval.setPort(this.getPort());
        return retval;
    
public static java.lang.StringgetKey(java.lang.String inetAddr, int port, java.lang.String transport)
Generates a key given the inet address port and transport.

param
inetAddr internet address
param
port the connection end point
param
transport the connection type
return
the connection key

        return transport+":"+ inetAddr +":"+port;
    
public abstract java.lang.StringgetKey()
Generates a key which identifies the message channel. This allows us to cache the message channel.

return
the key

public MessageProcessorgetMessageProcessor()
Gets the message processor.

return
the message processor

        return this.messageProcessor;
    
public abstract java.lang.StringgetPeerAddress()
Gets the peer address of the machine that sent us this message.

return
a string contianing the ip address or host name of the sender of the message.

public HostPortgetPeerHostPort()
Gets the peer host and port.

return
a HostPort structure for the peer.

        HostPort retval = new HostPort();
        retval.setHost(new Host(this.getPeerAddress()));
        retval.setPort(this.getPeerPort());
        return retval;
    
public abstract intgetPeerPort()
Gets the sender port (the port of the other end that sent me the message).

return
the peer port

public intgetPort()
Gets port of this message channel.

return
Port of this message channel.

        if (this.messageProcessor != null)
            return messageProcessor.getPort();
        else return -1;
    
public abstract SIPMessageStackgetSIPStack()
Gets the SIPMessageStack object from this message channel.

return
SIPMessageStack object of this message channel

public abstract java.lang.StringgetTransport()
Gets transport string of this message channel.

return
Transport string of this message channel.

public ViaHeadergetViaHeader()
Gets the Via header for this transport. Note that this does not set a branch identifier.

return
a via header for outgoing messages sent from this channel.

        ViaHeader channelViaHeader;
        
        channelViaHeader = new ViaHeader();
        
        channelViaHeader.setTransport(getTransport());
        
        channelViaHeader.setSentBy(getHostPort());
        return channelViaHeader;
    
public abstract java.lang.StringgetViaHost()
Gets the host to assign for an outgoing Request via header.

return
the via host

public HostPortgetViaHostPort()
Gets the via header host:port structure. This is extracted from the topmost via header of the request.

return
a host:port structure

        HostPort retval = new HostPort();
        retval.setHost(new Host(this.getViaHost()));
        retval.setPort(this.getViaPort());
        return retval;
    
public abstract intgetViaPort()
Gets the port to assign for the via header of an outgoing message.

return
the via port

public abstract voidhandleException(SIPServerException ex)
Handles an exception.

param
ex the exception to process

public abstract booleanisReliable()
Gets whether this channel is reliable or not.

return
True if reliable, false if not.

public abstract booleanisSecure()
Returns true if this is a secure channel.

return
true if connection is secure

protected voidlogMessage(Message sipMessage, java.lang.String address, int port, long time)
Logs a message sent to an address and port via the default interface.

param
sipMessage is the message to log.
param
address is the inet address to which the message is sent.
param
port is the port to which the message is directed.
param
time timestamp for the logged message

        String firstLine = sipMessage.getFirstLine();
        CSeqHeader cseq = (CSeqHeader) sipMessage.getCSeqHeader();
        CallIdHeader callid = (CallIdHeader) sipMessage.getCallId();
        String cseqBody = cseq.encodeBody();
        String callidBody = callid.encodeBody();
        // Default port.
        if (port == -1) port = 5060;
        if (ServerLog.needsLogging(ServerLog.TRACE_MESSAGES)) {
            Enumeration extList = sipMessage.getHeaders("NISTExtension");
            String status = null;
            if (extList != null && extList.hasMoreElements()) {
                Header exthdr = null;
                exthdr = (Header) extList.nextElement();
                status = exthdr.getHeaderValue();
            }
            ServerLog.logMessage(sipMessage.encode(),
                    this.getHost()+":"+this.getPort(),
                    address +
                    ":" + port, true, callidBody,
                    firstLine, status,
                    sipMessage.getTransactionId(), time);
        }
    
public voidlogResponse(Response sipResponse, long receptionTime, java.lang.String status)
Logs a response received at this message channel. This is used for processing incoming responses to a client transaction.

param
sipResponse the response object to be logged
param
receptionTime is the time at which the response was received.
param
status is the processing status of the message.

        try {
            int peerport = getPeerPort();
            if (peerport == 0 && sipResponse.getContactHeaders() != null) {
                ContactHeader contact =
		    (ContactHeader) sipResponse.getContactHeaders().getFirst();
                peerport = ((Address)contact.getAddress()).getPort();
                
            }
            String from = getPeerAddress() + ":" + peerport;
            String to = this.getHost() + ":" + getPort();
            ServerLog.logMessage(sipResponse,
                    from, to, status, false, receptionTime);
        } catch (RuntimeException ex) {
            ex.printStackTrace();
        }
    
protected abstract voidsendMessage(byte[] message, java.lang.String receiverAddress, int receiverPort)
Sends the message (after it has been formatted), to a specified address and a specified port

param
message Message to send.
param
receiverAddress Address of the receiver.
param
receiverPort Port of the receiver.

public voidsendMessage(Message sipMessage, java.lang.String receiverAddress, int receiverPort)
Sends a message given SIP message.

param
sipMessage is the messge to send.
param
receiverAddress is the address to which we want to send
param
receiverPort is the port to which we want to send

        long time = System.currentTimeMillis();
        byte[] bytes = sipMessage.encodeAsBytes();
        sendMessage(bytes, receiverAddress, receiverPort);
        logMessage(sipMessage, receiverAddress, receiverPort, time);
    
public abstract voidsendMessage(Message sipMessage)
Sends the message (after it has been formatted)

param
sipMessage Message to send.