use of javax.sip.Transaction in project Spark by igniterealtime.
the class CallProcessing method sayOK.
// busy here
// ------------------ say ok
public void sayOK(int callID, String sdpContent) throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
if (call == null) {
throw new CommunicationsException("Failed to find call with id=" + callID);
}
if (!call.isIncoming())
return;
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to extract call's associated dialog! Ending Call!");
}
Transaction transaction = dialog.getFirstTransaction();
if (transaction == null || !dialog.isServer()) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to extract a ServerTransaction " + "from the call's associated dialog!");
}
ServerTransaction serverTransaction = (ServerTransaction) transaction;
Response ok = null;
try {
ok = sipManCallback.messageFactory.createResponse(Response.OK, dialog.getFirstTransaction().getRequest());
sipManCallback.attachToTag(ok, dialog);
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to construct an OK response to an INVITE request", ex);
}
// Content
ContentTypeHeader contentTypeHeader = null;
try {
// content type should be application/sdp (not applications)
// reported by Oleg Shevchenko (Miratech)
contentTypeHeader = sipManCallback.headerFactory.createContentTypeHeader("application", "sdp");
} catch (ParseException ex) {
// Shouldn't happen
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to create a content type header for the OK request", ex);
}
try {
ok.setContent(sdpContent, contentTypeHeader);
} catch (NullPointerException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("No sdp data was provided for the ok response to an INVITE request!", ex);
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to parse sdp data while creating invite request!", ex);
}
// and should probably be removed
if (((ToHeader) ok.getHeader(ToHeader.NAME)).getTag() == null) {
try {
((ToHeader) ok.getHeader(ToHeader.NAME)).setTag(Integer.toString(dialog.hashCode()));
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Unable to set to tag", ex);
}
}
ContactHeader contactHeader = sipManCallback.getContactHeader();
ok.addHeader(contactHeader);
try {
serverTransaction.sendResponse(ok);
} catch (SipException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to send an OK response to an INVITE request", ex);
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
}
}
use of javax.sip.Transaction in project load-balancer by RestComm.
the class SIPBalancerForwarder method processTimeout.
/*
* (non-Javadoc)
* @see javax.sip.SipListener#processTimeout(javax.sip.TimeoutEvent)
*/
public void processTimeout(TimeoutEvent timeoutEvent) {
Transaction transaction = null;
if (timeoutEvent.isServerTransaction()) {
transaction = timeoutEvent.getServerTransaction();
if (logger.isDebugEnabled()) {
logger.debug("timeout => " + transaction.getRequest().toString());
}
} else {
transaction = timeoutEvent.getClientTransaction();
if (logger.isDebugEnabled()) {
logger.debug("timeout => " + transaction.getRequest().toString());
}
}
String callId = ((CallIdHeader) transaction.getRequest().getHeader(CallIdHeader.NAME)).getCallId();
register.unStickSessionFromNode(callId);
}
use of javax.sip.Transaction in project XobotOS by xamarin.
the class SipProviderImpl method transactionErrorEvent.
/**
* Invoked when an error has ocurred with a transaction. Propagate up to the
* listeners.
*
* @param transactionErrorEvent
* Error event.
*/
public void transactionErrorEvent(SIPTransactionErrorEvent transactionErrorEvent) {
SIPTransaction transaction = (SIPTransaction) transactionErrorEvent.getSource();
if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TRANSPORT_ERROR) {
// There must be a way to inform the TU here!!
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("TransportError occured on " + transaction);
}
// Treat this like a timeout event. (Suggestion from Christophe).
Object errorObject = transactionErrorEvent.getSource();
Timeout timeout = Timeout.TRANSACTION;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
Hop hop = clientTx.getNextHop();
if (sipStack.getRouter() instanceof RouterExt) {
((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
}
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
// Handling transport error like timeout
this.handleEvent(ev, (SIPTransaction) errorObject);
} else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_ERROR) {
// This is a timeout event.
Object errorObject = transactionErrorEvent.getSource();
Timeout timeout = Timeout.TRANSACTION;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
Hop hop = clientTx.getNextHop();
if (sipStack.getRouter() instanceof RouterExt) {
((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
}
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
this.handleEvent(ev, (SIPTransaction) errorObject);
} else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_RETRANSMIT) {
// This is a timeout retransmit event.
// We should never get this if retransmit filter is
// enabled (ie. in that case the stack should handle.
// all retransmits.
Object errorObject = transactionErrorEvent.getSource();
Transaction tx = (Transaction) errorObject;
if (tx.getDialog() != null)
InternalErrorHandler.handleException("Unexpected event !", this.sipStack.getStackLogger());
Timeout timeout = Timeout.RETRANSMIT;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
this.handleEvent(ev, (SIPTransaction) errorObject);
}
}
use of javax.sip.Transaction 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.Transaction in project Spark by igniterealtime.
the class CallProcessing method sayInternalError.
// answer call
// ------------------ Internal Error
void sayInternalError(int callID) throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
if (call == null) {
throw new CommunicationsException("Failed to find call with id=" + callID);
}
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to extract call's associated dialog! Ending Call!");
}
Transaction transaction = dialog.getFirstTransaction();
if (transaction == null || !dialog.isServer()) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to extract a transaction from the call's associated dialog!");
}
ServerTransaction serverTransaction = (ServerTransaction) transaction;
Response internalError = null;
try {
internalError = sipManCallback.messageFactory.createResponse(Response.SERVER_INTERNAL_ERROR, dialog.getFirstTransaction().getRequest());
sipManCallback.attachToTag(internalError, dialog);
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to construct an OK response to an INVITE request", ex);
}
ContactHeader contactHeader = sipManCallback.getContactHeader();
internalError.addHeader(contactHeader);
try {
serverTransaction.sendResponse(internalError);
} catch (SipException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to send an OK response to an INVITE request", ex);
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Failed to send an OK response to an INVITE request", e);
}
}
Aggregations