use of javax.sip.InvalidArgumentException 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.InvalidArgumentException in project Spark by igniterealtime.
the class CallProcessing method invite.
// -------------------------------- User Initiated processing
// ---------------------------------
Call invite(String callee, String sdpContent) throws CommunicationsException {
callee = callee.trim();
// Remove excessive characters from phone numbers such as '
// ','(',')','-'
String excessiveChars = SIPConfig.getExcessiveURIChar();
if (excessiveChars != null) {
StringBuffer calleeBuff = new StringBuffer(callee);
for (int i = 0; i < excessiveChars.length(); i++) {
String charToDeleteStr = excessiveChars.substring(i, i + 1);
int charIndex = -1;
while ((charIndex = calleeBuff.indexOf(charToDeleteStr)) != -1) calleeBuff.delete(charIndex, charIndex + 1);
}
callee = calleeBuff.toString();
}
// Handle default domain name (i.e. transform 1234 -> 1234@sip.com
String defaultDomainName = SIPConfig.getDefaultDomain();
if (// no sip scheme
defaultDomainName != null && !callee.trim().startsWith("tel:") && // most probably a sip uri
callee.indexOf('@') == -1) {
callee = callee + "@" + defaultDomainName;
}
// Let's be uri fault tolerant
if (// no sip scheme
callee.toLowerCase().indexOf("sip:") == -1 && // most probably a sip uri
callee.indexOf('@') != -1) {
callee = "sip:" + callee;
}
// Request URI
URI requestURI;
try {
requestURI = sipManCallback.addressFactory.createURI(callee);
} catch (ParseException ex) {
throw new CommunicationsException(callee + " is not a legal SIP uri!", ex);
}
// Call ID
CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
// CSeq
CSeqHeader cSeqHeader;
try {
cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1L, Request.INVITE);
} catch (ParseException ex) {
throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
} catch (InvalidArgumentException ex) {
// Shouldn't happen
throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
}
// FromHeader
FromHeader fromHeader = sipManCallback.getFromHeader();
// ToHeader
Address toAddress = sipManCallback.addressFactory.createAddress(requestURI);
ToHeader toHeader;
try {
toHeader = sipManCallback.headerFactory.createToHeader(toAddress, null);
} catch (ParseException ex) {
// Shouldn't happen
throw new CommunicationsException("Null is not an allowed tag for the to header!", ex);
}
// ViaHeaders
ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
// MaxForwards
MaxForwardsHeader maxForwards = sipManCallback.getMaxForwardsHeader();
// Contact
ContactHeader contactHeader = sipManCallback.getContactHeader();
Request invite = null;
try {
invite = sipManCallback.messageFactory.createRequest(requestURI, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
} catch (ParseException ex) {
throw new CommunicationsException("Failed to create invite Request!", ex);
}
//
invite.addHeader(contactHeader);
AllowHeader allow = null;
try {
allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
invite.addHeader(allow);
} catch (ParseException e) {
Log.error(e);
}
// 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
throw new CommunicationsException("Failed to create a content type header for the INVITE request", ex);
}
try {
invite.setContent(sdpContent, contentTypeHeader);
} catch (ParseException ex) {
throw new CommunicationsException("Failed to parse sdp data while creating invite request!", ex);
}
// Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(invite);
} catch (TransactionUnavailableException ex) {
throw new CommunicationsException("Failed to create inviteTransaction.\n" + "This is most probably a network connection error.", ex);
}
try {
inviteTransaction.sendRequest();
} catch (SipException ex) {
throw new CommunicationsException("An error occurred while sending invite request", ex);
}
Call call = callDispatcher.createCall(inviteTransaction.getDialog(), invite);
call.setState(Call.DIALING);
return call;
}
use of javax.sip.InvalidArgumentException in project Spark by igniterealtime.
the class RegisterProcessing method register.
synchronized void register(String registrarAddress, int registrarPort, String registrarTransport, int expires) throws CommunicationsException {
try {
isUnregistering = false;
// From
FromHeader fromHeader = sipManCallback.getFromHeader(true);
Address fromAddress = fromHeader.getAddress();
sipManCallback.fireRegistering(fromAddress.toString());
// Request URI
SipURI requestURI = null;
try {
requestURI = sipManCallback.addressFactory.createSipURI(null, registrarAddress);
} catch (ParseException ex) {
throw new CommunicationsException("Bad registrar address:" + registrarAddress, ex);
} catch (NullPointerException ex) {
// Do not throw an exc, we should rather silently notify the
// user
// throw new CommunicationsException("A registrar address was
// not specified!", ex);
sipManCallback.fireUnregistered(fromAddress.getURI().toString() + " (registrar not specified)");
return;
}
/*
requestURI.setPort(registrarPort);
try {
requestURI.setTransportParam(registrarTransport);
}
catch (ParseException ex) {
throw new CommunicationsException(registrarTransport
+ " is not a valid transport!", ex);
}
*/
// Call ID Header
CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
// CSeq Header
CSeqHeader cSeqHeader = null;
try {
cSeqHeader = sipManCallback.headerFactory.createCSeqHeader((long) 1, Request.REGISTER);
} catch (ParseException ex) {
// Should never happen
Log.error("register", ex);
} catch (InvalidArgumentException ex) {
// Should never happen
Log.error("register", ex);
}
// To Header
ToHeader toHeader = null;
try {
toHeader = sipManCallback.headerFactory.createToHeader(fromAddress, null);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
}
// User Agent Header
UserAgentHeader uaHeader = null;
ArrayList<String> userAgentList = new ArrayList<String>();
userAgentList.add(SoftPhoneManager.userAgent);
try {
uaHeader = sipManCallback.headerFactory.createUserAgentHeader(userAgentList);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
}
// Via Headers
ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
// MaxForwardsHeader
MaxForwardsHeader maxForwardsHeader = sipManCallback.getMaxForwardsHeader();
// Request
Request request = null;
try {
request = sipManCallback.messageFactory.createRequest(requestURI, Request.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
request.setHeader(uaHeader);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create the register request!", ex);
}
// Expires Header
ExpiresHeader expHeader = null;
for (int retry = 0; retry < 2; retry++) {
try {
expHeader = sipManCallback.headerFactory.createExpiresHeader(expires);
} catch (InvalidArgumentException ex) {
if (retry == 0) {
expires = 3600;
continue;
}
throw new CommunicationsException("Invalid registrations expiration parameter - " + expires, ex);
}
}
request.addHeader(expHeader);
// Contact Header should contain IP - bug report - Eero Vaarnas
ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
request.addHeader(contactHeader);
AllowHeader allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
request.addHeader(allow);
// Transaction
ClientTransaction regTrans = null;
try {
regTrans = sipManCallback.sipProvider.getNewClientTransaction(request);
} catch (TransactionUnavailableException ex) {
throw new CommunicationsException("Could not create a register transaction!\n" + "Check that the Registrar address is correct!");
}
try {
regTrans.sendRequest();
}// we sometimes get a null pointer exception here so catch them all
catch (Exception ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not send out the register request!", ex);
}
this.registerRequest = request;
} catch (Exception e) {
Log.error("register", e);
sipManCallback.fireRegistrationFailed(registrarAddress == null ? "" : registrarAddress, RegistrationEvent.Type.TimeOut);
}
}
use of javax.sip.InvalidArgumentException 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));
}
}
use of javax.sip.InvalidArgumentException in project load-balancer by RestComm.
the class BackToBackUserAgent method forwardResponse.
private void forwardResponse(ResponseEvent receivedResponse) throws SipException {
try {
ServerTransaction serverTransaction = (ServerTransaction) receivedResponse.getClientTransaction().getApplicationData();
Request stRequest = serverTransaction.getRequest();
Response newResponse = this.messageFactory.createResponse(receivedResponse.getResponse().getStatusCode(), stRequest);
ListeningPoint peerListeningPoint = sp.getListeningPoint(transport);
ContactHeader peerContactHeader = ((ListeningPointExt) peerListeningPoint).createContactHeader();
newResponse.setHeader(peerContactHeader);
serverTransaction.sendResponse(newResponse);
} catch (InvalidArgumentException e) {
throw new SipException("invalid response", e);
} catch (ParseException e) {
throw new SipException("invalid response", e);
}
}
Aggregations