Author: mes
Date: 2012-07-26 14:42:37 -0700 (Thu, 26 Jul 2012)
New Revision: 30009
Added:
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/net/server/CommandGetResponder.java
csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.R
csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.py
csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.sh
Modified:
csplugins/trunk/ucsd/mes/rest-impl/
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/CyActivator.java
Log:
added get responder
Property changes on: csplugins/trunk/ucsd/mes/rest-impl
___________________________________________________________________
Added: svn:ignore
+ target
Modified:
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/CyActivator.java
===================================================================
---
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/CyActivator.java
2012-07-26 21:37:06 UTC (rev 30008)
+++
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/CyActivator.java
2012-07-26 21:42:37 UTC (rev 30009)
@@ -1,6 +1,7 @@
package org.cytoscape.rest.internal;
import org.cytoscape.rest.internal.net.server.CommandPostResponder;
+import org.cytoscape.rest.internal.net.server.CommandGetResponder;
import org.cytoscape.rest.internal.net.server.LocalHttpServer;
import org.cytoscape.command.CommandExecutorTaskFactory;
import org.cytoscape.work.SynchronousTaskManager;
@@ -30,6 +31,7 @@
public void run() {
server = new LocalHttpServer(2609,
Executors.newSingleThreadExecutor());
server.addPostResponder(new
CommandPostResponder(cetf,stm));
+ server.addGetResponder(new
CommandGetResponder(cetf,stm));
server.run();
}
};
Added:
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/net/server/CommandGetResponder.java
===================================================================
---
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/net/server/CommandGetResponder.java
(rev 0)
+++
csplugins/trunk/ucsd/mes/rest-impl/src/main/java/org/cytoscape/rest/internal/net/server/CommandGetResponder.java
2012-07-26 21:42:37 UTC (rev 30009)
@@ -0,0 +1,72 @@
+package org.cytoscape.rest.internal.net.server;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.net.URLDecoder;
+
+import org.cytoscape.command.CommandExecutorTaskFactory;
+import org.cytoscape.work.SynchronousTaskManager;
+import org.cytoscape.rest.internal.net.server.LocalHttpServer.Response;
+import org.json.JSONObject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is responsible for handling POST requests received by the local
HTTP server.
+ */
+public class CommandGetResponder implements LocalHttpServer.GetResponder{
+
+ private final CommandExecutorTaskFactory cetf;
+ private final SynchronousTaskManager stm;
+ private final static Logger logger =
LoggerFactory.getLogger(CommandGetResponder.class);
+
+ public CommandGetResponder(CommandExecutorTaskFactory cetf,
SynchronousTaskManager stm) {
+ this.cetf = cetf;
+ this.stm = stm;
+ }
+
+ @Override
+ public boolean canRespondTo(String url) throws Exception {
+ return (url.indexOf("cytoscape") >= 0);
+ }
+
+ @Override
+ public Response respond(String url) throws Exception {
+ System.out.println("GET url : " + url);
+ String[] full = url.split("/");
+ int i = 0;
+ while (i<full.length) {
+ if (full[i].equals("cytoscape"))
+ break;
+ i++;
+ }
+
+ String namespace = full[++i];
+ String command = full[++i];
+ String args = "";
+ while (i<full.length-1)
+ args = args + full[++i] + "/";
+ args = args.replaceAll("&"," ");
+
+ String fullCommand = namespace + " " + command + " " + args;
+
+ System.out.println("GET command : " + fullCommand);
+
+ stm.execute(cetf.createTaskIterator(fullCommand));
+
+ Map<String, String> responseData = new HashMap<String,
String>();
+
+ responseData.put("namespace",namespace);
+ responseData.put("command",command);
+ responseData.put("args",args);
+ responseData.put("status","success");
+
+ JSONObject jsonObject = new JSONObject(responseData);
+
+ String responseBody = jsonObject.toString();
+ responseBody += "\n";
+ LocalHttpServer.Response response = new
LocalHttpServer.Response(responseBody, "application/json");
+ return response;
+ }
+}
Added: csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.R
===================================================================
--- csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.R
(rev 0)
+++ csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.R
2012-07-26 21:42:37 UTC (rev 30009)
@@ -0,0 +1,9 @@
+
+# need to install RCurl
+# install.package("RCurl")
+# library("RCurl")
+
+res <-
getURL("http://127.0.0.1:2609/cytoscape/network/load-file/file=/Users/mes/galFiltered.sif")
+
+
+
Added: csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.py
===================================================================
--- csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.py
(rev 0)
+++ csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.py
2012-07-26 21:42:37 UTC (rev 30009)
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+import httplib, urllib
+conn = httplib.HTTPConnection("127.0.0.1:2609")
+conn.request("GET",
"/cytoscape/network/load-file/file=/Users/mes/galFiltered.sif")
+response = conn.getresponse()
+print response.status, response.reason
+data = response.read()
+conn.close()
Property changes on:
csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.py
___________________________________________________________________
Added: svn:executable
+ *
Added: csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.sh
===================================================================
--- csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.sh
(rev 0)
+++ csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.sh
2012-07-26 21:42:37 UTC (rev 30009)
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+curl
"http://127.0.0.1:2609/cytoscape/network/load-file/file=/Users/mes/galFiltered.sif"
+
+
Property changes on:
csplugins/trunk/ucsd/mes/rest-impl/src/main/resources/examples/get.sh
___________________________________________________________________
Added: svn:executable
+ *
--
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.