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

📄 imnotifyprocessing.java

📁 基于JAINSIP的一个proxy源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * IMNotifyProcessing.java * * Created on September 26, 2002, 12:14 AM */package gov.nist.sip.instantmessaging.presence;import gov.nist.javax.sip.*;import javax.sip.*;import javax.sip.message.*; import javax.sip.header.*;import javax.sip.address.*;import java.util.*;import gov.nist.sip.instantmessaging.*;import gov.nist.sip.instantmessaging.presence.pidfparser.*;import gov.nist.sip.instantmessaging.presence.cpimparser.*;/** * * @author  olivier * @version 1.0 */public class IMNotifyProcessing {     private IMUserAgent imUA;     private int cseq;     public XMLpidfParser xmlPidfParser;     public XMLcpimParser xmlCpimParser;        /** Creates new IMNotifyProcessing */    public IMNotifyProcessing( IMUserAgent imUA) {        this.imUA=imUA;        xmlPidfParser=new XMLpidfParser();        xmlCpimParser=new XMLcpimParser();        cseq=0;    }       public void processOk(Response response,ClientTransaction clientTransaction) {	DebugIM.println("Processing OK received for a NOTIFY ");	        // We have to particular processing to do with the OK..        DebugIM.println("OK processed!!!");    }            public void processNotify(Request request,ServerTransaction serverTransaction) {        try {            InstantMessagingGUI imGUI=imUA.getInstantMessagingGUI();            ListenerInstantMessaging listenerIM=            imGUI.getListenerInstantMessaging();            MessageFactory messageFactory=imUA.getMessageFactory();            SipProvider sipProvider=imUA.getSipProvider();                        DebugIM.println("Process NOTIFY in progress...");            String fromURL=IMUtilities.getKey(request,"From");            ExpiresHeader expiresHeader=(ExpiresHeader)request.getHeader(ExpiresHeader.NAME);            SubscriptionStateHeader subscriptionStateHeader = 		(SubscriptionStateHeader)request.getHeader(SubscriptionStateHeader.NAME);            PresenceManager presenceManager=imUA.getPresenceManager();            /*            Presentity presentity=presenceManager.getPresentity(fromURL);            Dialog dialog=presentity.getDialog();            if (dialog==null) {                 DebugIM.println("ERROR, processNotify(), PB to retrieve the dialog");                 return;            }            */            	    //According to RFC3265 the ExpiresHeader should not exist in a NOTIFY	    // so it should go. Leaving it for backwards compability reasons for now            if ((expiresHeader!=null && expiresHeader.getExpires()==0) ||		(subscriptionStateHeader!=null && 		 subscriptionStateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)))	    { 	                    DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                " this is the NOTIFY related to the \"unSUBSCRIBE\"...");                // We have to update the buddy list!!!                    BuddyList buddyList=imGUI.getBuddyList();                    buddyList.changeBuddyStatus(fromURL,"offline");                                        // We can update the information field for the ChatFrame:                    ChatSessionManager chatSessionManager=listenerIM.getChatSessionManager();                    ChatSession chatSession=chatSessionManager.getChatSession(fromURL);                    if (chatSession==null) {                             DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                    " the chat session does not exist, no need to update the chatFrame!!!");                    }                    else {                             DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                    " the chat session does exist,  need to update the chatFrame!!!");                                                        chatSession.setInfo("The contact is offline");                    }                                        // Send an OK                    Response response=messageFactory.createResponse				(Response.OK,request);                    serverTransaction.sendResponse(response);                    DebugIM.println("OK replied to the NOTIFY");                                                          // WE have to update the presentity list: the status has changed!!!                                       presenceManager.updatePresentity(fromURL,"offline");                                        // Very important: we need to subscribe again!!!                    // Henrik: don't understand... if the user has removed the presentity, 		    //    why should it be resubscribed to? And without updating GUI?		    //IMSubscribeProcessing imSubscribeProcessing=imUA.getIMSubscribeProcessing();                    //imSubscribeProcessing.sendSubscribe(listenerIM.getLocalSipURL(),fromURL,false);            }            else {                		                Object content=request.getContent();                String text=null;                if (content instanceof String) {                    text=(String)content;                } else  if (content instanceof byte[] ) {		    text=new String(  (byte[])content  );		} else {		    DebugIM.println("DEBUG, IMNotifyProcessing, process(), "+			       " Error, the body of the request is unknown!!");		    DebugIM.println("ERROR, IMNotifyProcessing, process(): "+			       " pb with the xml body, 488 Not Acceptable Here replied");		    Response response=messageFactory.createResponse			(Response.NOT_ACCEPTABLE,request);		    serverTransaction.sendResponse(response);		    return;		}                                    if (text!=null && !text.trim().equals("") ) {                    // we have to parse the XML body!!!!                    try{                        ContentTypeHeader contentTypeHeader=(ContentTypeHeader)                        request.getHeader(ContentTypeHeader.NAME);                        String xmlType=contentTypeHeader.getContentSubType();                                                 DebugIM.println("DEBUG, IMNotifyProcessing, process(), the XML body format"+                        " is: "+xmlType);                        String status=null;                        if (xmlType.equals("xpidf+xml") ) {                            xmlPidfParser.parsePidfString(text);                             gov.nist.sip.instantmessaging.presence.pidfparser.PresenceTag                            presenceTag=xmlPidfParser.getPresenceTag();                            if (presenceTag==null)                                 DebugIM.println("ERROR: The presence Tag is null!!!");                            else                                DebugIM.println("the parsed body:"+presenceTag.toString());                                                        Vector atomTagList=presenceTag.getAtomTagList();                            AtomTag atomTag=(AtomTag)atomTagList.firstElement();                            AddressTag addressTag=atomTag.getAddressTag();                            MSNSubStatusTag msnSubStatusTag=addressTag.getMSNSubStatusTag();                            status=msnSubStatusTag.getMSNSubStatus();                        }                        else                             if (xmlType.equals("pidf+xml") ) {                                                               xmlCpimParser.parseCPIMString(text.trim());                                gov.nist.sip.instantmessaging.presence.cpimparser.PresenceTag 				    presenceTag=xmlCpimParser.getPresenceTag();                                if (presenceTag==null)                                    DebugIM.println("ERROR: The presence Tag is null!!!");                                else                                    DebugIM.println("the parsed body:"+presenceTag.toString());                                                                Vector tupleTagList=presenceTag.getTupleTagList();				NoteTag noteTag = null;				if (tupleTagList.size() > 0)  {                                	TupleTag tupleTag=(TupleTag)tupleTagList.firstElement();                                 	noteTag=tupleTag.getNoteTag();				}                                 if (noteTag!=null)                                    status=noteTag.getNote();                                else status="offline";                                DebugIM.println("status:"+status);                            }                                                                        // Send an OK                        Response response=messageFactory.createResponse                        (Response.OK,request);                        serverTransaction.sendResponse(response);                        DebugIM.println("OK replied to the NOTIFY");                                                                        // We have to update the buddy list!!!                        BuddyList buddyList=imGUI.getBuddyList();                        buddyList.changeBuddyStatus(fromURL,status);                                                // We can update the information field for the ChatFrame:                        ChatSessionManager chatSessionManager=listenerIM.getChatSessionManager();                        ChatSession chatSession=chatSessionManager.getChatSession(fromURL);                        if (chatSession==null) {                            DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                            " the chat session does not exist, no need to update the chatFrame!!!");                        }                        else {

⌨️ 快捷键说明

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