3 new revisions:

Revision: 50cba29ad3bc
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 08:22:53 2012
Log:      Update Issue 121...
http://code.google.com/p/sipservlets/source/detail?r=50cba29ad3bc

Revision: b03d522db5ca
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 08:26:49 2012
Log:      Update Issue 121...
http://code.google.com/p/sipservlets/source/detail?r=b03d522db5ca

Revision: 320e0f15e629
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 09:52:36 2012
Log:      Update Issue 121...
http://code.google.com/p/sipservlets/source/detail?r=320e0f15e629

==============================================================================
Revision: 50cba29ad3bc
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 08:22:53 2012
Log:      Update Issue 121

Backporting to master

Fixing Click to Call Distributed Example to accept REGISTER requests
(cherry picked from commit 979514660f451db36ba4c81cc9c6421e8ff1698e)

http://code.google.com/p/sipservlets/source/detail?r=50cba29ad3bc

Modified:
/sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java

=======================================
--- /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java Thu Apr 28 11:18:14 2011 +++ /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java Mon Aug 6 08:22:53 2012
@@ -23,6 +23,7 @@
 package org.mobicents.servlet.sip.example;

 import java.io.IOException;
+import java.util.HashMap;

 import javax.annotation.Resource;
 import javax.servlet.ServletConfig;
@@ -203,4 +204,32 @@
        public void noPrackReceived(SipErrorEvent ee) {
                logger.info("Error: noPrackReceived.");
        }
-}
+
+ protected void doRegister(SipServletRequest req) throws ServletException, IOException {
+               logger.info("Received register request: " + req.getTo());
+               int response = SipServletResponse.SC_OK;
+               SipServletResponse resp = req.createResponse(response);
+ HashMap<String, String> users = (HashMap<String, String>) getServletContext().getAttribute("registeredUsersMap");
+               if(users == null) users = new HashMap<String, String>();
+               getServletContext().setAttribute("registeredUsersMap", users);
+
+               Address address = req.getAddressHeader(CONTACT_HEADER);
+               String fromURI = req.getFrom().getURI().toString();
+
+               int expires = address.getExpires();
+               if(expires < 0) {
+                       expires = req.getExpires();
+               }
+               if(expires == 0) {
+                       users.remove(fromURI);
+                       logger.info("User " + fromURI + " unregistered");
+               } else {
+                       resp.setAddressHeader(CONTACT_HEADER, address);
+                       users.put(fromURI, address.getURI().toString());
+                       logger.info("User " + fromURI +
+                                       " registered with an Expire time of " + 
expires);
+               }
+
+               resp.send();
+       }
+}

==============================================================================
Revision: b03d522db5ca
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 08:26:49 2012
Log:      Update Issue 121

Backporting to master

Adding dar file for the click2call distributed example
(cherry picked from commit ad76a288738b3c71c37910a4a4e19188fb4234de)

http://code.google.com/p/sipservlets/source/detail?r=b03d522db5ca

Added:
/sip-servlets-examples/click2call-distributable/click2call-distributable-dar.properties

=======================================
--- /dev/null
+++ /sip-servlets-examples/click2call-distributable/click2call-distributable-dar.properties Mon Aug 6 08:26:49 2012
@@ -0,0 +1,2 @@
+OPTIONS: ("DistributableClick2Call", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0") +REGISTER: ("DistributableClick2Call", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0")

==============================================================================
Revision: 320e0f15e629
Author:   Jean Deruelle <[email protected]>
Date:     Mon Aug  6 09:52:36 2012
Log:      Update Issue 121

Backport to master branch

Fixing Click to Call Distributed Example to have the web interface (as in non distributed) and still work correctly with failover
(cherry picked from commit 422a1b8b0f2241337197d871c6be7ae2253620e7)

http://code.google.com/p/sipservlets/source/detail?r=320e0f15e629

Added:
/sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/Call.java /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/CallStatusContainer.java /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/SimpleWebServlet.java
Modified:
/sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java /sip-servlets-examples/click2call-distributable/src/main/sipapp/WEB-INF/web.xml
 /sip-servlets-examples/click2call-distributable/src/main/sipapp/index.jsp

