use of javax.sip.ServerTransaction 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.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processRegister.
private void processRegister(Request request, ServerTransaction serverTransactionId) {
try {
registerReceived = request;
ServerTransaction serverTransaction = serverTransactionId == null ? sipProvider.getNewServerTransaction(request) : serverTransactionId;
lastRegisterCSeqNumber = ((CSeqHeader) request.getHeader("CSeq")).getSeqNumber();
Response okResponse = protocolObjects.messageFactory.createResponse(Response.OK, request);
ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
if (toHeader.getTag() == null) {
toHeader.setTag(Integer.toString(new Random().nextInt(10000000)));
}
// okResponse.addHeader(contactHeader);
serverTransaction.sendResponse(okResponse);
} catch (Exception ex) {
ex.printStackTrace();
logger.error("error sending OK response to message", ex);
}
}
use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class Shootist method processRequest.
public void processRequest(RequestEvent requestReceivedEvent) {
Request request = requestReceivedEvent.getRequest();
requests.add(request);
ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
if (serverTransactionId == null) {
try {
serverTransactionId = sipProvider.getNewServerTransaction(request);
} catch (TransactionAlreadyExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransactionUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("\n\nRequest " + request.getMethod() + " received at " + sipStack.getStackName() + " with server transaction id " + serverTransactionId);
if (request.getMethod().equals(Request.INVITE)) {
processInvite(request, serverTransactionId);
} else if (request.getMethod().equals(Request.BYE)) {
processBye(request, serverTransactionId);
} else if (request.getMethod().equals(Request.ACK)) {
processAck(request, serverTransactionId);
} else {
try {
serverTransactionId.sendResponse(messageFactory.createResponse(200, request));
} catch (Exception e) {
e.printStackTrace();
fail("Unxepcted exception ");
}
}
}
use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class Shootist method processRequest.
public void processRequest(RequestEvent requestReceivedEvent) {
Request request = requestReceivedEvent.getRequest();
ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
if (serverTransactionId == null) {
try {
serverTransactionId = sipProvider.getNewServerTransaction(request);
} catch (TransactionAlreadyExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransactionUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("\n\nRequest " + request.getMethod() + " received at " + sipStack.getStackName() + " with server transaction id " + serverTransactionId);
if (request.getMethod().equals(Request.INVITE)) {
processInvite(request, serverTransactionId);
} else if (request.getMethod().equals(Request.BYE)) {
processBye(request, serverTransactionId);
} else if (request.getMethod().equals(Request.ACK)) {
processAck(request, serverTransactionId);
} else {
try {
serverTransactionId.sendResponse(messageFactory.createResponse(200, request));
} catch (Exception e) {
e.printStackTrace();
fail("Unxepcted exception ");
}
}
}
use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processPublish.
private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
logger.info("shootist: got a publish . 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);
if (request.getRawContent() != null) {
this.lastMessageContent = new String(request.getRawContent());
allMessagesContent.add(new String(lastMessageContent));
}
SIPIfMatchHeader sipIfMatchHeader = (SIPIfMatchHeader) request.getHeader(SIPIfMatchHeader.NAME);
boolean sipIfMatchFound = true;
if (sipIfMatchHeader != null && sipIfMatchHeader.getETag() != null && !sipIfMatchHeader.getETag().equals(sipETag)) {
sipIfMatchFound = false;
}
if (sipIfMatchFound) {
Response response = protocolObjects.messageFactory.createResponse(200, request);
sipETag = Integer.toString(new Random().nextInt(10000000));
SIPETagHeader sipTagHeader = protocolObjects.headerFactory.createSIPETagHeader(sipETag);
response.addHeader(sipTagHeader);
response.addHeader(request.getHeader(ExpiresHeader.NAME));
st.sendResponse(response);
logger.info("shootist: Sending OK.");
} else {
Response response = protocolObjects.messageFactory.createResponse(500, request);
serverTransactionId.sendResponse(response);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations