logger.log(Level.FINER, "Hashkey: " + hashkey);
}
// Set BERoute parameter on topmost Via
// Add quotes around it, as it may contain special characters
ViaImpl via = getTopVia(request);
via.setParameter(CLBConstants.BE_ROUTE_PARAM,
CLBConstants.QUOTE + instanceID + CLBConstants.QUOTE);
sipClientToClbFEMapper.pushRouteHeader(request, localAddress.getHostName(),
localAddress.getPort());
// Check if the application has set Contact
if (request.isContactIndicated()) {
// Check if this request is initiated from this instance
Header contactHeader = request.getRawHeader(Header.CONTACT);
if (contactHeader != null) {
// There is a contact, we need to add the BE-KEY to it
try {
AddressImpl addressValue = (AddressImpl) contactHeader.getAddressValue();
if (addressValue != null) {
// Fetch current read-only status
boolean readOnly = addressValue.isReadOnly();
// Allow writes on Address object
addressValue.setReadOnly(false);
URIImpl uriImpl = (URIImpl) addressValue.getURI();
if(uriImpl != null){
uriImpl.encodeBeKey(hashkey);
}
// Reset read-only status
addressValue.setReadOnly(readOnly);
}
} catch (ServletParseException e) {
throw new SipRoutingException("Malformed Contact", e);
}
}
replaceTopVia(request, via);
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER,
"The request originates from this instance, altered request: " + request);
}
return null;
} else if (request.isRecordRouteIndicated()) {
// This request was proxied, save ID of incoming connection.
String encodedConnection;
if ((encodedConnection=getEncondedConnection(request)) == null) {
throw new SipRoutingException("Could not find connection information in a proxied request, shall never happen!");
} else {
via.setParameter(CLBConstants.CONNID_PARAM, encodedConnection);
}
Header rrHeader = request.getRawHeader(Header.RECORD_ROUTE);
AddressImpl rrAddr;
try {
rrAddr = (AddressImpl) rrHeader.getAddressValue();
} catch (ServletParseException e) {
throw new SipRoutingException("Malformed record-Route", e);
}
// The R-R was added by the application, thus we shall set 'bekey'
// Fetch current read-only status
boolean readOnly = rrAddr.isReadOnly();
// Allow writes on Address object
rrAddr.setReadOnly(false);
URIImpl uriImpl = (URIImpl) rrAddr.getURI();
if (uriImpl != null) {
uriImpl.encodeBeKey(hashkey);
}
// Reset read-only status
rrAddr.setReadOnly(readOnly);
replaceTopVia(request, via);
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER,
"The request was proxied, altered request: " + request);
}
return null;
} else {
// This request was either:
// a) proxied but not Record-Routed; save ID of incoming connection so that response can travel back on it.
// b) a non-dialog request originating from this instance; no connection information will exist.
String encodedConnection;
if ((encodedConnection=getEncondedConnection(request)) != null) {
via.setParameter(CLBConstants.CONNID_PARAM, encodedConnection);
}
replaceTopVia(request, via);
return null;