=======================================
--- /dev/null
+++ /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/Call.java Mon Aug 6 09:52:36 2012
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.servlet.sip.example;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import javax.servlet.sip.SipApplicationSession;
+import javax.servlet.sip.SipSession;
+import javax.servlet.sip.SipApplicationSession.Protocol;
+
+
+public class Call implements Serializable
+{
+       private String from;
+       private String to;
+       private String status;
+       private HashSet<String> sessions = new HashSet<String>();
+
+       public Call(String from, String to) {
+               this.from = from;
+               this.to = to;
+       }
+
+       public String getFrom() {
+               return from;
+       }
+
+       public String getTo() {
+               return to;
+       }
+
+       public void addSession(SipSession session) {
+               this.sessions.add(session.getId());
+       }
+
+       public void end(SipApplicationSession sipApplicationSession) {
+               Iterator it = this.sessions.iterator();
+               while(it.hasNext()) {
+                       String sessionId = (String) it.next();
+ SipSession session = (SipSession) sipApplicationSession.getSession(sessionId, Protocol.SIP);
+                       try {
+                               session.createRequest("BYE").send();
+                       } catch (Exception ex) {
+                               ex.printStackTrace();
+                       }
+               }
+       }
+
+       public String getStatus() {
+               return this.status;
+       }
+
+       public void setStatus(String status) {
+               this.status = status;
+       }
+
+       /* (non-Javadoc)
+        * @see java.lang.Object#hashCode()
+        */
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((from == null) ? 0 : 
from.hashCode());
+               result = prime * result + ((to == null) ? 0 : to.hashCode());
+               return result;
+       }
+
+       /* (non-Javadoc)
+        * @see java.lang.Object#equals(java.lang.Object)
+        */
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               Call other = (Call) obj;
+               if (from == null) {
+                       if (other.from != null)
+                               return false;
+               } else if (!from.equals(other.from))
+                       return false;
+               if (to == null) {
+                       if (other.to != null)
+                               return false;
+               } else if (!to.equals(other.to))
+                       return false;
+               return true;
+       }
+}
=======================================
--- /dev/null
+++ /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/CallStatusContainer.java Mon Aug 6 09:52:36 2012
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.servlet.sip.example;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class CallStatusContainer implements Serializable {
+
+       private HashSet<Call> activeCalls = new HashSet<Call> ();
+
+       public Call addCall(String from, String to, String status) {
+               Call call = new Call(from, to);
+               call.setStatus(status);
+               activeCalls.add(call);
+               return call;
+       }
+
+       public void removeCall(String from, String to) {
+               activeCalls.remove(new Call(from, to));
+       }
+
+       public void removeCall(Call call) {
+               activeCalls.remove(call);
+       }
+
+       public Call getCall(String from, String to) {
+               Iterator<Call> it = activeCalls.iterator();
+               while(it.hasNext()) {
+                       Call call = it.next();
+                       if(call.getFrom().equals(from) && 
call.getTo().equals(to))
+                               return call;
+               }
+               return null;
+       }
+
+       public String getStatus(String from, String to) {
+               Call call = getCall(from,to);
+               if(call != null) {
+                       return call.getStatus();
+               } else {
+                       return null;
+               }
+
+       }
+}
=======================================
--- /dev/null
+++ /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/SimpleWebServlet.java Mon Aug 6 09:52:36 2012
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.servlet.sip.example;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.sip.ConvergedHttpSession;
+import javax.servlet.sip.SipApplicationSession;
+import javax.servlet.sip.SipFactory;
+import javax.servlet.sip.SipServletRequest;
+import javax.servlet.sip.SipSession;
+import javax.servlet.sip.URI;
+
+import org.apache.log4j.Logger;
+
+public class SimpleWebServlet extends HttpServlet
+{
+       private static final long serialVersionUID = 1L;
+       private static Logger logger = Logger.getLogger(SimpleWebServlet.class);
+       private SipFactory sipFactory;
+
+       @Override
+       public void init(ServletConfig config) throws ServletException {
+               super.init(config);
+               logger.info("the SimpleWebServlet has been started");
+               try {
+                       // Getting the Sip factory from the JNDI Context
+                       Properties jndiProps = new Properties();
+                       Context initCtx = new InitialContext(jndiProps);
+                       Context envCtx = (Context) 
initCtx.lookup("java:comp/env");
+ sipFactory = (SipFactory) envCtx.lookup("sip/DistributableClick2Call/SipFactory");
+                       logger.info("Sip Factory ref from JNDI : " + 
sipFactory);
+               } catch (NamingException e) {
+                       throw new ServletException("Uh oh -- JNDI problem !", 
e);
+               }
+       }
+    /**
+     * Handle the HTTP GET method by building a simple web page.
+     */
+    public void doGet (HttpServletRequest request,
+                  HttpServletResponse response)
+    throws ServletException, IOException
+    {
+        String toAddr = request.getParameter("to");
+        String fromAddr = request.getParameter("from");
+        String bye = request.getParameter("bye");
+
+ URI to = toAddr==null? null : sipFactory.createAddress(toAddr).getURI(); + URI from = fromAddr==null? null : sipFactory.createAddress(fromAddr).getURI();
+
+
+        // Create app session and request
+        SipApplicationSession appSession =
+ ((ConvergedHttpSession)request.getSession()).getApplicationSession();
+
+ CallStatusContainer calls = (CallStatusContainer) appSession.getAttribute("activeCalls");
+
+        if(bye != null) {
+               if(bye.equals("all")) {
+                       Iterator it = (Iterator) appSession.getSessions("sip");
+                       while(it.hasNext()) {
+                               SipSession session = (SipSession) it.next();
+                               Call call = (Call) session.getAttribute("call");
+                               call.end(appSession);
+                               calls.removeCall(call);
+                       }
+               } else {
+ // Someone wants to end an established call, send byes and clean up
+                       Call call = calls.getCall(fromAddr, toAddr);
+                       call.end(appSession);
+                       calls.removeCall(call);
+               }
+        } else {
+               if(calls == null) {
+                       calls = new CallStatusContainer();
+                       appSession.setAttribute("activeCalls", calls);
+               }
+
+               // Add the call in the active calls
+               Call call = calls.addCall(fromAddr, toAddr, "FFFF00");
+               appSession.setAttribute("activeCalls", calls);
+
+ SipServletRequest req = sipFactory.createRequest(appSession, "INVITE", from, to);
+
+               // Set some attribute
+ req.getSession().setAttribute("SecondPartyAddress", sipFactory.createAddress(fromAddr));
+               req.getSession().setAttribute("call", call);
+
+               // This session will be used to send BYE
+               call.addSession(req.getSession());
+
+               logger.info("Sending request" + req);
+               // Send the INVITE request
+               req.send();
+        }
+
+        // Write the output html
+       PrintWriter     out;
+        response.setContentType("text/html");
+        out = response.getWriter();
+
+        // Just redirect to the index
+ out.println("<HTML><META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=index.jsp\"><HEAD><TITLE></HTML>");
+        out.close();
+    }
+}
=======================================
--- /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java Mon Aug 6 08:22:53 2012 +++ /sip-servlets-examples/click2call-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableClick2CallSipServlet.java Mon Aug 6 09:52:36 2012
@@ -35,6 +35,8 @@
 import javax.servlet.sip.SipServletRequest;
 import javax.servlet.sip.SipServletResponse;
 import javax.servlet.sip.SipSession;
