📄 proxy.java
字号:
if (logger.isDebugEnabled()) logger .debug("Proxy, processRequest()," + " the only target is the Request-URI (mAddr parameter)"); // 4. Forward the request statefully: requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, true); return; } } /* * If the domain of the Request-URI indicates a domain this element * is not responsible for, the Request-URI MUST be placed into the * target set as the only target, and the element MUST proceed to * the task of Request Forwarding (Section 16.6). */ if (requestURI.isSipURI()) { SipURI requestSipURI = (SipURI) requestURI; if (!configuration.hasDomain(requestSipURI.getHost())) { if (logger.isDebugEnabled()) logger .debug("Proxy, processRequest()," + " we are not responsible for the domain: Let's check if we have" + " a registration for this domain from another proxy"); // We have to check if another proxy did not registered // to us, in this case we have to use the contacts provided // by the registered proxy to create the targets: if (registrar.hasDomainRegistered(request)) { targetURIList = registrar.getDomainContactsURI(request); if (targetURIList != null && !targetURIList.isEmpty()) { if (logger.isDebugEnabled()) { logger .debug("Proxy, processRequest(), we have" + " a registration for this domain from another proxy"); } // 4. Forward the request statefully: requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, true); return; } else { targetURIList = new Vector(); logger .debug("Proxy, processRequest()," + " we are not responsible for the domain: the only target" + " URI is given by the request-URI"); targetURI = requestURI; targetURIList.addElement(targetURI); } } else { logger .debug("Proxy, processRequest()," + " we are not responsible for the domain: the only target" + " URI is given by the request-URI"); targetURI = requestURI; targetURIList.addElement(targetURI); } // 4. Forward the request statelessly: requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, false); return; } else { logger .debug("Proxy, processRequest()," + " we are responsible for the domain... Let's find the contact..."); } } // we use a SIP registrar: if (request.getMethod().equals(Request.REGISTER)) { if (logger.isDebugEnabled()) logger.debug("Incoming request Register"); // we call the RegisterProcessing: registrar.processRegister(request, sipProvider, serverTransaction); // Henrik: let the presenceserver do some processing too if (isPresenceServer()) { presenceServer.processRegisterRequest(sipProvider, request, serverTransaction); } return; } /* * If we receive a subscription targeted to a user that is * publishing its state here, send to presence server */ if (isPresenceServer() && (request.getMethod().equals(Request.SUBSCRIBE))) { logger.debug("Incoming request Subscribe"); if (presenceServer.isStateAgent(request)) { Request clonedRequest = (Request) request.clone(); presenceServer.processSubscribeRequest(sipProvider, clonedRequest, serverTransaction); } else { // Do we know this guy? targetURIList = registrar.getContactsURI(request); if (targetURIList == null) { // If not respond that we dont know him. logger.debug("Proxy: received a Subscribe request to " + " a user in our domain that was not found, " + " responded 404"); Response response = messageFactory.createResponse( Response.NOT_FOUND, request); if (serverTransaction != null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); return; } else { logger.debug("Trying to forward subscribe to " + targetURIList.toString() + "\n" + request.toString()); requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, false); } } return; } /** * Received a Notify. TOADD: Check if it match active * VirtualSubscriptions and update it */ if (isPresenceServer() && (request.getMethod().equals(Request.NOTIFY))) { logger.info("Incoming request Notify"); Response response = messageFactory.createResponse(481, request); response.setReasonPhrase("Subscription does not exist"); if (serverTransaction != null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); logger .debug("Proxy: received a Notify request. Probably wrong, responded 481"); return; } if (isPresenceServer() && (request.getMethod().equalsIgnoreCase("PUBLISH"))) { logger.info("Incoming request Publish"); logger.debug("Proxy: received a Publish request."); Request clonedRequest = (Request) request.clone(); if (presenceServer.isStateAgent(clonedRequest)) { logger.debug("PresenceServer.isStateAgent"); } else { logger.debug("PresenceServer is NOT StateAgent"); } if (presenceServer.isStateAgent(clonedRequest)) { presenceServer.processPublishRequest(sipProvider, clonedRequest, serverTransaction); } else { Response response = messageFactory.createResponse( Response.NOT_FOUND, request); if (serverTransaction != null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); } return; } if (request.getMethod().equals(Request.BYE)) { if (serverTransaction == null) { if (logger.isDebugEnabled()) logger.debug("Proxy, null server transactin for BYE"); return; } Response response = messageFactory.createResponse(Response.OK, request); serverTransaction.sendResponse(response); Request clonedRequest = (Request) request.clone(); ViaHeader via = this.getStackViaHeader(); clonedRequest.addHeader(via); ClientTransaction newct = sipProvider .getNewClientTransaction(clonedRequest); newct.sendRequest(); } /* * If the target set for the request has not been predetermined as * described above, this implies that the element is responsible for * the domain in the Request-URI, and the element MAY use whatever * mechanism it desires to determine where to send the request. ... * When accessing the location service constructed by a registrar, * the Request-URI MUST first be canonicalized as described in * Section 10.3 before being used as an index. */ if (requestURI.isSipURI()) { SipURI requestSipURI = (SipURI) requestURI; Iterator iterator = requestSipURI.getParameterNames(); if (logger.isDebugEnabled()) logger.debug("Proxy, processRequest(), we canonicalized" + " the request-URI"); while (iterator != null && iterator.hasNext()) { String name = (String) iterator.next(); requestSipURI.removeParameter(name); } } if (registrar.hasRegistration(request)) { targetURIList = registrar.getContactsURI(request); // We fork only INVITE and SUBSCRIBE. if (targetURIList != null && targetURIList.size() > 1 && (!request.getMethod().equals("INVITE") && !request.getMethod().equals("SUBSCRIBE"))) { if (logger.isDebugEnabled()) logger .debug("Proxy, processRequest(), the request " + " to fork is not an INVITE, so we will process" + " it with the first target as the only target."); targetURI = (URI) targetURIList.firstElement(); targetURIList = new Vector(); targetURIList.addElement(targetURI); // 4. Forward the request statefully to the target: requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, true); return; } if (targetURIList != null && !targetURIList.isEmpty()) { if (logger.isDebugEnabled()) logger.debug("Proxy, processRequest(), the target set" + " is the set of the contacts URI from the " + " location service"); // 4. Forward the request statefully to each target Section // 16.6.: requestForwarding.forwardRequest(targetURIList, sipProvider, request, serverTransaction, true); return; } else { // Let's continue and try the default hop. } } // The registrar cannot help to decide the targets, so let's use // our router: the default hop! logger.debug("Proxy, processRequest(), the registrar cannot help" + " to decide the targets, dropping request"); /* * If the target set remains empty after applying all of the above, * the proxy MUST return an error response, which SHOULD be the 480 * (Temporarily Unavailable) response. */ Response response = messageFactory.createResponse( Response.TEMPORARILY_UNAVAILABLE, request); if (serverTransaction != null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (logger.isDebugEnabled()) logger .debug("Proxy, processRequest(), unable to set " + " the targets, 480 (Temporarily Unavailable) replied:\n" + response.toString()); } catch (Exception ex) { try { if (logger.isDebugEnabled()) { logger.error("Proxy, processRequest(), internal error, " + "exception raised:", ex); ex.printStackTrace(); } // 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("Proxy, processRequest()," + " 500 SERVER_INTERNAL_ERROR replied:\n" + response.toString()); } catch (Exception e) { e.printStackTrace(); } } } /** * This is a listener method. */ public void processResponse(ResponseEvent responseEvent) { try { Response response = responseEvent.getResponse(); SipProvider sipProvider = (SipProvider) responseEvent.getSource(); ClientTransaction clientTransaction = responseEvent .getClientTransaction(); logger .debug("\n***************************************************************" + "\n***************************************************************" + "\nResponse " + response.getStatusCode() + " " + response.getReasonPhrase() + " received:\n" + response.toString()); logger.debug("Processing Response in progress"); if (logger.isDebugEnabled()) ProxyUtilities.printTransaction(clientTransaction); // Henrik - added handling of responses addressed to server // If we use a presenceserver, and if statuscode was OK... CSeqHeader cseqHeader = (CSeqHeader) response .getHeader(CSeqHeader.NAME); if (cseqHeader.getMethod().equals("SUBSCRIBE")) { presenceServer.processSubscribeResponse((Response) response .clone(), clientTransaction); } else if (cseqHeader.getMethod().equals("NOTIFY")) { // presenceServer.processNotifyResponse((Response)response.clone(), // clientTransaction); } responseForwarding.forwardResponse(sipProvider, response, clientTransaction); } catch (Exception ex) { logger.error("Proxy, processResponse(), internal error, " + "exception raised:",ex); } } /** * Processes a timeout event. An incoming servrer tx can result in multiple * forked client tx. This method removes the client tx if it times out. * Finally if a server tx has no more client tx, it returns a timeout to the * server tx. */ public void processTimeout(TimeoutEvent timeOutEvent) { logger.debug("TimeoutEvent received"); SipProvider sipProvider = (SipProvider) timeOutEvent.getSource(); TransactionsMapping transactionsMapping = null; if (timeOutEvent.isServerTransaction()) { ServerTransaction serverTransaction = timeOutEvent .getServerTransaction(); transactionsMapping = (TransactionsMapping) serverTransaction .getApplicationData(); transactionsMapping.removeMapping(serverTransaction); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -