private void forwardRequestStatefully(SipProvider sipProvider,
Request clonedRequest, Request originalRequest,
ServerTransaction serverTransaction) throws ParseException,
SipException, JipletException
{
MessageFactory messageFactory = jiplet.getMessageFactory();
/*
* A stateful jiplet MUST create a new client transaction for this
* request as described in Section 17.1 and instructs the transaction to
* send the request using the address, port and transport determined in
* step 7
*/
// SERVER TRANSACTION CHECK
if (serverTransaction == null
&& !clonedRequest.getMethod().equals(Request.MESSAGE))
{
// dont create a server transaction for MESSAGE -
// just forward the request statefully through a new
// client transaction.
return;
}
if (originalRequest.getMethod().equals(Request.CANCEL))
{
// reply to the canceled request and maybe to the received CANCEL
// and also send CANCELs to pending client transactions
JipletDialog jdialog = jiplet.getDialog(serverTransaction
.getDialog(), true);
Transaction firstTransaction = (Transaction) jdialog
.getAttribute("firstTransaction");
if (firstTransaction == null)
{
throw new JipletException(
"ERROR, RequestForwarding Cancel, the first transaction"
+ " for the dialog is null");
}
if (firstTransaction instanceof ClientTransaction)
{
return;
}
ServerTransaction firstServerTransaction = (ServerTransaction) firstTransaction;
try
{
// send 487 Request Terminated reply to canceled request
Response response = messageFactory.createResponse(
Response.REQUEST_TERMINATED, firstServerTransaction
.getRequest());
firstServerTransaction.sendResponse(response);
}
catch (InvalidArgumentException e)
{
// inapplicable - it only happens if the Response was created
// by Dialog.createReliableProvisionalResponse(int) and the
// application calls ServerTransaction.sendResponse() to send it
JipletLogger
.error("Cancel response sending failed - invalid send method used.");
}
// find the response context
TransactionsMapping transactionsMapping = jdialog
.getTransactionsMapping();
Vector clientTransactions = transactionsMapping
.getClientTransactions(firstServerTransaction);
if (clientTransactions == null || clientTransactions.isEmpty())
{
// RFC states to send the CANCEL statelessly in this case
forwardRequestStatelessly(sipProvider, clonedRequest,
originalRequest, serverTransaction);
return;
}
try
{
// send OK to CANCEL
Response response = messageFactory.createResponse(Response.OK,
originalRequest);
serverTransaction.sendResponse(response);
}
catch (InvalidArgumentException e)
{