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

📄 imnotifyprocessing.java

📁 基于JAINSIP的一个proxy源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                            " the chat session does exist,  need to update the chatFrame!!!");                            chatSession.setInfo("The contact is "+status);                                                    }                                                // WE have to update the presentity list: the status has changed!!!                        presenceManager.updatePresentity(fromURL,status);                                            }                    catch(Exception e) {                        //e.printStackTrace();                        DebugIM.println("ERROR, IMNotifyProcessing, process(): "+                        " pb with the xml body, 488 Not Acceptable Here replied");                        Response response=messageFactory.createResponse				(Response.NOT_ACCEPTABLE_HERE,request);                        serverTransaction.sendResponse(response);                                           e.printStackTrace();                    }                }                else {                    DebugIM.println("DEBUG, IMNotifyProcessing, processNotify(), "+                    " PB to get the NOTIFY xml body, 488 Not Acceptable Here replied");                                       Response response=messageFactory.createResponse                        (Response.NOT_ACCEPTABLE_HERE,request);                    serverTransaction.sendResponse(response);                }            }        }        catch (Exception ex) {            ex.printStackTrace();        }    }            public void sendNotifyToAllSubscribers(String status,String subStatus) {        try{             // We have to get all our subscribers and send them a NOTIFY!             PresenceManager presenceManager=imUA.getPresenceManager();             Vector subscribersList=presenceManager.getAllSubscribers();             DebugIM.println("DEBUG, IMNotifyProcessing, sendNotifyToAllSuscribers(),"+             " we have to notify our SUBSCRIBERS: let's send a NOTIFY for each one "+             "of them (subscribersList: "+subscribersList.size()+")!!!");             for (int i=0;i<subscribersList.size();i++) {                Subscriber subscriber=(Subscriber)subscribersList.elementAt(i);                                 Response okSent=subscriber.getOkSent();                String subscriberName=subscriber.getSubscriberName();                                String contactAddress= imUA.getIMAddress()+":"+                                       imUA.getIMPort();                String xmlBody=null;                //if (!status.equals("closed") )                    xmlBody=xmlPidfParser.createXMLBody(status,subStatus,subscriberName,                    contactAddress);                                Dialog dialog=subscriber.getDialog();                if (dialog==null) {                    DebugIM.println("ERROR, sendNotifyToAllSubscribers(), PB to "+                    "retrieve the dialog, NOTIFY not sent!");                }                else                    sendNotify(okSent,xmlBody,dialog);             }	     	     //Send a PUBLISH request to our PA	     IMRegisterProcessing imRegisterProcessing = imUA.getIMRegisterProcessing();	     if (imRegisterProcessing.isRegistered()) {		 //Fetching the sip-uri from gui. Isn't that a bit odd?		 IMPublishProcessing imPublishProcessing = imUA.getIMPublishProcessing();		 javax.swing.JTextField guiSipURI = imUA.getInstantMessagingGUI().getLocalSipURLTextField();		 String localSipURI = guiSipURI.getText();		 int  colonIndex = localSipURI.indexOf(':');		 String localURI = localSipURI.substring(colonIndex+1); //strip off "sip:"		 imPublishProcessing.sendPublish(localURI, subStatus); //"fosfor@nitrogen.epact.se"	     }        }        catch (Exception ex) {            ex.printStackTrace();        }     }           public void sendNotify(Response okSent,String body,Dialog dialog) {        try{            // We send the NOTIFY!!!                        // we create the Request-URI: the one of the proxy            HeaderFactory headerFactory=imUA.getHeaderFactory();            AddressFactory addressFactory=imUA.getAddressFactory();            MessageFactory messageFactory=imUA.getMessageFactory();            SipProvider sipProvider=imUA.getSipProvider();                        String imProtocol=imUA.getIMProtocol();            String proxyAddress=imUA.getProxyAddress();            int proxyPort=imUA.getProxyPort();                        SipURI requestURI=null;            if (proxyAddress!=null) {                 requestURI=addressFactory.createSipURI(null,proxyAddress);                 requestURI.setPort(proxyPort);                 requestURI.setTransportParam(imProtocol);            }            else {                DebugIM.println("DEBUG, IMNotifyProcessing, sendNotify(), request-uri is null");                return;            }                                   Address localAddress=dialog.getLocalParty();            Address remoteAddress=dialog.getRemoteParty();                                    FromHeader fromHeader=headerFactory.createFromHeader(localAddress,dialog.getLocalTag());            ToHeader toHeader=headerFactory.createToHeader(remoteAddress,dialog.getRemoteTag());                        int cseq=dialog.getLocalSequenceNumber();            CSeqHeader cseqHeader=headerFactory.createCSeqHeader(cseq,"NOTIFY");                            CallIdHeader callIdHeader=dialog.getCallId();                         //  Via header            String branchId=Utils.generateBranchId();            ViaHeader viaHeader=headerFactory.createViaHeader(                imUA.getIMAddress(),imUA.getIMPort(),imProtocol,branchId);            Vector viaList=new Vector();            viaList.addElement(viaHeader);                        // MaxForwards header:            MaxForwardsHeader maxForwardsHeader=headerFactory.createMaxForwardsHeader(70);                        Request request=null;            ClientTransaction clientTransaction=null;            if (body==null) {                                request=messageFactory.createRequest(requestURI,"NOTIFY",                callIdHeader,cseqHeader,fromHeader,toHeader,viaList,maxForwardsHeader);                                           }            else {                body=body+"\r\n";                // Content-Type:                ContentTypeHeader contentTypeHeader=headerFactory.createContentTypeHeader(                "application","xpidf+xml");                                request=messageFactory.createRequest(requestURI,"NOTIFY",                callIdHeader,cseqHeader,fromHeader,toHeader,viaList,maxForwardsHeader                ,contentTypeHeader,body);                               }                     // WE have to add a new Header: "Subscription-State"	    // Modified by Henrik Leion            DebugIM.println("DEBUG, IMNotifyProcessing, sendNotify(), We add the Subscription-State"+			    " header to the request");	    String subscriptionState;	    if (body == null)		subscriptionState = "terminated";	    else		subscriptionState = "active";            Header header=headerFactory.createHeader("Subscription-State",subscriptionState);            request.setHeader(header);                        // WE have to add a new Header: "Event"            header=headerFactory.createHeader("Event","presence");            request.setHeader(header);                        // ProxyAuthorization header if not null:            ProxyAuthorizationHeader proxyAuthHeader=imUA.getProxyAuthorizationHeader();            if (proxyAuthHeader!=null)                 request.setHeader(proxyAuthHeader);                        clientTransaction=sipProvider.getNewClientTransaction(request);            dialog.sendRequest(clientTransaction);                        DebugIM.println("DEBUG, IMNotifyProcessing, sendNotify(),"+            " NOTIFY sent:\n" );            DebugIM.println(request.toString());	    //Added by Henrik Leion	    //If the Notify ended the dialog (body was null and 	    //  SubscriptionStateHeader=terminated) the dialog should be deleted	    if (body==null) {		dialog.delete();	    }        }        catch (Exception ex) {            ex.printStackTrace();        }    }    }

⌨️ 快捷键说明

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