use of javax.sip.ServerTransaction in project smscgateway by RestComm.
the class TxSipServerSbb method onMESSAGE.
// *********
// SIP Event Handlers
public void onMESSAGE(javax.sip.RequestEvent event, ActivityContextInterface aci) {
if (this.logger.isFineEnabled()) {
this.logger.fine("onMESSAGE " + event);
}
Sip sip = sipManagement.getSipByName(SipManagement.SIP_NAME);
try {
final Request request = event.getRequest();
byte[] message = request.getRawContent();
final ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
final String toUser = ((SipUri) toHeader.getAddress().getURI()).getUser();
final FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
final String fromUser = ((SipUri) fromHeader.getAddress().getURI()).getUser();
// Persist this message
TargetAddress ta = this.createDestTargetAddress(toUser, sip.getNetworkId());
byte[] udh = null;
Header udhHeader = request.getHeader(SipXHeaders.XSmsUdh);
if (udhHeader != null) {
udh = this.hexStringToByteArray(((SIPHeader) udhHeader).getValue());
}
Header codingHeader = request.getHeader(SipXHeaders.XSmsCoding);
DataCodingSchemeImpl codingSchme = dcsGsm7;
if (codingHeader != null) {
int dcs = Integer.parseInt(((SIPHeader) codingHeader).getValue());
codingSchme = this.createDataCodingScheme(dcs);
}
Date validityPeriod = null;
Header validityHeader = request.getHeader(SipXHeaders.XSmsValidty);
if (validityHeader != null) {
try {
validityPeriod = MessageUtil.parseDate(((SIPHeader) validityHeader).getValue());
} catch (ParseException e) {
logger.severe("ParseException when parsing ValidityPeriod field: " + e.getMessage(), e);
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e.getMessage(), true);
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e1) {
this.logger.severe("Exception while trying to send 500 response to sip", e1);
}
return;
}
}
// Registered Delivery
int regDeliveryInt = 0;
Header regDeliveryHeader = request.getHeader(SipXHeaders.XRegDelivery);
if (regDeliveryHeader != null) {
regDeliveryInt = Integer.parseInt(((SIPHeader) regDeliveryHeader).getValue());
}
Sms sms = null;
try {
sms = this.createSmsEvent(fromUser, message, ta, persistence, udh, codingSchme, validityPeriod, regDeliveryInt, sip.getNetworkId());
this.processSms(sms, persistence);
} catch (SmscProcessingException e1) {
if (!e1.isSkipErrorLogging()) {
if (e1.isIsWarning()) {
this.logger.warning(e1.getMessage());
} else {
this.logger.severe(e1.getMessage(), e1);
}
smscStatAggregator.updateMsgInFailedAll();
}
if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
if (sms != null) {
generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), false, true);
} else {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
}
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
return;
} catch (Throwable e1) {
this.logger.severe("Exception while processing a message from sip", e1);
smscStatAggregator.updateMsgInFailedAll();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
// TODO: we possibly need to response ERROR message to sip
res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
return;
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
} catch (Exception e) {
this.logger.severe("Error while trying to process received the SMS " + event, e);
}
}
use of javax.sip.ServerTransaction 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.ServerTransaction 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.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processRefer.
public void processRefer(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
logger.info("shootist: got a refer . ServerTxId = " + serverTransactionId);
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
inviteServerTid = st;
Dialog dialog = st.getDialog();
this.dialogCount++;
this.dialog = dialog;
logger.info("Shootme: dialog = " + dialog);
Response response = protocolObjects.messageFactory.createResponse(referResponseToSend, request);
sipETag = Integer.toString(new Random().nextInt(10000000));
st.sendResponse(response);
logger.info("shootist: Sending " + referResponseToSend);
List<Header> headers = new ArrayList<Header>();
EventHeader eventHeader = (EventHeader) protocolObjects.headerFactory.createHeader(EventHeader.NAME, "Refer");
headers.add(eventHeader);
if (sendNotifyForRefer) {
if (!referReceived) {
referReceived = true;
SubscriptionStateHeader subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "active;expires=3600");
headers.add(subscriptionStateHeader);
allMessagesContent.add("SIP/2.0 100 Trying");
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 100 Trying", "message", "sipfrag;version=2.0", headers, null);
Thread.sleep(1000);
headers.remove(subscriptionStateHeader);
subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "terminated;reason=noresource");
headers.add(subscriptionStateHeader);
if (inviteRequest == null) {
ExtensionHeader extensionHeader = (ExtensionHeader) protocolObjects.headerFactory.createHeader("Out-Of-Dialog", "true");
headers.add(extensionHeader);
}
allMessagesContent.add("SIP/2.0 200 OK");
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 200 OK", "message", "sipfrag;version=2.0", headers, null);
} else {
SubscriptionStateHeader subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "active;expires=3600");
headers.add(subscriptionStateHeader);
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 100 Subsequent", "message", "sipfrag;version=2.0", headers, null);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processRequest.
public void processRequest(RequestEvent requestReceivedEvent) {
if (abortProcessing) {
logger.error("Processing aborted");
return;
}
Request request = requestReceivedEvent.getRequest();
eventListener.uasAfterRequestReceived(request.getMethod(), appServer);
if (firstRequest == null)
firstRequest = request;
ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
logger.info("\n\nRequest " + request.getMethod() + " received at " + protocolObjects.sipStack.getStackName() + " with server transaction id " + serverTransactionId + " dialog " + requestReceivedEvent.getDialog());
if (request.getMethod().equals(Request.INVITE)) {
processInvite(requestReceivedEvent, serverTransactionId);
}
if (request.getMethod().equals(Request.BYE)) {
processBye(request, serverTransactionId);
}
if (request.getMethod().equals(Request.ACK)) {
processAck(request, serverTransactionId);
}
if (request.getMethod().equals(Request.PRACK)) {
processPrack(request, serverTransactionId);
}
if (request.getMethod().equals(Request.CANCEL)) {
processCancel(requestReceivedEvent, serverTransactionId);
}
if (request.getMethod().equals(Request.MESSAGE)) {
processMessage(request, serverTransactionId);
}
if (request.getMethod().equals(Request.REGISTER)) {
processRegister(request, serverTransactionId);
}
if (request.getMethod().equals(Request.NOTIFY)) {
processNotify(requestReceivedEvent, serverTransactionId);
}
if (request.getMethod().equals(Request.SUBSCRIBE)) {
processSubscribe(requestReceivedEvent, serverTransactionId);
}
if (request.getMethod().equals(Request.UPDATE)) {
processUpdate(request, serverTransactionId);
}
if (request.getMethod().equals(Request.PUBLISH)) {
processPublish(requestReceivedEvent, serverTransactionId);
}
if (request.getMethod().equals(Request.REFER)) {
processRefer(requestReceivedEvent, serverTransactionId);
}
}
Aggregations