maxForwardsHeader.setMaxForwards(maxForwardsHeader.getMaxForwards() - 1);
}
// Add the via header to the top of the header list.
request.addHeader(viaHeader);
//Removing first routeHeader if it is for us
RouteHeader routeHeader = (RouteHeader) request.getHeader(RouteHeader.NAME);
if(routeHeader != null) {
SipURI routeUri = (SipURI)routeHeader.getAddress().getURI();
if(routeUri.getHost().equalsIgnoreCase(myHost) && routeUri.getPort() == myPort) {
request.removeFirst(RouteHeader.NAME);
}
}
// Record route the invite so the bye comes to me.
if (request.getMethod().equals(Request.INVITE) || request.getMethod().equals(Request.SUBSCRIBE)) {
SipURI sipUri = addressFactory
.createSipURI(null, sipProvider.getListeningPoint(
ListeningPoint.UDP).getIPAddress());
sipUri.setPort(sipProvider.getListeningPoint(ListeningPoint.UDP).getPort());
//See RFC 3261 19.1.1 for lr parameter
sipUri.setLrParam();
Address address = addressFactory.createAddress(sipUri);
address.setURI(sipUri);
RecordRouteHeader recordRoute = headerFactory
.createRecordRouteHeader(address);
request.addHeader(recordRoute);
//Adding Route Header
SipURI routeSipUri = addressFactory
.createSipURI(null, "127.0.0.1");
routeSipUri.setPort(5070);
routeSipUri.setLrParam();
RouteHeader route = headerFactory.createRouteHeader(addressFactory.createAddress(routeSipUri));
request.addFirst(route);
}
else if (!Request.ACK.equals(request.getMethod())) {
//Adding Route Header
if(((SipURI)request.getRequestURI()).getPort() == 5070) {
SipURI routeSipUri = addressFactory
.createSipURI(null, "127.0.0.1");
routeSipUri.setPort(5080);
routeSipUri.setLrParam();
RouteHeader route = headerFactory.createRouteHeader(addressFactory.createAddress(routeSipUri));
request.addFirst(route);
}
}
//sending request
sipProvider.sendRequest(request);