use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPDialog method createPrack.
/*
* (non-Javadoc) Retransmissions of the reliable provisional response cease when a matching
* PRACK is received by the UA core. PRACK is like any other request within a dialog, and the
* UAS core processes it according to the procedures of Sections 8.2 and 12.2.2 of RFC 3261. A
* matching PRACK is defined as one within the same dialog as the response, and whose method,
* CSeq-num, and response-num in the RAck header field match, respectively, the method from
* the CSeq, the sequence number from the CSeq, and the sequence number from the RSeq of the
* reliable provisional response.
*
* @see javax.sip.Dialog#createPrack(javax.sip.message.Response)
*/
public Request createPrack(Response relResponse) throws DialogDoesNotExistException, SipException {
if (this.getState() == null || this.getState().equals(DialogState.TERMINATED))
throw new DialogDoesNotExistException("Dialog not initialized or terminated");
if ((RSeq) relResponse.getHeader(RSeqHeader.NAME) == null) {
throw new SipException("Missing RSeq Header");
}
try {
SIPResponse sipResponse = (SIPResponse) relResponse;
SIPRequest sipRequest = (SIPRequest) this.createRequest(Request.PRACK, (SIPResponse) relResponse);
String toHeaderTag = sipResponse.getTo().getTag();
sipRequest.setToTag(toHeaderTag);
RAck rack = new RAck();
RSeq rseq = (RSeq) relResponse.getHeader(RSeqHeader.NAME);
rack.setMethod(sipResponse.getCSeq().getMethod());
rack.setCSequenceNumber((int) sipResponse.getCSeq().getSeqNumber());
rack.setRSequenceNumber(rseq.getSeqNumber());
sipRequest.setHeader(rack);
return (Request) sipRequest;
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
return null;
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPClientTransaction method createCancel.
/*
* (non-Javadoc)
*
* @see javax.sip.ClientTransaction#createCancel()
*/
public Request createCancel() throws SipException {
SIPRequest originalRequest = this.getOriginalRequest();
if (originalRequest == null)
throw new SipException("Bad state " + getState());
if (!originalRequest.getMethod().equals(Request.INVITE))
throw new SipException("Only INIVTE may be cancelled");
if (originalRequest.getMethod().equalsIgnoreCase(Request.ACK))
throw new SipException("Cannot Cancel ACK!");
else {
SIPRequest cancelRequest = originalRequest.createCancelRequest();
cancelRequest.setInviteTransaction(this);
return cancelRequest;
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPDialog method sendRequest.
public void sendRequest(ClientTransaction clientTransactionId, boolean allowInterleaving) throws TransactionDoesNotExistException, SipException {
if ((!allowInterleaving) && clientTransactionId.getRequest().getMethod().equals(Request.INVITE)) {
new Thread((new ReInviteSender(clientTransactionId))).start();
return;
}
SIPRequest dialogRequest = ((SIPClientTransaction) clientTransactionId).getOriginalRequest();
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("dialog.sendRequest " + " dialog = " + this + "\ndialogRequest = \n" + dialogRequest);
if (clientTransactionId == null)
throw new NullPointerException("null parameter");
if (dialogRequest.getMethod().equals(Request.ACK) || dialogRequest.getMethod().equals(Request.CANCEL))
throw new SipException("Bad Request Method. " + dialogRequest.getMethod());
// JvB: added, allow re-sending of BYE after challenge
if (byeSent && isTerminatedOnBye() && !dialogRequest.getMethod().equals(Request.BYE)) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("BYE already sent for " + this);
throw new SipException("Cannot send request; BYE already sent");
}
if (dialogRequest.getTopmostVia() == null) {
Via via = ((SIPClientTransaction) clientTransactionId).getOutgoingViaHeader();
dialogRequest.addHeader(via);
}
if (!this.getCallId().getCallId().equalsIgnoreCase(dialogRequest.getCallId().getCallId())) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("CallID " + this.getCallId());
sipStack.getStackLogger().logError("RequestCallID = " + dialogRequest.getCallId().getCallId());
sipStack.getStackLogger().logError("dialog = " + this);
}
throw new SipException("Bad call ID in request");
}
// Set the dialog back pointer.
((SIPClientTransaction) clientTransactionId).setDialog(this, this.dialogId);
this.addTransaction((SIPTransaction) clientTransactionId);
// Enable the retransmission filter for the transaction
((SIPClientTransaction) clientTransactionId).isMapped = true;
From from = (From) dialogRequest.getFrom();
To to = (To) dialogRequest.getTo();
// tag assignment is OK.
if (this.getLocalTag() != null && from.getTag() != null && !from.getTag().equals(this.getLocalTag()))
throw new SipException("From tag mismatch expecting " + this.getLocalTag());
if (this.getRemoteTag() != null && to.getTag() != null && !to.getTag().equals(this.getRemoteTag())) {
if (sipStack.isLoggingEnabled())
this.sipStack.getStackLogger().logWarning("To header tag mismatch expecting " + this.getRemoteTag());
}
/*
* The application is sending a NOTIFY before sending the response of the dialog.
*/
if (this.getLocalTag() == null && dialogRequest.getMethod().equals(Request.NOTIFY)) {
if (!this.getMethod().equals(Request.SUBSCRIBE))
throw new SipException("Trying to send NOTIFY without SUBSCRIBE Dialog!");
this.setLocalTag(from.getTag());
}
try {
if (this.getLocalTag() != null)
from.setTag(this.getLocalTag());
if (this.getRemoteTag() != null)
to.setTag(this.getRemoteTag());
} catch (ParseException ex) {
InternalErrorHandler.handleException(ex);
}
Hop hop = ((SIPClientTransaction) clientTransactionId).getNextHop();
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("Using hop = " + hop.getHost() + " : " + hop.getPort());
}
try {
MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(hop.getTransport()).getIPAddress(), this.firstTransactionPort, hop);
MessageChannel oldChannel = ((SIPClientTransaction) clientTransactionId).getMessageChannel();
// Remove this from the connection cache if it is in the
// connection
// cache and is not yet active.
oldChannel.uncache();
// Not configured to cache client connections.
if (!sipStack.cacheClientConnections) {
oldChannel.useCount--;
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("oldChannel: useCount " + oldChannel.useCount);
}
if (messageChannel == null) {
/*
* At this point the procedures of 8.1.2 and 12.2.1.1 of RFC3261 have been tried
* but the resulting next hop cannot be resolved (recall that the exception thrown
* is caught and ignored in SIPStack.createMessageChannel() so we end up here with
* a null messageChannel instead of the exception handler below). All else
* failing, try the outbound proxy in accordance with 8.1.2, in particular: This
* ensures that outbound proxies that do not add Record-Route header field values
* will drop out of the path of subsequent requests. It allows endpoints that
* cannot resolve the first Route URI to delegate that task to an outbound proxy.
*
* if one considers the 'first Route URI' of a request constructed according to
* 12.2.1.1 to be the request URI when the route set is empty.
*/
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Null message channel using outbound proxy !");
Hop outboundProxy = sipStack.getRouter(dialogRequest).getOutboundProxy();
if (outboundProxy == null)
throw new SipException("No route found! hop=" + hop);
messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(outboundProxy.getTransport()).getIPAddress(), this.firstTransactionPort, outboundProxy);
if (messageChannel != null)
((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
} else {
((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("using message channel " + messageChannel);
}
}
if (messageChannel != null)
messageChannel.useCount++;
// See if we need to release the previously mapped channel.
if ((!sipStack.cacheClientConnections) && oldChannel != null && oldChannel.useCount <= 0)
oldChannel.close();
} catch (Exception ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logException(ex);
throw new SipException("Could not create message channel", ex);
}
try {
// Increment before setting!!
localSequenceNumber++;
dialogRequest.getCSeq().setSeqNumber(getLocalSeqNumber());
} catch (InvalidArgumentException ex) {
sipStack.getStackLogger().logFatalError(ex.getMessage());
}
try {
((SIPClientTransaction) clientTransactionId).sendMessage(dialogRequest);
/*
* Note that if the BYE is rejected then the Dialog should bo back to the ESTABLISHED
* state so we only set state after successful send.
*/
if (dialogRequest.getMethod().equals(Request.BYE)) {
this.byeSent = true;
/*
* Dialog goes into TERMINATED state as soon as BYE is sent. ISSUE 182.
*/
if (isTerminatedOnBye()) {
this.setState(DialogState._TERMINATED);
}
}
} catch (IOException ex) {
throw new SipException("error sending message", ex);
}
}
use of javax.sip.SipException in project Openfire by igniterealtime.
the class SimpleSession method sendNotify.
public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
Request notifyRequest = prepareNotifyRequest(dialog);
try {
User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
String presenceContent;
SimplePresence simplePresence = new SimplePresence();
simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
simplePresence.setDmNote(myPresence.getStatus());
if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
else {
simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
if (myPresence.getShow() != null) {
switch(myPresence.getShow()) {
case away:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
case dnd:
simplePresence.setRpid(SimplePresence.Rpid.BUSY);
break;
case xa:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
default:
break;
}
}
}
presenceContent = simplePresence.toXML();
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
notifyRequest.setContent(presenceContent, contentTypeHeader);
} catch (Exception e) {
Log.debug("Unable to include presence details in the packet.", e);
}
sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SipHelper method sendReinvite.
public ClientTransaction sendReinvite(Dialog dialog, String sessionDescription) throws SipException {
try {
Request request = dialog.createRequest(Request.INVITE);
request.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
// Adding rport argument in the request could fix some SIP servers
// in resolving the initiator's NAT port mapping for relaying the
// response message from the other end.
ViaHeader viaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
if (viaHeader != null)
viaHeader.setRPort();
ClientTransaction clientTransaction = mSipProvider.getNewClientTransaction(request);
if (DEBUG)
Log.d(TAG, "send RE-INVITE: " + request);
dialog.sendRequest(clientTransaction);
return clientTransaction;
} catch (ParseException e) {
throw new SipException("sendReinvite()", e);
}
}
Aggregations