throw new IllegalArgumentException();
}
}
// time to give birth to a new request...
SipServletRequest copiedReq = null;
// need special treatment for from and to headers
// Set<String> from = headerMap != null ? headerMap.remove("From") : null;
// Set<String> to = headerMap != null ? headerMap.remove("To") : null;
SipFactoryFacade sfImpl = (SipFactoryFacade) _sf;
SipApplicationSessionImpl sappSessImpl = (SipApplicationSessionImpl) origRequest.getApplicationSession();
try {
if ((from != null) && (to != null)) {
copiedReq = sfImpl.createRequestImpl(sappSessImpl,
origRequest.getMethod(),
sfImpl.createAddress(from.iterator().next()),
sfImpl.createAddress(to.iterator().next()), false,
origRequestImpl);
} else if (from != null) {
copiedReq = sfImpl.createRequestImpl(sappSessImpl,
origRequest.getMethod(),
sfImpl.createAddress(from.iterator().next()),
origRequestImpl.getToImpl(), false, origRequestImpl);
} else if (to != null) {
copiedReq = sfImpl.createRequestImpl(sappSessImpl,
origRequest.getMethod(), origRequestImpl.getFromImpl(),
sfImpl.createAddress(to.iterator().next()), false,
origRequestImpl);
} else {
copiedReq = sfImpl.createRequestImpl(sappSessImpl,
origRequest.getMethod(), origRequestImpl.getFromImpl(),
origRequestImpl.getToImpl(), false, origRequestImpl);
}
} catch (ServletParseException e) {
throw new IllegalArgumentException(e);
}
SipServletRequestImpl copiedReqImpl = (SipServletRequestImpl) copiedReq;
// lets add non system headers
if ((clonedHeaderMap != null) && !clonedHeaderMap.isEmpty()) {
Iterator<String> names = clonedHeaderMap.keySet().iterator();
Iterator<List<String>> values = clonedHeaderMap.values().iterator();
while (names.hasNext()) {
setHeader(names.next(), values.next(), copiedReqImpl);
}
}
if (route != null) {
MultiLineHeader rHdr = new MultiLineHeader(Header.ROUTE, true);
for (String s: route) {
rHdr.setValue(s, false);
}
copiedReqImpl.setHeader(rHdr);
} else {
Header rt = origRequestImpl.getRawHeader(Header.ROUTE);
if (rt != null) {
copiedReqImpl.setHeader((Header) rt.clone());
}
}
if (contact != null) {
if (origRequest.getMethod().equals("REGISTER")) {
copiedReqImpl.setHeader("Contact", contact.iterator().next());
} else { // change only parameters and user part of the URI
try {
Address cnctAddr = new AddressImpl(contact.iterator().next());
Address contactAddr = copiedReqImpl.getAddressHeaderImpl(
"Contact");
if (contactAddr != null && !contactAddr.isWildcard()) {
((AddressImpl) contactAddr).modifyContactParameters(cnctAddr);
}
} catch (ServletParseException ex) {
if (_log.isLoggable(Level.FINE)) {
_log.log(Level.FINE,
" Exception while parsing Contact address ", ex);
}
}
}
}
if (linkedSessions) {
SipSession session1 = origRequest.getSession();
SipSession session2 = copiedReq.getSession();
if ((session1 == null) || (session2 == null)) {
throw new NullPointerException();
}