Fields Summary |
---|
private com.sun.midp.security.SecurityToken | classSecurityTokenSecurity token for SIP/SIPS protocol class |
private static StackConnector | instanceThe unique instance of this class |
protected gov.nist.siplite.SipStack | sipStackThe actual stack |
private String | localAddresslisten address |
private gov.nist.siplite.ListeningPoint | tempListeningPointTemporary listening point. |
private gov.nist.siplite.SipProvider | tempSipProviderTemporary sip provider. |
protected Vector | connectionNotifiersListlist of connection notifiers |
protected Vector | sipDialogListlist of all current dialogs |
public static gov.nist.siplite.address.AddressFactory | addressFactoryAddress factory handle. |
public static gov.nist.siplite.message.MessageFactory | messageFactoryMessage factory handle. |
public static gov.nist.siplite.header.HeaderFactory | headerFactoryHeader factory handle. |
private gov.nist.siplite.ListeningPoint | sharedListeningPointShared listening point |
private gov.nist.siplite.SipProvider | sharedSipProviderShared sipProvider instance |
int | sharedPortNumberShared port number |
Vector | sharedMimeTypesIndicates mime types used by applications for SipConnectionNotifiers
in shared mode |
Methods Summary |
---|
public void | closeSharedSipConnectionNotifier(java.lang.String mimeType)Close a SipConnectionNotifier in shared mode
// Ignore when sharedMimeTypes already removed
if (sharedMimeTypes == null) {
return;
}
sharedMimeTypes.removeElement((String)mimeType);
if (sharedMimeTypes.size() == 0) {
try {
sipStack.deleteListeningPoint(sharedListeningPoint);
sipStack.deleteSipProvider(sharedSipProvider);
} catch (ObjectInUseException oiue) {
throw new IOException(oiue.getMessage());
}
sharedMimeTypes = null;
/*
* There are no more associated listening points in shared mode;
* so stop the stack
*/
sipStack.stopStack();
}
|
public javax.microedition.sip.SipConnectionNotifier | createSharedSipConnectionNotifier(boolean secure, java.lang.String transport, java.lang.String mimeType)Creates a sip connection notifier in shared mode. In shared mode,
SipConnectionNotifier is supposed to use a single shared port or
listening point for all applications
if (sharedMimeTypes != null) {
for (int i = 0; i < sharedMimeTypes.size(); i++) {
if (mimeType.equalsIgnoreCase(
((String)sharedMimeTypes.elementAt(i)))) {
throw new IOException("Application type is already " +
"reserved");
}
}
} else {
sharedMimeTypes = new Vector();
}
/*
* Add the mimeType to sharedMimeTypes vector
*/
sharedMimeTypes.addElement((String)mimeType);
/*
* SipConnectionNotifier in shared mode must use shared system SIP port
* and shared SIP identity. So a shared listening point and sipProvider
* must be used for every SipConnectionNotifier in shared mode
*/
if ((sharedListeningPoint == null) &&
(sharedSipProvider == null)) {
// select a free port
sharedPortNumber = selectPort(sharedPortNumber, transport);
sharedListeningPoint =
this.tempListeningPoint; // initialized by "selectPort()"
sharedSipProvider =
this.tempSipProvider; // initialized by "selectPort()"
}
SipConnectionNotifier sipConnectionNotifier =
new SipConnectionNotifierImpl(sharedSipProvider, localAddress,
sharedPortNumber, this.classSecurityToken, mimeType, true);
// ((SipConnectionNotifierImpl)sipConnectionNotifier).start();
// Add the the newly created sip connection notifier to the list of
// connection notifiers
this.connectionNotifiersList.addElement(sipConnectionNotifier);
return sipConnectionNotifier;
|
public javax.microedition.sip.SipClientConnection | createSipClientConnection(gov.nist.siplite.address.SipURI inputURI)Creates a sip Client Connection to send a request to the
following SIP URI user@host:portNumber;parameters
SipClientConnection sipClientConnection =
new SipClientConnectionImpl(inputURI, this.classSecurityToken);
return sipClientConnection;
|
public javax.microedition.sip.SipConnectionNotifier | createSipConnectionNotifier(int portNumber, boolean secure, java.lang.String transport, java.lang.String mimeType)Create a sip connection notifier on a specific port
using or not the sip secure layer and with some restrictive parameters
to receive requests
// select a free port (if need)
portNumber = selectPort(portNumber, transport);
SipConnectionNotifier sipConnectionNotifier =
new SipConnectionNotifierImpl(tempSipProvider, localAddress,
portNumber, this.classSecurityToken, mimeType, false);
// ((SipConnectionNotifierImpl)sipConnectionNotifier).start();
// Add the the newly created sip connection notifier to the list of
// connection notifiers
this.connectionNotifiersList.addElement(sipConnectionNotifier);
return sipConnectionNotifier;
|
protected javax.microedition.sip.SipDialog | findDialog(java.lang.String dialogID)find in the dialog list, the sip dialog with the same dialog ID
as the one in parameter
Enumeration e = sipDialogList.elements();
while (e.hasMoreElements()) {
SipDialog sipDialog = (SipDialog)e.nextElement();
if (sipDialog.getDialogID() != null &&
sipDialog.getDialogID().equals(dialogID)) {
return sipDialog;
}
}
return null;
|
protected static java.lang.String | generateTag()generate a random tag that can be used either in the FromHeader or in the
ToHeader
return String.valueOf(new Random().nextInt(Integer.MAX_VALUE));
|
public java.util.Vector | getConnectionNotifiersList()Gets the current connection notifier list.
return connectionNotifiersList;
|
public static synchronized gov.nist.microedition.sip.StackConnector | getInstance(com.sun.midp.security.SecurityToken classSecurityToken)Get the unique instance of this class
if (instance == null)
instance = new StackConnector(classSecurityToken);
return instance;
|
public javax.microedition.sip.SipConnectionNotifier | getSipConnectionNotifier(int portNumber, java.lang.String acceptContactType)Retrieve from the list of connection notifier the one that use the same
port as in parameter
Enumeration e = connectionNotifiersList.elements();
while (e.hasMoreElements()) {
SipConnectionNotifier sipConnectionNotifier =
(SipConnectionNotifier)e.nextElement();
try {
if (sipConnectionNotifier.getLocalPort() != portNumber) {
continue;
}
if (acceptContactType != null) {
String scnMimeType =
((SipConnectionNotifierImpl)sipConnectionNotifier).
getMIMEType();
if (scnMimeType != null) {
if (scnMimeType.equalsIgnoreCase(acceptContactType) ||
"*".equals(acceptContactType)) {
return sipConnectionNotifier;
}
}
} else {
return sipConnectionNotifier;
}
} catch (IOException ioe) {
// Intentionally ignored.
}
}
return null;
|
public gov.nist.siplite.SipStack | getSipStack()Gets the current SipStack object.
return sipStack;
|
public void | processRequest(gov.nist.siplite.RequestEvent requestEvent)Processes the current transaction event.
try {
String acceptContactType = null;
Request request = requestEvent.getRequest();
AcceptContactHeader acHdr = request.getAcceptContact();
if (acHdr != null) { // Accept-Contact header present
acceptContactType = acHdr.getType();
}
// Retrieve the SipConnectionNotifier from the transaction
SipConnectionNotifierImpl sipConnectionNotifier = null;
ServerTransaction serverTransaction =
requestEvent.getServerTransaction();
if (serverTransaction != null)
sipConnectionNotifier =
(SipConnectionNotifierImpl)serverTransaction
.getApplicationData();
// If it's a new request coming in, the
// sipConnectionNotifier will certainly be null, so
// retrieve from the list of connection notifier the one
// that use the same port as in parameter
if (sipConnectionNotifier == null) {
SipProvider sipProvider = (SipProvider)requestEvent.getSource();
ListeningPoint listeningPoint = sipProvider.getListeningPoint();
sipConnectionNotifier =
((SipConnectionNotifierImpl)
getSipConnectionNotifier(listeningPoint.getPort(),
acceptContactType));
if ((serverTransaction != null) &&
(sipConnectionNotifier != null)) {
serverTransaction.setApplicationData(sipConnectionNotifier);
}
}
if (sipConnectionNotifier != null) {
sipConnectionNotifier.notifyRequestReceived(request);
} else {
// No need to throw any RuntimeException; just log the error
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
"we cannot find any connection notifier" +
"matching to handle this request");
}
}
} catch (NullPointerException npe) {
// npe.printStackTrace();
} catch (IllegalArgumentException iae) {
// iae.printStackTrace();
}
|
public void | processResponse(gov.nist.siplite.ResponseEvent responseEvent)Processes the resposne event.
try {
Response response = responseEvent.getResponse();
// Retrieve the SipClientConnection from the transaction
ClientTransaction clientTransaction =
responseEvent.getClientTransaction();
SipClientConnectionImpl sipClientConnection =
(SipClientConnectionImpl)clientTransaction.getApplicationData();
if (sipClientConnection != null) {
// translate null when client transactions are same
if (sipClientConnection.getClientTransaction()
.equals(clientTransaction)) {
sipClientConnection.notifyResponseReceived(response, null);
} else { // send new client transaction
sipClientConnection.notifyResponseReceived(response,
clientTransaction);
}
} else {
throw new RuntimeException(
"we cannot find any client connection" +
"matching to handle this request");
}
} catch (NullPointerException npe) {
// npe.printStackTrace();
} catch (IllegalArgumentException iae) {
// iae.printStackTrace();
}
|
public void | processTimeout(gov.nist.siplite.TimeoutEvent timeoutEvent)Process a timeout event.
|
public static synchronized void | releaseInstance()remove the instance of the stack.
instance = null;
|
private int | selectPort(int portNumber, java.lang.String transport)Create a listening point ans sip provider on given or random
selected port. When port is selected successfully,
ListeningPoint and SipProvider instances are created.
boolean isRandomPort = (portNumber == -1);
final int MAX_ATTEMPTS = 1000;
int attemps = 0;
if (isRandomPort) {
// Try the default port first.
portNumber = SIPConstants.DEFAULT_NONTLS_PORT;
}
do {
if (attemps++ > MAX_ATTEMPTS) {
throw new IOException("Cannot select a port!");
}
// Creates the listening point
// IMPL_NOTE : Use the parameters to restrain the incoming messages
try {
tempListeningPoint =
sipStack.createListeningPoint(portNumber, transport);
} catch (TransportNotSupportedException tnse) {
// tnse.printStackTrace();
throw new IOException(tnse.getMessage());
} catch (IllegalArgumentException iae) {
if (isRandomPort) { // port is busy
// Select a random port from 1024 to 10000.
portNumber = new DistributedRandom().nextInt(8975) + 1024;
continue;
} else {
throw new IOException(iae.getMessage());
}
}
// Creates the sip provider
try {
tempSipProvider =
sipStack.createSipProvider(tempListeningPoint);
} catch (ObjectInUseException oiue) {
if (isRandomPort) { // port is busy
// Select a random port from 1024 to 10000.
portNumber = new DistributedRandom().nextInt(8975) + 1024;
continue;
} else {
// oiue.printStackTrace();
throw new ObjectInUseException(oiue.getMessage());
}
}
isRandomPort = false;
// Add this class as a listener for incoming messages
try {
tempSipProvider.addSipListener(this);
} catch (TooManyListenersException tmle) {
// tmle.printStackTrace();
throw new IOException(tmle.getMessage());
}
} while (isRandomPort);
return portNumber;
|