⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestforwarding.java

📁 The source code for this package is located in src/gov/nist/sip/proxy. The proxy is a pure JAIN-SIP
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				 * proxy MUST apply the procedures to the first value in the				 * Route header field, if present, else the Request-URI. The				 * procedures will produce an ordered set of (address, port,				 * transport) tuples. Independently of which URI is being used				 * as input to the procedures of [4], if the Request-URI				 * specifies a SIPS resource, the proxy MUST follow the				 * procedures of [4] as if the input URI were a SIPS URI.				 */				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequest(), (STEP 7)"									+ " Determine Next-Hop Address, Port, and Transport will be done by the stack...");				/** **************************************************************************** */				/** ************ 8. Add a Via header field value ********* */				/** **************************************************************************** */				/*				 * The proxy MUST insert a Via header field value into the copy				 * before the existing Via header field values.				 */								 Iterator lps=sipStack.getListeningPoints();				 lp=(ListeningPoint)lps.next();				 stackIPAddress = lp.getIPAddress();					 								ViaHeader viaHeader = null;				if (clonedRequest.getMethod().equals(Request.CANCEL)) {					// Branch Id will be assigned by the stack.					viaHeader = headerFactory.createViaHeader(stackIPAddress,							lp.getPort(), lp.getTransport(), null);					if (clonedRequest.getMethod().equals(Request.CANCEL)) {						// Cancel is hop by hop so remove all other via headers.						clonedRequest.removeHeader(ViaHeader.NAME);					}				} else {					viaHeader = headerFactory.createViaHeader(stackIPAddress,							lp.getPort(), lp.getTransport(), ProxyUtilities									.generateBranchId());				}				if (viaHeader != null)					clonedRequest.addHeader(viaHeader);				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequest(), (STEP 8)"									+ " the proxy inserts a Via header field value into the copy"									+ " before the existing Via header field values");				/*				 * Proxies choosing to detect loops have an additional				 * constraint in the value they use for construction of the				 * branch parameter. A proxy choosing to detect loops SHOULD				 * create a branch parameter separable into two parts by the				 * implementation. The first part MUST satisfy the constraints				 * of Section 8.1.1.7 as described above. The second is used to				 * perform loop detection and distinguish loops from spirals.				 */				// Not yet implemented				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequest(), (STEP 8)"									+ " Loop detection not implemented");				/** ************************************************************************* */				/**				 *  9. Add a Content-Length header field if necessary				 * 				 */				/** ************************************************************************* */				try {					ContentTypeHeader contentTypeHeader = (ContentTypeHeader) clonedRequest							.getHeader(ContentTypeHeader.NAME);					if (contentTypeHeader == null) {						if (logger.isDebugEnabled())							logger.debug("RequestForwarding, forwardRequest(),"									+ " no Content-Type header,"									+ " we don't stripe any parameters!!!");					} else						contentTypeHeader.removeParameter("msgr");				} catch (Exception e) {					logger.debug("RequestForwarding, forwardRequest(), Stripe"							+ " Parameter failed!!!!");				}				/** ************************************************************************* */				/** ********* 10. Forward Request ********* */				/** ************************************************************************* */				if (statefullForwarding) {					forwardRequestStatefully(sipProvider, clonedRequest,							request, serverTransaction);				} else {					forwardRequestStatelessly(sipProvider, clonedRequest,							request, serverTransaction);				}				/** ************************************************************************ */				/** ******** 11. Set timer C ********* */				/** ************************************************************************ */				// Not Implemented....			}		} catch (Exception ex) {			try {				logger.error("RequestForwarding, forwardRequest(), "						+ " internal error, " + "exception raised:", ex);				// This is an internal error:				// Let's return a 500 SERVER_INTERNAL_ERROR				Response response = messageFactory.createResponse(						Response.SERVER_INTERNAL_ERROR, request);				if (serverTransaction != null)					serverTransaction.sendResponse(response);				else					sipProvider.sendResponse(response);				if (logger.isDebugEnabled())					logger.debug("RequestForwarding, forwardRequest(), "							+ " 500 SERVER_INTERNAL_ERROR replied:\n"							+ response.toString());			} catch (Exception e) {				e.printStackTrace();			}		}	}	/**	 * Forward the request statefully.	 * 	 * @param sipProvider --	 *            sip provider to forward request.	 * @param clonedRequest --	 *            cloned request to forward.	 * @param originalRequest --	 *            incoming request	 * @param serverTransaction --	 *            server transaction used to fwd the request.	 */	private void forwardRequestStatefully(SipProvider sipProvider,			Request clonedRequest, Request originalRequest,			ServerTransaction serverTransaction) {		MessageFactory messageFactory = proxy.getMessageFactory();		if (logger.isDebugEnabled()) {			logger.debug("serverTransaction =  " + serverTransaction);			if (serverTransaction != null)				logger.debug("dialog =  " + serverTransaction.getDialog());		}		try {			/*			 * A stateful proxy MUST create a new client transaction for this			 * request as described in Section 17.1 and instructs the			 * transaction to send the request using the address, port and			 * transport determined in step 7			 */			if (serverTransaction == null					&& !clonedRequest.getMethod().equals(Request.MESSAGE)) {				// dont create a server transaction for MESSAGE -				// just forward the request statefully through a new				// client transaction.				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequestStatefully(),"									+ " the cloned request does not have a server transaction,"									+ " so we drop the request!");				return;			}			if (originalRequest.getMethod().equals(Request.CANCEL)) {				// 487 Request Terminated to reply:				Response response = messageFactory.createResponse(						Response.REQUEST_TERMINATED, originalRequest);				CSeqHeader cSeqHeader = (CSeqHeader) response						.getHeader(CSeqHeader.NAME);				cSeqHeader.setMethod("INVITE");				serverTransaction.sendResponse(response);				if (logger.isDebugEnabled())					logger							.debug("Proxy, processRequest(), 487 Request Terminated"									+ " replied to the CANCEL:\n"									+ response.toString());			}			if (logger.isDebugEnabled())				logger.debug("RequestForwarding, forwardRequestStatefully(),"						+ " the dialog state is null, so we have to"						+ " forward the request using"						+ " a new clientTransaction");			ClientTransaction clientTransaction = sipProvider					.getNewClientTransaction(clonedRequest);			clientTransaction.sendRequest();			if (logger.isDebugEnabled())				logger.debug("RequestForwarding, forwardRequestStatefully(),"						+ ", cloned request forwarded statefully:\n "						+ clonedRequest);			TransactionsMapping transactionsMapping = (TransactionsMapping) serverTransaction					.getApplicationData();			if (transactionsMapping != null)				transactionsMapping.addMapping(serverTransaction,						clientTransaction);			else {				transactionsMapping = new TransactionsMapping();				transactionsMapping.addMapping(serverTransaction,						clientTransaction);				serverTransaction.setApplicationData(transactionsMapping);				clientTransaction.setApplicationData(transactionsMapping);			}		} catch (Exception ex) {			try {				if (logger.isDebugEnabled()) {					logger							.debug(									"RequestForwarding, forwardRequestStatefully(), "											+ " internal error, "											+ "exception raised:", ex);					ex.printStackTrace();					System.exit(0);				}				// This is an internal error:				// Let's return a 500 SERVER_INTERNAL_ERROR				Response response = messageFactory.createResponse(						Response.SERVER_INTERNAL_ERROR, originalRequest);				if (serverTransaction != null)					serverTransaction.sendResponse(response);				else					sipProvider.sendResponse(response);				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequestStatefully(), "									+ " 500 SERVER_INTERNAL_ERROR replied:\n"									+ response.toString());			} catch (Exception e) {				e.printStackTrace();			}		}	}	private void forwardRequestStatelessly(SipProvider sipProvider,			Request clonedRequest, Request originalRequest,			ServerTransaction serverTransaction) {		MessageFactory messageFactory = proxy.getMessageFactory();		HeaderFactory headerFactory = proxy.getHeaderFactory();		AddressFactory addressFactory = proxy.getAddressFactory();		SipStack sipStack = proxy.getSipStack();		try {			// We forward statelessly:			// It means the Request does not create dialogs...			sipProvider.sendRequest(clonedRequest);			if (logger.isDebugEnabled())				logger.debug("RequestForwarding, forwardRequestStatelessly(), "						+ " cloned request forwarded statelessly:\n"						+ clonedRequest.toString());		} catch (Exception ex) {			try {				logger.error("RequestForwarding, forwardRequestStatelessly(), "						+ " internal error, " + "exception raised:", ex);				// This is an internal error:				// Let's return a 500 SERVER_INTERNAL_ERROR				Response response = messageFactory.createResponse(						Response.SERVER_INTERNAL_ERROR, originalRequest);				if (serverTransaction != null)					serverTransaction.sendResponse(response);				else					sipProvider.sendResponse(response);				if (logger.isDebugEnabled())					logger							.debug("RequestForwarding, forwardRequestStatelessly(), "									+ " 500 SERVER_INTERNAL_ERROR replied:\n"									+ response.toString());			} catch (Exception e) {				e.printStackTrace();			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -