use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processPrack.
private void processPrack(Request request, ServerTransaction serverTransactionId) {
try {
prackReceived = true;
prackRequestReceived = request;
ServerTransaction st = serverTransactionId;
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
Response response = protocolObjects.messageFactory.createResponse(200, request);
st.sendResponse(response);
Thread.sleep(200);
inviteServerTid.sendResponse(getFinalResponse());
} catch (Exception e) {
logger.error("Unexpected exception while trying to send the 200 to PRACK " + request, e);
}
}
use of javax.sip.ServerTransaction in project load-balancer by RestComm.
the class TestSipListener method processInvite.
/**
* Process the invite request.
*/
public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
inviteReceived = true;
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
inviteRequest = request;
logger.info("shootme: got an Invite " + request);
try {
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
inviteServerTid = st;
Dialog dialog = st.getDialog();
if (request.getHeader(JoinHeader.NAME) != null) {
setJoinRequestReceived(true);
this.joinDialog = dialog;
} else if (request.getHeader(ReplacesHeader.NAME) != null) {
setReplacesRequestReceived(true);
this.replacesDialog = dialog;
} else {
this.dialogCount++;
this.dialog = dialog;
}
logger.info("Shootme: dialog = " + dialog);
this.inviteRequest = request;
boolean sendReliably = false;
RequireHeader requireHeader = (RequireHeader) request.getHeader(RequireHeader.NAME);
if (requireHeader != null && "100rel".equalsIgnoreCase(requireHeader.getOptionTag().trim())) {
sendReliably = true;
}
if (respondWithError == null)
for (int provisionalResponseToSend : provisionalResponsesToSend) {
Thread.sleep(getTimeToWaitBetweenProvisionnalResponse());
Response response = protocolObjects.messageFactory.createResponse(provisionalResponseToSend, request);
if (provisionalResponseToSend >= Response.TRYING && provisionalResponseToSend < Response.OK) {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
if (provisionalResponseToSend != Response.TRYING && toHeader.getTag() == null) {
// Application is supposed to set.
toHeader.setTag(TO_TAG);
}
if (sendReliably && provisionalResponseToSend != Response.TRYING) {
requireHeader = protocolObjects.headerFactory.createRequireHeader("100rel");
response.addHeader(requireHeader);
Header rseqHeader = protocolObjects.headerFactory.createRSeqHeader(rseqNumber.getAndIncrement());
response.addHeader(rseqHeader);
dialog.sendReliableProvisionalResponse(response);
} else {
st.sendResponse(response);
eventListener.uasAfterResponse(response.getStatusCode(), appServer);
}
}
}
if (respondWithError != null && !sendReliably) {
Response response = protocolObjects.messageFactory.createResponse(respondWithError, request);
response.setReasonPhrase("Unable to setup media services");
st.sendResponse(response);
eventListener.uasAfterResponse(response.getStatusCode(), appServer);
return;
}
ContactHeader contactHeader = (ContactHeader) request.getHeader(ContactHeader.NAME);
if (contactHeader != null && "0.0.0.0".equals(((SipURI) contactHeader.getAddress().getURI()).getHost())) {
abortProcessing = true;
throw new IllegalArgumentException("we received a contact header with 0.0.0.0 in an INVITE !");
}
if (!waitForCancel) {
Address address = null;
if (!isIpv6)
address = protocolObjects.addressFactory.createAddress("Shootme <sip:127.0.0.1:" + myPort + ";transport=" + protocolObjects.transport + ">");
else
address = protocolObjects.addressFactory.createAddress("Shootme <sip:[::1]:" + myPort + ";transport=" + protocolObjects.transport + ">");
contactHeader = protocolObjects.headerFactory.createContactHeader(address);
setFinalResponse(protocolObjects.messageFactory.createResponse(finalResponseToSend, request));
if (testAckViaParam) {
ViaHeader viaHeader = (ViaHeader) getFinalResponse().getHeader(ViaHeader.NAME);
viaHeader.setParameter("testAckViaParam", "true");
}
ToHeader toHeader = (ToHeader) getFinalResponse().getHeader(ToHeader.NAME);
if (toHeader.getTag() == null) {
// Application is supposed to set.
toHeader.setTag(TO_TAG);
}
getFinalResponse().addHeader(contactHeader);
if (!sendReliably) {
Thread.sleep(2000);
st.sendResponse(getFinalResponse());
eventListener.uasAfterResponse(getFinalResponse().getStatusCode(), appServer);
}
} else {
logger.info("Waiting for CANCEL, stopping the INVITE processing ");
return;
}
if (("join").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
sendJoinMessage = true;
}
if (("replaces").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
sendReplacesMessage = true;
}
} catch (Exception ex) {
logger.error("unexpected exception", ex);
throw new RuntimeException(ex);
}
}
use of javax.sip.ServerTransaction in project jain-sip.ha by RestComm.
the class SimpleB2BUAHandler method forwardResponse.
/**
* @param responseEvent
* @throws InvalidArgumentException
*/
@SuppressWarnings("unchecked")
private void forwardResponse(Response receivedResponse) throws SipException, InvalidArgumentException {
if (receivedResponse.getStatusCode() == 202) {
return;
}
System.out.println("Forwarding " + receivedResponse);
final ServerTransaction origServerTransaction = this.getServerTransaction();
Response forgedResponse = null;
try {
forgedResponse = messageFactory.createResponse(receivedResponse.getStatusCode(), origServerTransaction.getRequest());
} catch (ParseException e) {
throw new SipException("Failed to forge message", e);
}
// if ((getIncomingDialog() == null || getIncomingDialog().getState() == DialogState.EARLY) && localTag != null && getIncomingDialog() != null && getIncomingDialog().isServer()) {
// // no tag set in the response, since the dialog creating transaction didn't had it
// try {
// ((ToHeader)forgedResponse.getHeader(ToHeader.NAME)).setTag(localTag);
// } catch (ParseException e) {
// throw new SipException("Failed to set local tag", e);
// }
// }
// copy headers
ListIterator<String> lit = receivedResponse.getHeaderNames();
String headerName = null;
ListIterator<Header> headersIterator = null;
while (lit.hasNext()) {
headerName = lit.next();
if (SimpleB2BUAHandler.getHeadersToOmmitOnResponseCopy().contains(headerName)) {
continue;
} else {
forgedResponse.removeHeader(headerName);
headersIterator = receivedResponse.getHeaders(headerName);
while (headersIterator.hasNext()) {
forgedResponse.addLast((Header) headersIterator.next().clone());
}
}
}
// Copy content
final byte[] rawOriginal = receivedResponse.getRawContent();
if (rawOriginal != null && rawOriginal.length != 0) {
final byte[] copy = new byte[rawOriginal.length];
System.arraycopy(rawOriginal, 0, copy, 0, copy.length);
try {
forgedResponse.setContent(copy, (ContentTypeHeader) forgedResponse.getHeader(ContentTypeHeader.NAME));
} catch (ParseException e) {
throw new SipException("Failed to copy content.", e);
}
}
// set contact if the received response had it
if (receivedResponse.getHeader(ContactHeader.NAME) != null) {
final String transport = ((ViaHeader) forgedResponse.getHeader(ViaHeader.NAME)).getTransport();
forgedResponse.setHeader(((ListeningPointImpl) sipProvider.getListeningPoint(transport)).createContactHeader());
}
// set the to tag mandatory so that the dialog gets replicated
if (((MessageExt) forgedResponse).getToHeader().getTag() == null) {
try {
((MessageExt) forgedResponse).getToHeader().setTag("696");
} catch (ParseException e) {
e.printStackTrace();
}
}
origServerTransaction.sendResponse(forgedResponse);
}
use of javax.sip.ServerTransaction in project jain-sip.ha by RestComm.
the class SimpleStatefulProxy method forwardResponse.
/**
* @param responseEvent
* @throws InvalidArgumentException
*/
@SuppressWarnings("unchecked")
private void forwardResponse(Response receivedResponse) throws SipException, InvalidArgumentException {
System.out.println("Forwarding " + receivedResponse);
final ServerTransaction origServerTransaction = this.getServerTransaction();
Response forgedResponse = (Response) receivedResponse.clone();
forgedResponse.removeFirst(ViaHeader.NAME);
origServerTransaction.sendResponse(forgedResponse);
}
Aggregations