public SipServletRequestImpl createRequestImpl(
SipApplicationSessionImpl appSession, String method, Address from,
Address to, boolean sameCallID, SipServletRequestImpl origRequest) {
if (!method.equals("ACK") && !method.equals("CANCEL")) {
Address fromCopy = (Address) from.clone();
Address toCopy = (Address) to.clone();
// Remove protection, lock up
((AddressImpl) fromCopy).setReadOnly(false);
((AddressImpl) toCopy).setReadOnly(false);
fromCopy.setParameter(AddressImpl.TAG_PARAM, createTag());
toCopy.removeParameter(AddressImpl.TAG_PARAM);
SipServletRequestImpl req = null;
String defaultHandler = null;
if (origRequest == null) {
URI requestURI = (URI) toCopy.getURI().clone();
if ("REGISTER".equals(method) && requestURI.isSipURI()) {
((SipURI)requestURI).setUser(null);
}
req = new SipServletRequestImpl(method, requestURI,
SipFactoryImpl.PROTOCOL_LINE);
req.setInternalRoutingDirective(
SipApplicationRoutingDirective.NEW, null);
req.setBeKey(appSession.getBeKey());
} else {
req = (SipServletRequestImpl) origRequest.clone();
req.setInternalRoutingDirective(
SipApplicationRoutingDirective.CONTINUE, origRequest);
// copy region in case of CONTINUE as well
req.setRegion(origRequest.getRegion());
req.clearApplicationDispatchers();
// The clone will copy the session-case. For the new request
// the session-case should be internal.
req.setSessionCase(SessionCase.INTERNAL);
req.removeSystemHeaders();
req.removeRemoteSettings();
defaultHandler = origRequest.getSessionImpl().getHandler();
}
// set CallID
Header callIDHeader = new SingleLineHeader(Header.CALL_ID, true);
if ((origRequest == null) || !sameCallID) {
callIDHeader.setValue(createCallID(), false);
} else {
callIDHeader.setValue(origRequest.getCallId(), false);
}
req.setHeader(callIDHeader);
URI fromURI = cleanupFromOrToURI(fromCopy.getURI().clone());
fromCopy.setURI(fromURI);
URI toURI = cleanupFromOrToURI(toCopy.getURI().clone());
toCopy.setURI(toURI);
// Put protection, lock again
((AddressImpl) fromCopy).setReadOnly(true);
((AddressImpl) toCopy).setReadOnly(true);