use of javax.sip.message.Response in project Spark by igniterealtime.
the class CallProcessing method processInvite.
// -------------------------- Requests ---------------------------------
void processInvite(ServerTransaction serverTransaction, Request invite) {
Dialog dialog = serverTransaction.getDialog();
if (!sipManCallback.isBusy() && !(PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator())) {
Call call = callDispatcher.createCall(dialog, invite);
sipManCallback.fireCallReceived(call);
// change status
call.setState(Call.ALERTING);
// sdp description may be in acks - bug report Laurent Michel
ContentLengthHeader cl = invite.getContentLength();
if (cl != null && cl.getContentLength() > 0) {
call.setRemoteSdpDescription(new String(invite.getRawContent()));
}
// Are we the one they are looking for?
URI calleeURI = ((ToHeader) invite.getHeader(ToHeader.NAME)).getAddress().getURI();
/**
* @todo We shoud rather ask the user what to do here as some
* would add prefixes or change user URIs
*/
if (calleeURI.isSipURI()) {
boolean assertUserMatch = SIPConfig.isFailCallInUserMismatch();
// user info is case sensitive according to rfc3261
if (assertUserMatch) {
String calleeUser = ((SipURI) calleeURI).getUser();
String localUser = sipManCallback.getLocalUser();
if (calleeUser != null && !calleeUser.equals(localUser)) {
sipManCallback.fireCallRejectedLocally("The user specified by the caller did not match the local user!", invite, call);
call.setState(Call.DISCONNECTED);
Response notFound = null;
try {
notFound = sipManCallback.messageFactory.createResponse(Response.NOT_FOUND, invite);
sipManCallback.attachToTag(notFound, dialog);
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a NOT_FOUND response to an INVITE request!", ex));
return;
}
try {
serverTransaction.sendResponse(notFound);
} catch (SipException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", ex));
return;
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
return;
}
return;
}
}
}
// Send RINGING
Response ringing = null;
try {
ringing = sipManCallback.messageFactory.createResponse(Response.RINGING, invite);
sipManCallback.attachToTag(ringing, dialog);
} catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a RINGING response to an INVITE request!", ex));
return;
}
try {
serverTransaction.sendResponse(ringing);
} catch (SipException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", ex));
return;
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
return;
}
} else {
// Send BUSY_HERE
Response busy = null;
try {
busy = sipManCallback.messageFactory.createResponse(Response.BUSY_HERE, invite);
sipManCallback.attachToTag(busy, dialog);
} catch (ParseException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a RINGING response to an INVITE request!", ex));
return;
}
try {
serverTransaction.sendResponse(busy);
} catch (SipException ex) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", ex));
return;
} catch (InvalidArgumentException e) {
sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", e));
return;
}
}
}
use of javax.sip.message.Response 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.message.Response 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));
}
}
use of javax.sip.message.Response in project Spark by igniterealtime.
the class SipManager method processResponse.
// -------------------- PROCESS RESPONSE
public void processResponse(ResponseEvent responseReceivedEvent) {
Log.debug("<RESPONSE>");
Log.debug("[" + responseReceivedEvent.getResponse().getStatusCode() + "]");
Log.debug("</RESPONSE>");
ClientTransaction clientTransaction = responseReceivedEvent.getClientTransaction();
if (clientTransaction == null) {
return;
}
Response response = responseReceivedEvent.getResponse();
// TODO REMOVE
@SuppressWarnings("unused") Dialog dialog = clientTransaction.getDialog();
String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
// TODO REMOVE
@SuppressWarnings("unused") Response responseClone = (Response) response.clone();
// OK
if (response.getStatusCode() == Response.OK) {
// REGISTER
if (method.equals(Request.REGISTER)) {
registerProcessing.processOK(clientTransaction, response);
} else // INVITE
if (method.equals(Request.INVITE)) {
callProcessing.processInviteOK(clientTransaction, response);
} else // BYE
if (method.equals(Request.BYE)) {
callProcessing.processByeOK(clientTransaction, response);
} else // CANCEL
if (method.equals(Request.CANCEL)) {
callProcessing.processCancelOK(clientTransaction, response);
} else if (method.equals(Request.SUBSCRIBE)) {
}
} else // SESSION PROGRESS
if (response.getStatusCode() == Response.SESSION_PROGRESS) {
callProcessing.processRingingBack(clientTransaction, response);
} else // ACCEPTED
if (response.getStatusCode() == Response.ACCEPTED) {
// SUBSCRIBE
if (method.equals(Request.SUBSCRIBE)) {
} else if (method.equals(Request.REFER)) {
Call call = callProcessing.getCallDispatcher().findCall(clientTransaction.getDialog());
try {
callProcessing.endCall(call);
} catch (CommunicationsException e) {
Log.error("Trasnfer", e);
}
}
} else // report and fix - Asa Karlsson
if (response.getStatusCode() == Response.RINGING) {
if (method.equals(Request.INVITE)) {
callProcessing.processRinging(clientTransaction, response);
} else {
fireUnknownMessageReceived(response);
}
} else // TRYING
if (response.getStatusCode() == Response.TRYING || // reported by Les Roger Davis
response.getStatusCode() / 100 == 1) {
if (method.equals(Request.INVITE)) {
callProcessing.processTrying(clientTransaction, response);
} else // Luis Vazquez <luis at teledata.com.uy>
if (method.equals(Request.REGISTER)) {
// do nothing
} else {
// TODO TRYING // fireUnknownMessageReceived(response);
}
} else // NOT_FOUND
if (response.getStatusCode() == Response.NOT_FOUND) {
if (method.equals(Request.INVITE)) {
callProcessing.processNotFound(clientTransaction, response);
}
if (method.equals(Request.SUBSCRIBE)) {
} else if (method.equals(Request.REGISTER)) {
fireRegistrationFailed("Invalid username.", RegistrationEvent.Type.NotFound);
Log.debug("REGISTER NOT FOUND");
}
} else // NOT_IMPLEMENTED
if (response.getStatusCode() == Response.NOT_IMPLEMENTED) {
if (method.equals(Request.REGISTER)) {
// Fixed typo issues - Reported by pizarro
registerProcessing.processNotImplemented(clientTransaction, response);
} else if (method.equals(Request.INVITE)) {
callProcessing.processNotImplemented(clientTransaction, response);
} else {
fireUnknownMessageReceived(response);
}
} else // REQUEST_TERMINATED
if (response.getStatusCode() == Response.REQUEST_TERMINATED) {
callProcessing.processRequestTerminated(clientTransaction, response);
} else // BUSY_HERE
if (response.getStatusCode() == Response.BUSY_HERE) {
if (method.equals(Request.INVITE)) {
callProcessing.processBusyHere(clientTransaction, response);
} else {
fireUnknownMessageReceived(response);
}
} else // 401 UNAUTHORIZED
if (response.getStatusCode() == Response.UNAUTHORIZED || response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED) {
if (method.equals(Request.INVITE)) {
callProcessing.processAuthenticationChallenge(clientTransaction, response);
} else if (method.equals(Request.REGISTER)) {
// TODO REMOVE
@SuppressWarnings("unused") CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
registerProcessing.processAuthenticationChallenge(clientTransaction, response);
loginfailed++;
if (loginfailed < 3)
Log.debug("Removed");
else
fireRegistrationFailed("Invalid password.", RegistrationEvent.Type.WrongPass);
} else if (method.equals(Request.SUBSCRIBE)) {
} else
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.FORBIDDEN) {
} else if (response.getStatusCode() == 403) {
// Wrong Authorization User
fireRegistrationFailed("Invalid auth user.", RegistrationEvent.Type.WrongAuthUser);
} else // Other Errors
if (// || response.getStatusCode() == Response.SESSION_NOT_ACCEPTABLE
response.getStatusCode() / 100 == 4) {
if (method.equals(Request.INVITE)) {
callProcessing.processCallError(clientTransaction, response);
} else {
fireUnknownMessageReceived(response);
}
} else if (response.getStatusCode() == Response.ACCEPTED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.ADDRESS_INCOMPLETE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.ALTERNATIVE_SERVICE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.AMBIGUOUS) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.BAD_EVENT) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.BAD_EXTENSION) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.BAD_GATEWAY) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.BAD_REQUEST) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.BUSY_EVERYWHERE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.CALL_IS_BEING_FORWARDED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST) {
/**
* @todo add proper request handling
*/
// fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.DECLINE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.DOES_NOT_EXIST_ANYWHERE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.EXTENSION_REQUIRED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.GONE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.INTERVAL_TOO_BRIEF) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.LOOP_DETECTED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.MESSAGE_TOO_LARGE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.METHOD_NOT_ALLOWED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.MOVED_PERMANENTLY) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.MOVED_TEMPORARILY) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.MULTIPLE_CHOICES) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.NOT_ACCEPTABLE_HERE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.PAYMENT_REQUIRED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.QUEUED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.REQUEST_ENTITY_TOO_LARGE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.REQUEST_PENDING) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.REQUEST_TIMEOUT) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.REQUEST_URI_TOO_LONG) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else // Contorno para falha na plataforma
if (response.getStatusCode() == Response.SERVER_INTERNAL_ERROR) {
//
} else if (response.getStatusCode() == Response.SERVER_TIMEOUT) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.SERVICE_UNAVAILABLE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.SESSION_NOT_ACCEPTABLE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.SESSION_PROGRESS) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.TEMPORARILY_UNAVAILABLE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.TOO_MANY_HOPS) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.UNDECIPHERABLE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.UNSUPPORTED_MEDIA_TYPE) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.UNSUPPORTED_URI_SCHEME) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.USE_PROXY) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else if (response.getStatusCode() == Response.VERSION_NOT_SUPPORTED) {
/**
* @todo add proper request handling
*/
fireUnknownMessageReceived(response);
} else {
// We couldn't recognise the message
fireUnknownMessageReceived(response);
}
}
use of javax.sip.message.Response in project Spark by igniterealtime.
the class SipManager method sendNotImplemented.
// answer to
/**
* 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 = null;
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));
} catch (InvalidArgumentException e) {
fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", e));
}
}
Aggregations