use of javax.sip.header.ExpiresHeader in project Openfire by igniterealtime.
the class SimpleListener method processResponse.
public void processResponse(ResponseEvent responseEvent) {
if (responseEvent.getClientTransaction() != null) {
Log.debug("SimpleListener for " + myUsername + ": Getting client transaction...");
ClientTransaction clientTransaction = responseEvent.getClientTransaction();
Dialog clientDialog = clientTransaction.getDialog();
getSession().printDialog(clientDialog);
}
Log.debug("SimpleListener for " + myUsername + ": Received a response event: " + responseEvent.getResponse().toString());
// String fromAddr = "";
String toAddr = "";
Response response = responseEvent.getResponse();
// }
if (response.getHeader(ToHeader.NAME) != null) {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
URI toUri = toHeader.getAddress().getURI();
if (toUri instanceof SipUri)
toAddr = ((SipUri) toUri).getUser() + "@" + ((SipUri) toUri).getHost();
else
toAddr = toUri.toString();
}
if (response.getHeader(CSeqHeader.NAME) != null) {
String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
if (method.equals(Request.REGISTER)) {
if (response.getStatusCode() / 100 == 2) {
int expires = 0;
if (response.getHeader(ContactHeader.NAME) != null) {
expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
} else if (response.getHeader(ExpiresHeader.NAME) != null) {
expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
}
if (expires > 0) {
Log.debug("SimpleListener(" + myUsername + ").processResponse: " + getSession().getRegistration().getUsername() + " log in successful!");
getSession().sipUserLoggedIn();
} else {
if (getSession().getLoginStatus().equals(TransportLoginStatus.LOGGING_OUT)) {
Log.debug("SimpleListener(" + myUsername + ").processResponse: " + getSession().getRegistration().getUsername() + " log out successful!");
getSession().sipUserLoggedOut();
getSession().removeStack();
}
}
}
}
if (method.equals(Request.SUBSCRIBE)) {
if (response.getStatusCode() / 100 == 2) {
Log.debug("SimpleListener for " + myUsername + ": Handling SUBSCRIBE acknowledgement!!");
int expires = 0;
if (response.getHeader(ContactHeader.NAME) != null) {
expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
}
if (response.getHeader(ExpiresHeader.NAME) != null) {
expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
}
if (expires > 0) {
// Confirm subscription of roster item
getSession().contactSubscribed(toAddr);
} else {
// Confirm unsubscription of roster item
getSession().contactUnsubscribed(toAddr);
}
Log.debug("SimpleListener for " + myUsername + ": Handled SUBSCRIBE acknowledgement!!");
}
}
}
}
Aggregations