} catch (ParseException e1) {
throw new SipException("failed to set local tag", e1);
}
final String transport = request.getTopmostViaHeader().getTransport();
final ListeningPointImpl listeningPointImpl = (ListeningPointImpl) sipProvider.getListeningPoint(transport);
final ViaList viaList = new ViaList();
viaList.add((Via) listeningPointImpl.createViaHeader());
request.setVia(viaList);
try {
request.setHeader(headerFactory.createMaxForwardsHeader(70));
} catch (InvalidArgumentException e) {
throw new SipException("Failed to create max forwards header",e);
}
request.setHeader((Header) outgoingDialogCallId.clone());
// note: cseq will be set by dialog when sending
// set contact if the original response had it
if (origRequest.getHeader(ContactHeader.NAME) != null) {
request.setHeader(listeningPointImpl.createContactHeader());
}
/*
* Route header fields of the upstream request MAY be copied in the
* downstream request, except the topmost Route header if it is under
* the responsibility of the B2BUA. Additional Route header fields MAY
* also be added to the downstream request.
*/
if (outgoingDialog == null || outgoingDialog.getState() == null) {
// first request, no route available
final RouteList routeList = request.getRouteHeaders();
if (routeList != null) {
final RouteHeader topRoute = routeList.get(0);
final URI topRouteURI = topRoute.getAddress().getURI();
if (topRouteURI.isSipURI()) {
final SipURI topRouteSipURI = (SipURI) topRouteURI;
if (topRouteSipURI.getHost().equals(listeningPointImpl.getIPAddress())
&& topRouteSipURI.getPort() == listeningPointImpl.getPort()) {
if (routeList.size() > 1) {
routeList.remove(0);
}
else {
request.removeHeader(RouteHeader.NAME);