private final static void send487Response(Transaction inviteTransaction, SipServletRequestImpl inviteRequest) throws IllegalStateException, DispatcherException {
		SipServletResponseImpl inviteResponse = (SipServletResponseImpl)
			inviteRequest.createResponse(Response.REQUEST_TERMINATED);

		inviteRequest.setRoutingState(RoutingState.CANCELLED);
		//JSR 289 Section 6.2.1.1 Cancel Message Processing : since receiving a CANCEL request causes the UAS
		// to respond to an ongoing INVITE transaction with a non-2XX (specifically, 487) response, the SipSession state
		// normally becomes TERMINATED as a result of the non-2XX final response sent back to the UAC.
		// Issue 1484 : http://code.google.com/p/mobicents/issues/detail?id=1484
		// we terminate the session only for initial requests
		if(inviteRequest.isInitial()) {
			inviteRequest.getSipSession().setState(State.TERMINATED);
		}
		try {
			Response requestTerminatedResponse = (Response) inviteResponse.getMessage();
                        SipContext context = SipApplicationSessionCreationThreadLocal.lookupContext();
                        if (context != null) {
                            // bug zendesk#34106, because of JBOSS lifcycle and save the cost, get context param dirrectly
                            // from init param.
                            String reasonHeaderText = (String) context.getServletContext().getInitParameter(REQUEST_TERMINATED_REASON);
                            if (reasonHeaderText != null && !reasonHeaderText.isEmpty()) {
                                if(logger.isDebugEnabled()) {
					logger.debug("487 Request Terminated is being sent, adding Reason header with text: " + reasonHeaderText);
				}
                                ReasonHeader reasonHeader = SipFactoryImpl.headerFactory.createReasonHeader("SIP", Response.REQUEST_TERMINATED, reasonHeaderText);
                                requestTerminatedResponse.addHeader(reasonHeader);
                            }
                        }
			((ServerTransaction)inviteTransaction).sendResponse(requestTerminatedResponse);
			inviteRequest.getSipSession().getSipApplicationSession().getSipContext().getSipApplicationDispatcher().updateResponseStatistics(requestTerminatedResponse, false);
		} catch (SipException e) {
			throw new DispatcherException(Response.SERVER_INTERNAL_ERROR, "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL", e);
		} catch (InvalidArgumentException e) {
			throw new DispatcherException(Response.SERVER_INTERNAL_ERROR, "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL", e);
		} catch (ParseException e) {
                    throw new DispatcherException(Response.SERVER_INTERNAL_ERROR, "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL", e);
                }
	}
private final static void send487Response ( Transaction inviteTransaction , SipServletRequestImpl inviteRequest ) throws IllegalStateException , DispatcherException { SipServletResponseImpl inviteResponse = ( SipServletResponseImpl ) inviteRequest . createResponse ( Response . REQUEST_TERMINATED ) ; inviteRequest . setRoutingState ( RoutingState . CANCELLED ) ; if ( inviteRequest . isInitial ( ) ) { inviteRequest . getSipSession ( ) . setState ( State . TERMINATED ) ; } try { Response requestTerminatedResponse = ( Response ) inviteResponse . getMessage ( ) ; SipContext context = SipApplicationSessionCreationThreadLocal . lookupContext ( ) ; if ( context != null ) { String reasonHeaderText = ( String ) context . getServletContext ( ) . getInitParameter ( REQUEST_TERMINATED_REASON ) ; if ( reasonHeaderText != null && ! reasonHeaderText . isEmpty ( ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "487 Request Terminated is being sent, adding Reason header with text: " + reasonHeaderText ) ; } ReasonHeader reasonHeader = SipFactoryImpl . headerFactory . createReasonHeader ( "SIP" , Response . REQUEST_TERMINATED , reasonHeaderText ) ; requestTerminatedResponse . addHeader ( reasonHeader ) ; } } ( ( ServerTransaction ) inviteTransaction ) . sendResponse ( requestTerminatedResponse ) ; inviteRequest . getSipSession ( ) . getSipApplicationSession ( ) . getSipContext ( ) . getSipApplicationDispatcher ( ) . updateResponseStatistics ( requestTerminatedResponse , false ) ; } catch ( SipException e ) { throw new DispatcherException ( Response . SERVER_INTERNAL_ERROR , "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL" , e ) ; } catch ( InvalidArgumentException e ) { throw new DispatcherException ( Response . SERVER_INTERNAL_ERROR , "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL" , e ) ; } catch ( ParseException e ) { throw new DispatcherException ( Response . SERVER_INTERNAL_ERROR , "Impossible to send the 487 to the INVITE transaction corresponding to CANCEL" , e ) ; } }
@param inviteTransaction
@param inviteRequest