RegistrationHelperpublic class RegistrationHelper extends Object implements SipListener, RunnableA helper class that runs a registration call flow. |
Fields Summary |
---|
private SipStack | sipStackCurrent SIP stack context. | private SipProvider | sipProviderCurrent SIP provider. | private MessageFactory | messageFactoryMessage factory. | private HeaderFactory | headerFactoryHJeader factory. | private String | userNameCurrent user name. | private String | userAddressCurrent user address. | private ListeningPoint | lpCurrent event listening filter. | private Thread | myThreadLocal thread for asynchoronous processing. | protected boolean | successfulRegistrationFlag indicating successful registraion. | private AuthenticationListener | authenticationListenerCredentials listener for authentication requests. | private int | countReoriginateRequestCount of authorization requests (RFC 2617, 3.2.2). |
Constructors Summary |
---|
public RegistrationHelper(SipStack myStack, String userName, String userAddress, ListeningPoint lp)Constructor.
this.sipStack = myStack;
this.userName = userName;
this.userAddress = userAddress;
this.messageFactory = new MessageFactory();
this.headerFactory = new HeaderFactory();
this.lp = lp;
myThread = new Thread(this);
// authenticationListener=new DigestClientAuthentication();
|
Methods Summary |
---|
public void | doRegister()Performs the session registration.
myThread.start();
// Wait to register ourselves so we can receive messages.
synchronized (this) {
try {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"WAIT");
}
this.wait();
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"WAKE UP");
}
} catch (InterruptedException ex) {
return;
}
}
| public void | processRequest(RequestEvent requestEvent)Processes a request.
(always logs a message that request is ignored)
// System.out.println("Ignoring request");
| public void | processResponse(ResponseEvent responseEvent)Process a response message.
Response response = responseEvent.getResponse();
if (response.getStatusCode() == Response.OK) {
this.successfulRegistration = true;
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"Registration listener : sending notify!");
}
synchronized (this) {
// System.out.println("NOTIFY");
this.notify(); // Authentication done!
}
} else {
// Need to call out here to the Authentication listener.
// check if 401 or 407
if (response.getStatusCode() == Response.
PROXY_AUTHENTICATION_REQUIRED ||
response.getStatusCode() == Response.UNAUTHORIZED) {
Exception ex = null;
try {
ClientTransaction clientTransac = responseEvent.
getClientTransaction();
Request newRequest =
authenticationListener
.createNewRequest(sipStack,
clientTransac.getRequest(),
response, countReoriginateRequest);
if (newRequest == null) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION,
LogChannels.LC_JSR180,
"Authentication failed...");
}
return;
}
countReoriginateRequest ++;
ClientTransaction ct =
sipProvider.getNewClientTransaction(newRequest);
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION,
LogChannels.LC_JSR180,
"Got client Transaction " + ct);
}
ct.sendRequest();
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION,
LogChannels.LC_JSR180,
"RegistrationHelper: request sent:\n" + newRequest);
}
} catch (SipException se) {
ex = se;
} catch (IOException ioe) {
ex = ioe;
}
if (ex != null) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
"RegistrationHelper: processResponse(),"
+ " exception raised: "
+ ex.getMessage());
}
}
}
}
| public void | processTimeout(TimeoutEvent timeoutEvent)Process a tiomeout event.
synchronized (this) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"NOTIFY");
}
this.notify(); // Authentication done!
}
| public void | run()Starts asynchronous processing int separate thread.
try {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"starting registration thread");
}
sipStack.stackInitialized = false;
Hop hop = sipStack.getRouter().getOutboundProxy();
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"got listening point");
}
sipProvider = lp.getProvider();
StringBuffer requestLine =
new StringBuffer("REGISTER sip:")
.append(sipStack.getNextHop().getHost())
.append(":")
.append(sipStack.getNextHop().getPort())
.append(";transport="+hop.getTransport())
.append(" SIP/2.0\r\n");
StringBuffer from =
new StringBuffer("From: <sip:")
.append(userName)
.append("@")
.append(userAddress)
.append(">;tag=1234\r\n");
StringBuffer to =
new StringBuffer("To: <sip:")
.append(userName)
.append("@")
.append(userAddress)
.append(">\r\n");
String via =
lp.messageProcessor.getViaHeader().toString();
int port = lp.getPort();
StringBuffer contact = new
StringBuffer(
"Contact: <sip:"
+ userName
+ "@" + sipStack.getIPAddress()
+ ":" + port
+ ";transport=" + hop.getTransport()
+ ">\r\n");
CallIdHeader callId = sipProvider.getNewCallId();
CSeqHeader cseq = new CSeqHeader();
cseq.setMethod(Request.REGISTER);
cseq.setSequenceNumber(1);
MaxForwardsHeader maxForwards = new MaxForwardsHeader();
maxForwards.setMaxForwards(1);
String registerRequest =
new StringBuffer().append(requestLine)
.append(via).append(callId.toString())
.append(cseq.toString())
.append(maxForwards.toString())
.append(from).append(to).append(contact).
toString();
// System.out.println(registerRequest);
Request request = messageFactory.createRequest
(registerRequest);
ClientTransaction ct =
sipProvider.getNewClientTransaction(request);
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"Got client Transaction " + ct);
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"SENDING REGISTER TO THE PROXY");
}
ct.sendRequest();
} catch (Exception ex) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
"Exception: " + ex);
}
synchronized (this) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"NOTIFY");
}
this.notify();
}
}
|
|