Author: paperwing
Date: 2012-05-08 16:04:40 -0700 (Tue, 08 May 2012)
New Revision: 29160

Added:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
Removed:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/LocalGetResponder.java
Modified:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
Log:
Minor updates; renamed responder class, completed method for parsing encoded 
URL. About to add support for the Cytoscape-App-Works-With tag in the jar 
manifest which indicates the versions of Cytoscape that the app is known to 
work with

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-05-08 22:36:27 UTC (rev 29159)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-05-08 23:04:40 UTC (rev 29160)
@@ -5,6 +5,7 @@
 import org.cytoscape.app.internal.action.AppManagerAction;
 import org.cytoscape.app.internal.manager.AppManager;
 import org.cytoscape.app.internal.net.WebQuerier;
+import org.cytoscape.app.internal.net.server.AppGetResponder;
 import org.cytoscape.app.internal.net.server.LocalHttpServer;
 import org.cytoscape.app.internal.net.server.LocalHttpServer.Response;
 import org.cytoscape.app.swing.CySwingAppAdapter;
@@ -346,7 +347,7 @@
                registerService(bc, webQuerier, WebQuerier.class, new 
Properties());
                
                // Attempt to instantiate new manager
-               AppManager appManager = new AppManager(
+               final AppManager appManager = new AppManager(
                                cyAppAdapter, 
cyApplicationConfigurationServiceRef, webQuerier);
                registerService(bc, appManager, AppManager.class, new 
Properties());
                
@@ -361,16 +362,7 @@
                        @Override
                        public void run() {
                                server = new LocalHttpServer(2608, 
Executors.newSingleThreadExecutor());
-                               server.addGetResponder(new 
LocalHttpServer.GetResponder() {
-                                       public boolean canRespondTo(String url) 
{
-                                           return true;
-                                       }
-
-                                       @Override
-                                       public LocalHttpServer.Response 
respond(String url) throws Exception {
-                                               return new 
LocalHttpServer.Response("sample response body for url: " + url + "\n", 
"application/json");
-                                       }
-                               });
+                               server.addGetResponder(new 
AppGetResponder(appManager));
                                
                                server.run();
                        }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-05-08 22:36:27 UTC (rev 29159)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-05-08 23:04:40 UTC (rev 29160)
@@ -32,6 +32,12 @@
        private static final String APP_VERSION_TAG = "Cytoscape-App-Version";
        
        /**
+        * The name of the key in the app jar's manifest file indicating the 
major versions of
+        * Cytoscape that the app is known to be compatible with in 
comma-delimited form
+        */
+       private static final String APP_COMPATIBLE_TAG = 
"Cytoscape-App-Works-With";
+       
+       /**
         * A regular a expression representing valid app versions, which are in 
the format major.minor.patch[-tag]
         */
        private static final String APP_VERSION_TAG_REGEX = 
"(0|([1-9]+\\d*))\\.(\\d)+\\.(\\d)+(-.*)?";

Copied: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
 (from rev 29141, 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/LocalGetResponder.java)
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
                          (rev 0)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
  2012-05-08 23:04:40 UTC (rev 29160)
@@ -0,0 +1,93 @@
+package org.cytoscape.app.internal.net.server;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cytoscape.app.internal.manager.AppManager;
+import org.cytoscape.app.internal.net.server.LocalHttpServer.Response;
+
+/**
+ * This class is responsible for handling GET requests received by the local 
HTTP server.
+ */
+public class AppGetResponder implements LocalHttpServer.GetResponder{
+
+       private static final String STATUS_QUERY_URL = "status";
+       private static final String STATUS_QUERY_APP_NAME = "appname";
+       
+       private static final String INSTALL_QUERY_URL = "install";
+       private static final String INSTALL_QUERY_APP_NAME = "appname";
+       
+       private AppManager appManager;
+       
+       @Override
+       public boolean canRespondTo(String url) throws Exception {
+               return true;
+       }
+
+       @Override
+       public Response respond(String url) throws Exception {
+               Map<String, String> parsed = parseEncodedUrl(url);
+               
+               System.out.println("Request received. Url: " + url);
+               System.out.println("Url request prefix: " + 
getUrlRequestPrefix(url));
+               System.out.println("Parsed result of encoded url: " + parsed);
+               
+               LocalHttpServer.Response response = new 
LocalHttpServer.Response("test response", "text/plain");
+               
+               return response;
+       }
+       
+       public AppGetResponder(AppManager appManager) {
+               this.appManager = appManager;
+
+       }
+       
+       /**
+        * Parses the parameters from an URL encoded in the 
application/x-www-form-urlencoded form, 
+        * which is the default form. This method uses a simple parsing method, 
only scanning text after the last '?' symbol
+        * and splitting with the '=' symbol. A more comprehensive (and 
possibly securer) parser can be found in the URLEncodedUtils 
+        * class of the Apache HttpClient library.
+        * 
+        * @param url The encoded URL in String form
+        * @return A map containing the encoded keys as keys and the 
corresponding encoded values as values.
+        */
+       private Map<String, String> parseEncodedUrl(String url) {
+               Map<String, String> parameters = new HashMap<String, String>();
+               
+               int lastIndex = url.lastIndexOf("?");
+               
+               if (lastIndex != -1) {
+                       String paramSubstring = url.substring(lastIndex + 1);
+                       
+                       String[] splitParameters = paramSubstring.split("&");
+                       
+                       
+                       String key, value;
+                       int equalSignIndex;
+                       for (int i = 0; i < splitParameters.length; i++) {
+                               equalSignIndex = 
splitParameters[i].indexOf('=');
+                               
+                               if (equalSignIndex != -1) {
+                                       key = splitParameters[i].substring(0, 
equalSignIndex);
+                                       value = 
splitParameters[i].substring(equalSignIndex + 1);
+                                       
+                                       parameters.put(key, value);
+                               }
+                       }
+               }
+               
+               return parameters;
+       }
+       
+       /**
+        * Returns the request prefix for a URL encoded according to the 
application/x-www-form-urlencoded specification, ie.
+        * returns "installed" for 
"http://127.0.0.1:2608/installed?appname=3d&version=1.0.0";
+        */
+       private String getUrlRequestPrefix(String url) {
+               
+               // Use the last occurrence of the question mark
+               int lastIndex = url.lastIndexOf("?");
+               
+               return url.substring(url.indexOf("/"), lastIndex);
+       }
+}


Property changes on: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Deleted: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/LocalGetResponder.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/LocalGetResponder.java
        2012-05-08 22:36:27 UTC (rev 29159)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/server/LocalGetResponder.java
        2012-05-08 23:04:40 UTC (rev 29160)
@@ -1,48 +0,0 @@
-package org.cytoscape.app.internal.net.server;
-
-import java.util.Map;
-
-import org.cytoscape.app.internal.net.server.LocalHttpServer.Response;
-
-/**
- * This class is responsible for handling GET requests received by the local 
HTTP server.
- */
-public class LocalGetResponder implements LocalHttpServer.GetResponder{
-
-       private static final String STATUS_QUERY_URL = "status";
-       private static final String STATUS_QUERY_APP_NAME = "appname";
-       
-       private static final String INSTALL_QUERY_URL = "install";
-       private static final String INSTALL_QUERY_APP_NAME = "appname";
-       
-       
-       @Override
-       public boolean canRespondTo(String url) throws Exception {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public Response respond(String url) throws Exception {
-               // TODO Auto-generated method stub
-               return null;
-       }
-       
-       
-       /**
-        * Parses the parameters from an URL encoded in the 
application/x-www-form-urlencoded form, 
-        * which is the default form. This method uses a simple parsing method, 
only scanning text after the last '?' symbol
-        * and splitting with the '=' symbol. A more comprehensive (and 
possibly securer) parser can be found in the URLEncodedUtils 
-        * class of the Apache HttpClient library.
-        * 
-        * @param url
-        * @return
-        */
-       private Map<String, String> parseEncodedUrl(String url) {
-               int lastIndex = url.lastIndexOf("?");
-               
-               String paramSubstring = url.substring(lastIndex);
-               
-               return null;
-       }
-}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to