+import javax.servlet.sip.SipApplicationSession.Protocol;
+import javax.servlet.sip.annotation.SipApplicationKey;

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -64,36 +66,13 @@
                super.init(servletConfig);
        }

-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void doInvite(SipServletRequest req) throws ServletException,
-                       IOException {
- logger.info("Click2Dial don't handle INVITE. Here's the one we got : " + req.toString()); - SipSession linkedSession = (SipSession) req.getSession().getAttribute("LinkedSession");
-               SipServletRequest r = linkedSession.createRequest("INVITE");
-               Object content = req.getContent();
-               if(content != null) {
-                       r.setContent(content, req.getContentType());
-               }
-               r.send();
-       }
-
-       @Override
-       protected void doOptions(SipServletRequest req) throws ServletException,
-                       IOException {
-               logger.info("Got :  " + req.toString());
-               req.createResponse(SipServletResponse.SC_OK).send();
-       }
-
        @Override
     protected void doSuccessResponse(SipServletResponse resp)
                        throws ServletException, IOException {
                logger.info("Got OK");
                SipSession session = resp.getSession();

- if ("INVITE".equals(resp.getMethod()) && resp.getStatus() == SipServletResponse.SC_OK) {
+               if (resp.getStatus() == SipServletResponse.SC_OK) {

                        Boolean inviteSent = (Boolean) 
session.getAttribute("InviteSent");
                        if (inviteSent != null && inviteSent.booleanValue()) {
@@ -102,7 +81,6 @@
                        Address secondPartyAddress = (Address) resp.getSession()
                                        .getAttribute("SecondPartyAddress");
                        if (secondPartyAddress != null) {
- resp.getApplicationSession().setAttribute("setFromSipServletUA1", resp.getApplicationSession().getId());

                                SipServletRequest invite = 
sipFactory.createRequest(resp
                                                .getApplicationSession(), 
"INVITE", session
@@ -112,22 +90,27 @@
                                                + secondPartyAddress);

                                String contentType = resp.getContentType();
-                               if (contentType != null) {
-                                       invite.setContent(resp.getContent(), 
contentType);
+                               if 
(contentType.trim().equals("application/sdp")) {
+                                       invite.setContent(resp.getContent(), 
"application/sdp");
                                }

-                               session.setAttribute("LinkedSession", 
invite.getSession());
-                               
invite.getSession().setAttribute("LinkedSession", session);
+                               session.setAttribute("LinkedSessionId", 
invite.getSession().getId());
+                               
invite.getSession().setAttribute("LinkedSessionId", session.getId());

                                SipServletRequest ack = resp.createAck();
                                
invite.getSession().setAttribute("FirstPartyAck", ack);
invite.getSession().setAttribute("FirstPartyContent", resp.getContent());

+                               Call call = (Call) session.getAttribute("call");
+
+                               // The call links the two sessions, add the new 
session to the call
+                               call.addSession(invite.getSession());
+                               invite.getSession().setAttribute("call", call);
+
                                invite.send();

                                session.setAttribute("InviteSent", 
Boolean.TRUE);
                        } else {
- resp.getApplicationSession().setAttribute("setFromSipServletUA2", resp.getApplicationSession().getId());
                                String cSeqValue = resp.getHeader("CSeq");
                                if(cSeqValue.indexOf("INVITE") != -1) {
                                        logger.info("Got OK from second party -- 
sending ACK");
@@ -136,16 +119,13 @@
                                        SipServletRequest firstPartyAck = 
(SipServletRequest) resp
                                                        
.getSession().getAttribute("FirstPartyAck");

-                                       if (resp.getContentType() != null) {
+// if (resp.getContentType() != null && resp.getContentType().equals("application/sdp")) {
                                                
firstPartyAck.setContent(resp.getContent(),
-                                                               
resp.getContentType());
+                                                               
"application/sdp");
secondPartyAck.setContent(resp.getSession().getAttribute("FirstPartyContent"),
-                                                               
resp.getContentType());
-                                       }
-
-                                       session.setAttribute("LinkedSession", 
firstPartyAck.getSession());
-                                       
firstPartyAck.getSession().setAttribute("LinkedSession", session);
-
+                                                               
"application/sdp");
+//                                     }
+
                                        firstPartyAck.send();
                                        secondPartyAck.send();
                                }
@@ -157,6 +137,10 @@
protected void doErrorResponse(SipServletResponse resp) throws ServletException,
                        IOException {
                // If someone rejects it remove the call from the table
+ CallStatusContainer calls = (CallStatusContainer) resp.getApplicationSession().getAttribute("activeCalls"); + calls.removeCall(resp.getFrom().getURI().toString(), resp.getTo().getURI().toString()); + calls.removeCall(resp.getTo().getURI().toString(), resp.getFrom().getURI().toString());
+               resp.getApplicationSession().setAttribute("activeCalls", calls);

        }

@@ -165,15 +149,20 @@
                        IOException {
                logger.info("Got bye");
                SipSession session = request.getSession();
-               SipSession linkedSession = (SipSession) session
-                               .getAttribute("LinkedSession");
-               if (linkedSession != null) {
-                       SipServletRequest bye = 
linkedSession.createRequest("BYE");
-                       logger.info("Sending bye to " + 
linkedSession.getRemoteParty());
-                       bye.send();
-               } else {
-                       throw new RuntimeException("linkedSession is not replicated 
correctly");
-               }
+               String linkedSessionId= (String) 
session.getAttribute("LinkedSessionId");
+               logger.info("linked session id = " + linkedSessionId);
+               if(linkedSessionId != null) {
+ SipSession linkedSession = (SipSession) request.getApplicationSession().getSession(linkedSessionId, Protocol.SIP);
+                       if (linkedSession != null) {
+                               SipServletRequest bye = 
linkedSession.createRequest("BYE");
+                               logger.info("Sending bye to " + 
linkedSession.getRemoteParty());
+                               bye.send();
+                       }
+               }
+ CallStatusContainer calls = (CallStatusContainer) request.getApplicationSession().getAttribute("activeCalls"); + calls.removeCall(request.getFrom().getURI().toString(), request.getTo().getURI().toString()); + calls.removeCall(request.getTo().getURI().toString(), request.getFrom().getURI().toString());
+               request.getApplicationSession().getAttribute("activeCalls");
                SipServletResponse ok = request
                                .createResponse(SipServletResponse.SC_OK);
                ok.send();
@@ -209,9 +198,9 @@
                logger.info("Received register request: " + req.getTo());
                int response = SipServletResponse.SC_OK;
                SipServletResponse resp = req.createResponse(response);
- HashMap<String, String> users = (HashMap<String, String>) getServletContext().getAttribute("registeredUsersMap"); + HashMap<String, String> users = (HashMap<String, String>) req.getApplicationSession().getAttribute("registeredUsersMap");
                if(users == null) users = new HashMap<String, String>();
-               getServletContext().setAttribute("registeredUsersMap", users);
+               req.getApplicationSession().setAttribute("registeredUsersMap", 
users);

                Address address = req.getAddressHeader(CONTACT_HEADER);
                String fromURI = req.getFrom().getURI().toString();
@@ -232,4 +221,12 @@

                resp.send();
        }
-}
+
+       @SipApplicationKey
+ public static String makeAppSessionKey(SipServletRequest sipServletRequest) {
+               if("REGISTER".equalsIgnoreCase(sipServletRequest.getMethod())) {
+                       return "registeredUsersMapAppSession";
+               }
+               return null;
+       }
+}
=======================================
--- /sip-servlets-examples/click2call-distributable/src/main/sipapp/WEB-INF/web.xml Wed Apr 1 13:52:46 2009 +++ /sip-servlets-examples/click2call-distributable/src/main/sipapp/WEB-INF/web.xml Mon Aug 6 09:52:36 2012
@@ -6,7 +6,7 @@
        <distributable/>
        <servlet>
         <servlet-name>ClickToCall</servlet-name>
- <servlet-class>org.mobicents.servlet.sip.example.DistributableClick2CallHttpServletServlet</servlet-class> + <servlet-class>org.mobicents.servlet.sip.example.SimpleWebServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
=======================================
--- /sip-servlets-examples/click2call-distributable/src/main/sipapp/index.jsp Wed Apr 1 13:52:46 2009 +++ /sip-servlets-examples/click2call-distributable/src/main/sipapp/index.jsp Mon Aug 6 09:52:36 2012
@@ -1,32 +1,88 @@
+<%@ page import="java.util.HashMap"%>
 <%@ page import="org.mobicents.servlet.sip.example.*"%>
-<%@ page import="javax.servlet.sip.*"%>
+<%@ page import="javax.servlet.sip.*"%>
 <html>
+<title>Click To Call Demo</title>
 <head>
-<title>Sample "Hello, World" Application</title>
-</head>
-<body>
-
-<p><font size="6">Simple Click To Call Demo</font></p>
-<form method="GET" action="call">
-
-       <p>To:</p>
- <p><input type="text" name="to" size="20" value="sip:[email protected]:5050"></p>
-       <p>From:</p>
- <p><input type="text" name="from" size="20" value="sip:[email protected]:5060"></p> - <p><input type="submit" value="Call" name="B1"><input type="reset" value="Reset" name="B2"></p>
-</form>
-<p>&nbsp;</p>
+<style>
+body { font-family: Tahoma, Geneva, 'Trebuchet MS', Arial, Helvetica, sans-serif; }
+
+.calltable, a {
+       border: 1px solid #D4E0EE;
+       border-collapse: collapse;
+       font-family: "Trebuchet MS", Arial, sans-serif;
+       color: #555;
+}
+
+.headtable {
+       border: none;
+       width: 100%;
+}
+
+td.calltable, tr {
+       padding: 4px;
+border: 1px dotted black;
+}
+</style>
+</head>
+<body>
+<table class="headtable"><tr>
+<td style="vertical-align:middle"><img alt="Mobicents" src="images/mobicents.logo.jpeg"/> +<a style="font-size: 30px;margin-left:100px"><b>Click-to-Call Sample Application</b></a></td>
+</tr></table>
 <hr/>
-<a>Debug</a>
 <%
-SipApplicationSession appSession =
- ((ConvergedHttpSession)request.getSession()).getApplicationSession(); -out.println("<br/>appSession.setFromSipServletUA1=" + appSession.getAttribute("setFromSipServletUA1")); -out.println("<br/>appSession.setFromSipServletUA2=" + appSession.getAttribute("setFromSipServletUA2")); -out.println("<br/>appSession.setFromHttpServlet=" + appSession.getAttribute("setFromHttpServlet"));
-out.println("<br/>JSESSIONID=" + request.getSession().getId());
-out.println("<br/>APPSESSIONID=" + appSession.getId());
-%>
-
+SipSessionsUtil sessionsUtil = (SipSessionsUtil) getServletContext().getAttribute("javax.servlet.sip.SipSessionsUtil"); +SipApplicationSession sipApplicationSession = sessionsUtil.getApplicationSessionByKey("registeredUsersMapAppSession", false);
+HashMap<String, String> users = null;
+if(sipApplicationSession != null) {
+ users = (HashMap<String, String>) sipApplicationSession.getAttribute("registeredUsersMap");
+}
+if(users == null) {
+ out.println("<a>No registered users. Please register at least two SIP User Agents.</a><br/>");
+} else {
+       String[] userArray = new String[0];
+       userArray = users.keySet().toArray(userArray);
+
+        // Create app session and request
+    SipApplicationSession appSession =
+       ((ConvergedHttpSession)request.getSession()).getApplicationSession();
+
+ CallStatusContainer calls = (CallStatusContainer) appSession.getAttribute("activeCalls");
+
+       out.println("<table class=\"calltable\">");
+       out.println("<tr><td bgcolor=\"#DDDDDD\">From \\ To</td>");
+ for(String col:userArray) out.println("<td class=\"calltable\" bgcolor=\"#EEEEEE\"><b>" + col + "</b></td>");
+       out.println("</tr>");
+       for(String fromAddr:userArray) {
+               out.println("<tr><td bgcolor=\"#EEEEEE\"><b>"+fromAddr 
+"</b></td>");
+               String fromAddrV = users.get(fromAddr);
+               for(String toAddr:userArray) {
+                       if(!toAddr.equals(fromAddr)) {
+                               String toAddrV = users.get(toAddr);
+                               String status = calls==null? 
null:calls.getStatus(fromAddrV, toAddrV);
+                               if(status == null) status = "FFFFFF"; // This 
is hex RGB color
+                               if(status.equals("FFFFFF"))
+                                       out.println("<td class=\"calltable\" 
bgcolor=\"#" + status
+                                               + "\" align=\"center\"><a 
href=\"call?to="
+                                               + users.get(toAddr) + "&from="
+                                               + users.get(fromAddr) 
+"\"\">call</a></td>");
+                               else
+                                       out.println("<td class=\"calltable\" 
bgcolor=\"#" + status
+                                                       + "\" align=\"center\"><a>call in progress 
</a><a href=\"call?to="
+                                                       + users.get(toAddr) + 
"&bye=true&from="
+                                                       + users.get(fromAddr) 
+"\"\">end</a></td>");
+
+                       } else {
+                               out.println("<td class=\"calltable\" ></td>");
+                       }
+               }
+               out.println("<tr>");
+       }
+       out.println("</table>");
+       out.println("<br/><a href=\"call?bye=all\">Close all calls</a>");
+}
+
+%>
 </body>
 </html>

Reply via email to