public void checkRouteHeader(SipServletRequestImpl req, boolean remove) {
// loose route support: remove first route header which should refer to
// this sipstack
// TODO implement support for strict route
Header r = req.getRawHeader(Header.ROUTE);
if (r == null) {
req.setFragmentId(((URIImpl) req.getRequestURI()).getFragmentId());
// Session Case handling
req.setSessionCase(SessionCase.EXTERNAL);
// end Session Case handling
// Populate Parameters from Request URI if initial request
if (req.isInitial()) {
req.setRequestParams((URIImpl) req.getRequestURI());
}
} else {
r.setReadOnly(false);
ListIterator<Address> it_a = null;
try {
it_a = r.getAddressValues();
} catch (ServletParseException e) {
// TR HH52078
SipServletResponseImpl failureResp = req.createTerminatingResponse(400);
if (failureResp == null) {
return;
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"failed to parse top route , send 400 response");
}
failureResp.popDispatcher().dispatch(failureResp);
return;
}
Address a = it_a.next();
URIImpl uri = (URIImpl) a.getURI();
// Session Case handling
// TODO move constants
final String CALL_PARAM = "call";
final String CALL_PARAM_ORIG = "orig";
final String CALL_PARAM_TERMINATING = "term_registered";
final String CALL_PARAM_TERMINATING_UNREG = "term_unregistered";
String callParam = uri.getParameter(CALL_PARAM);
// if(callParam == null) callParam = uri.getParameter(CALL_PARAM);
if (callParam == null) {
req.setSessionCase(SessionCase.EXTERNAL);
} else {
if (callParam.equals(CALL_PARAM_ORIG)) {
req.setSessionCase(SessionCase.ORIGINATING);
} else if (callParam.equals(CALL_PARAM_TERMINATING)) {
req.setSessionCase(SessionCase.TERMINATING);
} else if (callParam.equals(CALL_PARAM_TERMINATING_UNREG)) {
req.setSessionCase(SessionCase.TERMINATING_UNREGISTERED);
} else {
req.setSessionCase(SessionCase.EXTERNAL);
logger.log(Level.WARNING,
"Assigned SessionCase external due to unknown value of " +
CALL_PARAM + " :" + callParam);
}
}
// end Session Case handling
if (uri.getLrParam()) {
// Before removing the Route header extract the fragment-id.
// This code needs BASIC TESTING in an extended
// spiraling scenario, such as
//
// UAC/EAS --> proxy/external --> proxy/EAS --> UAS/external
//
// logger.log(Level.FINE, "+++ Route header with ;lr seen in resolver");
// logger.log(Level.FINE, "+++ try setting frag info from the Route header
// URI");
// logger.log(Level.FINE, "+++ URI: "+(SipURIImpl)a.getURI());
// logger.log(Level.FINE, "+++ and the id is:
// "+((SipURIImpl)a.getURI()).getFragmentId());
// logger.log(Level.FINE, "+++ let's set it in the request then");
req.setFragmentId(((URIImpl) a.getURI()).getFragmentId());
if (remove) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Removing route = " + a);
}
it_a.remove();
// support of popped route added.
req.setInitialPoppedRoute(a);
req.setRecordRouteURI(uri);
}
} else {
throw new IllegalAccessError(
"we do not support strict routes yet");
}
r.setReadOnly(true);
}
}