use of javax.sip.message.Response in project Openfire by igniterealtime.
the class SipManager method sendNotImplemented.
/**
* Sends a NOT_IMPLEMENTED response through the specified transaction.
*
* @param serverTransaction the transaction to send the response through.
* @param request the request that is being answered.
*/
void sendNotImplemented(ServerTransaction serverTransaction, Request request) {
Response notImplemented;
try {
notImplemented = messageFactory.createResponse(Response.NOT_IMPLEMENTED, request);
attachToTag(notImplemented, serverTransaction.getDialog());
} catch (ParseException ex) {
fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
return;
}
try {
serverTransaction.sendResponse(notImplemented);
} catch (SipException ex) {
fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
}
}
use of javax.sip.message.Response 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!!");
}
}
}
}
use of javax.sip.message.Response in project XobotOS by xamarin.
the class SipHelper method sendInviteOk.
/**
* @param event the INVITE request event
*/
public ServerTransaction sendInviteOk(RequestEvent event, SipProfile localProfile, String sessionDescription, ServerTransaction inviteTransaction, String externalIp, int externalPort) throws SipException {
try {
Request request = event.getRequest();
Response response = mMessageFactory.createResponse(Response.OK, request);
response.addHeader(createContactHeader(localProfile, externalIp, externalPort));
response.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
if (inviteTransaction == null) {
inviteTransaction = getServerTransaction(event);
}
if (inviteTransaction.getState() != TransactionState.COMPLETED) {
if (DEBUG)
Log.d(TAG, "send OK: " + response);
inviteTransaction.sendResponse(response);
}
return inviteTransaction;
} catch (ParseException e) {
throw new SipException("sendInviteOk()", e);
}
}
use of javax.sip.message.Response in project XobotOS by xamarin.
the class SipHelper method sendInviteAck.
/**
* @param event the INVITE ACK request event
*/
public void sendInviteAck(ResponseEvent event, Dialog dialog) throws SipException {
Response response = event.getResponse();
long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getSeqNumber();
Request ack = dialog.createAck(cseq);
if (DEBUG)
Log.d(TAG, "send ACK: " + ack);
dialog.sendAck(ack);
}
use of javax.sip.message.Response in project XobotOS by xamarin.
the class SipSessionGroup method expectResponse.
/**
* @return true if the event is a response event and the CSeqHeader method
* match the given arguments; false otherwise
*/
private static boolean expectResponse(String expectedMethod, EventObject evt) {
if (evt instanceof ResponseEvent) {
ResponseEvent event = (ResponseEvent) evt;
Response response = event.getResponse();
return expectedMethod.equalsIgnoreCase(getCseqMethod(response));
}
return false;
}
Aggregations