public void start ( ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "start" ) ; } if ( started ) { throw new IllegalStateException ( "Proxy branch alredy started!" ) ; } if ( canceled ) { throw new IllegalStateException ( "Proxy branch was cancelled, you must create a new branch!" ) ; } if ( timedOut ) { throw new IllegalStateException ( "Proxy brnach has timed out!" ) ; } if ( proxy . getAckReceived ( ) ) { throw new IllegalStateException ( "An ACK request has been received on this proxy. Can not start new branches." ) ; } // Initialize these here for efficiency. if ( logger . isDebugEnabled ( ) ) { logger . debug ( "start - calling updateTimer" ) ; } updateTimer ( false , originalRequest . getSipApplicationSession ( false ) ) ; SipURI recordRoute = null ; // If the proxy is not adding record-route header, set it to null and it // will be ignored in the Proxying if ( proxy . getRecordRoute ( ) || this . getRecordRoute ( ) ) { if ( recordRouteURI == null && recordRouteURIString == null ) { recordRouteURIString = DEFAULT_RECORD_ROUTE_URI ; } if ( recordRouteURIString != null ) { try { recordRouteURI = ( ( SipURI ) proxy . getSipFactoryImpl ( ) . createURI ( recordRouteURIString ) ) ; } catch ( ServletParseException e ) { logger . error ( "A problem occured while setting the target URI while proxying a request " + recordRouteURIString , e ) ; } } recordRoute = recordRouteURI ; } addTransaction ( originalRequest ) ; URI destination = null ; //app may have modified the branch request, so give it priority //fixes https://github.com/RestComm/sip-servlets/issues/131 if ( outgoingRequest . getRequestURI ( ) . equals ( this . getProxy ( ) . getOriginalRequest ( ) . getRequestURI ( ) ) ) { if ( targetURI != null ) { try { destination = proxy . getSipFactoryImpl ( ) . createURI ( targetURI ) ; } catch ( ServletParseException e ) { logger . error ( "A problem occured while setting the target URI while proxying a request " + targetURI , e ) ; } } } else { //the app has mofified the requestURI after branch creation.. destination = outgoingRequest . getRequestURI ( ) ; } Request cloned = ProxyUtils . createProxiedRequest ( outgoingRequest , this , destination , this . outboundInterface , recordRoute , this . pathURI ) ; //tells the application dispatcher to stop routing the original request //since it has been proxied originalRequest . setRoutingState ( RoutingState . PROXIED ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Proxy Branch 1xx Timeout set to " + proxyBranch1xxTimeout ) ; } if ( proxyBranch1xxTimeout > 0 ) { proxy1xxTimeoutTask = new ProxyBranchTimerTask ( this , ResponseType . INFORMATIONAL , originalRequest . getSipApplicationSession ( false ) ) ; proxy . getProxyTimerService ( ) . schedule ( proxy1xxTimeoutTask , proxyBranch1xxTimeout * 1000L ) ; proxyBranch1xxTimerStarted = true ; } started = true ; forwardRequest ( cloned , false ) ; }
After the branch is initialized this method proxies the initial request to the specified destination . Subsequent requests are proxied through proxySubsequentRequest