use of javax.sip.Transaction in project Spark by igniterealtime.
the class SipManager method processTimeout.
public void processTimeout(TimeoutEvent transactionTimeOutEvent) {
Transaction transaction;
if (transactionTimeOutEvent.isServerTransaction()) {
transaction = transactionTimeOutEvent.getServerTransaction();
} else {
transaction = transactionTimeOutEvent.getClientTransaction();
}
Request request = transaction.getRequest();
if (request.getMethod().equals(Request.REGISTER)) {
registerProcessing.processTimeout(transaction, request);
} else if (request.getMethod().equals(Request.INVITE)) {
callProcessing.processTimeout(transaction, request);
} else {
// Just show an error for now
}
}
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);
}
}
use of javax.sip.Transaction in project Spark by igniterealtime.
the class CallProcessing method processCancel.
void processCancel(ServerTransaction serverTransaction, Request cancelRequest) {
if (!serverTransaction.getDialog().getFirstTransaction().getRequest().getMethod().equals(Request.INVITE)) {
return;
}
// find the call
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(cancelRequest);
return;
}
// change status
call.setState(Call.DISCONNECTED);
// (report and fix by Ranga)
try {
Response ok = sipManCallback.messageFactory.createResponse(Response.OK, cancelRequest);
sipManCallback.attachToTag(ok, call.getDialog());
serverTransaction.sendResponse(ok);
} catch (ParseException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create an OK Response to an CANCEL request.", ex));
} catch (SipException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send an OK Response to an CANCEL request.", ex));
} catch (InvalidArgumentException e) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
}
try {
// stop the invite transaction as well
Transaction tran = call.getDialog().getFirstTransaction();
// filtered by the stack but it doesn't hurt checking anyway
if (!(tran instanceof ServerTransaction)) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Received a misplaced CANCEL request!"));
return;
}
ServerTransaction inviteTran = (ServerTransaction) tran;
Request invite = call.getDialog().getFirstTransaction().getRequest();
Response requestTerminated = sipManCallback.messageFactory.createResponse(Response.REQUEST_TERMINATED, invite);
sipManCallback.attachToTag(requestTerminated, call.getDialog());
inviteTran.sendResponse(requestTerminated);
} catch (ParseException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a REQUEST_TERMINATED Response to an INVITE request.", ex));
} catch (SipException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send an REQUEST_TERMINATED Response to an INVITE request.", ex));
} catch (InvalidArgumentException e) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
}
}
Aggregations