use of javax.sip.message.Response in project XobotOS by xamarin.
the class SipProviderImpl method getNewDialog.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
*/
public Dialog getNewDialog(Transaction transaction) throws SipException {
if (transaction == null)
throw new NullPointerException("Null transaction!");
if (!sipStack.isAlive())
throw new SipException("Stack is stopped.");
if (isAutomaticDialogSupportEnabled())
throw new SipException(" Error - AUTOMATIC_DIALOG_SUPPORT is on");
if (!sipStack.isDialogCreated(transaction.getRequest().getMethod()))
throw new SipException("Dialog cannot be created for this method " + transaction.getRequest().getMethod());
SIPDialog dialog = null;
SIPTransaction sipTransaction = (SIPTransaction) transaction;
if (transaction instanceof ServerTransaction) {
SIPServerTransaction st = (SIPServerTransaction) transaction;
Response response = st.getLastResponse();
if (response != null) {
if (response.getStatusCode() != 100)
throw new SipException("Cannot set dialog after response has been sent");
}
SIPRequest sipRequest = (SIPRequest) transaction.getRequest();
String dialogId = sipRequest.getDialogId(true);
dialog = sipStack.getDialog(dialogId);
if (dialog == null) {
dialog = sipStack.createDialog((SIPTransaction) transaction);
// create and register the dialog and add the inital route set.
dialog.addTransaction(sipTransaction);
dialog.addRoute(sipRequest);
sipTransaction.setDialog(dialog, null);
} else {
sipTransaction.setDialog(dialog, sipRequest.getDialogId(true));
}
if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
sipStack.putInMergeTable(st, sipRequest);
}
} else {
SIPClientTransaction sipClientTx = (SIPClientTransaction) transaction;
SIPResponse response = sipClientTx.getLastResponse();
if (response == null) {
// A response has not yet been received, then set this up as the
// default dialog.
SIPRequest request = (SIPRequest) sipClientTx.getRequest();
String dialogId = request.getDialogId(false);
dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
throw new SipException("Dialog already exists!");
} else {
dialog = sipStack.createDialog(sipTransaction);
}
sipClientTx.setDialog(dialog, null);
} else {
throw new SipException("Cannot call this method after response is received!");
}
}
dialog.addEventListener(this);
return dialog;
}
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 camel by apache.
the class SipSubscriptionListener method processResponse.
public void processResponse(ResponseEvent responseReceivedEvent) {
LOG.debug("Response received at Subscriber");
Response response = responseReceivedEvent.getResponse();
Transaction clientTransactionId = responseReceivedEvent.getClientTransaction();
LOG.debug("Response received with client transaction id {}:{}", clientTransactionId, response.getStatusCode());
if (clientTransactionId == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("Stray response -- dropping");
}
return;
}
}
use of javax.sip.message.Response in project camel by apache.
the class SipPresenceAgentListener method processSubscribe.
public void processSubscribe(RequestEvent requestEvent, ServerTransaction serverTransaction) {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
try {
LOG.debug("SipPresenceAgentListener: Received a Subscribe request, sending OK");
LOG.debug("SipPresenceAgentListener request: {}", request);
EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
if (eventHeader == null) {
LOG.debug("Cannot find event header.... dropping request.");
return;
}
// Always create a ServerTransaction, best as early as possible in the code
Response response = null;
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
// Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
boolean isInitial = requestEvent.getDialog() == null;
if (isInitial) {
String toTag = UUID.randomUUID().toString();
response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
// Application is supposed to set.
toHeader.setTag(toTag);
this.dialog = st.getDialog();
// subscribe dialogs do not terminate on bye.
this.dialog.terminateOnBye(false);
} else {
response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(200, request);
}
// Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
response.addHeader(sipPresenceAgent.getConfiguration().getContactHeader());
// Expires header is mandatory in 2xx responses to SUBSCRIBE
response.addHeader(sipPresenceAgent.getConfiguration().getExpiresHeader());
st.sendResponse(response);
LOG.debug("SipPresenceAgentListener: Sent OK Message");
LOG.debug("SipPresenceAgentListener response: {}", response);
sendNotification(eventHeader, isInitial, request.getContent());
} catch (Throwable e) {
LOG.error("Exception thrown during Notify processing in the SipPresenceAgentListener.", e);
}
}
Aggregations