|
From: <ha...@us...> - 2008-09-08 21:21:23
|
Revision: 2142
http://cogkit.svn.sourceforge.net/cogkit/?rev=2142&view=rev
Author: hategan
Date: 2008-09-08 21:21:21 +0000 (Mon, 08 Sep 2008)
Log Message:
-----------
preserve case for requests; reply with bad request instead of not replying
Modified Paths:
--------------
trunk/current/src/cog/modules/provider-coaster/src/org/globus/cog/abstraction/impl/execution/coaster/BootstrapService.java
Modified: trunk/current/src/cog/modules/provider-coaster/src/org/globus/cog/abstraction/impl/execution/coaster/BootstrapService.java
===================================================================
--- trunk/current/src/cog/modules/provider-coaster/src/org/globus/cog/abstraction/impl/execution/coaster/BootstrapService.java 2008-09-08 21:20:19 UTC (rev 2141)
+++ trunk/current/src/cog/modules/provider-coaster/src/org/globus/cog/abstraction/impl/execution/coaster/BootstrapService.java 2008-09-08 21:21:21 UTC (rev 2142)
@@ -28,6 +28,7 @@
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -80,6 +81,7 @@
private void loadList() {
URL url = BootstrapService.class.getClassLoader().getResource(
ServiceManager.BOOTSTRAP_LIST);
+ System.err.println(url);
if (url == null) {
throw new RuntimeException(ServiceManager.BOOTSTRAP_LIST
+ " not found in classpath");
@@ -100,6 +102,7 @@
+ d[0]);
}
valid.add("/" + d[0]);
+ System.err.println(d[0]);
checksums.put("/" + d[0], d[1]);
line = br.readLine();
}
@@ -161,8 +164,8 @@
}
else {
ServerSocket socket = channel.socket();
- if (CoGProperties.getDefault().getIPAddress() != null) {
- return "http://" + CoGProperties.getDefault().getIPAddress()
+ if (CoGProperties.getDefault().getHostName() != null) {
+ return "http://" + CoGProperties.getDefault().getHostName()
+ ":" + socket.getLocalPort();
}
else {
@@ -271,6 +274,8 @@
+ "<h1>Error: Your are not authorized to access this resource</h1></body></html>\n";
public static final String ERROR_NOTFOUND = "<html><head><title>Error</title></head><body>"
+ "<h1>Error: The requested resource is not available</h1></body></html>\n";
+ public static final String ERROR_BAD_REQUEST = "<html><head><title>Error</title></head><body>"
+ + "<h1>Error: The request could not be understood by this server</h1></body></html>\n";
private SocketChannel channel;
private int state;
@@ -369,10 +374,14 @@
if (logger.isDebugEnabled()) {
logger.debug("Headers: " + headers);
}
- cmd = cmd.toLowerCase();
String[] tokens = cmd.split("\\s+");
- if (tokens[0].equals("get")) {
- String page = tokens[1];
+ if (tokens[0].equals("GET")) {
+ String page = getPage(tokens[1]);
+ Map cgiParams = getCGIParams(tokens[1]);
+ String coasterId = (String) cgiParams.get("serviceId");
+ if (coasterId != null) {
+ ServiceManager.getDefault().serviceIsActive(coasterId);
+ }
if (page.equals("/")) {
page = "/index.html";
}
@@ -387,6 +396,9 @@
}
key.interestOps(SelectionKey.OP_WRITE);
}
+ else {
+ sendError("400 Bad Request", ERROR_BAD_REQUEST);
+ }
}
private void sendError(String error, String html) {
@@ -444,6 +456,37 @@
channel.close();
processor.removeChannel(channel);
}
+
+ private String getPage(String local) {
+ int i = local.indexOf('?');
+ if (i == -1) {
+ return local;
+ }
+ else {
+ return local.substring(0, i);
+ }
+ }
+
+ private Map getCGIParams(String local) {
+ int i = local.indexOf('?');
+ if (i == -1) {
+ return Collections.EMPTY_MAP;
+ }
+ else {
+ Map m = new HashMap();
+ String[] params = local.substring(i).split("&");
+ for (int j = 0; j < params.length; j++) {
+ int k = params[j].indexOf('=');
+ if (k == -1) {
+ //not valid, discard parameter
+ }
+ else {
+ m.put(params[j].substring(0, k), params[j].substring(k + 1));
+ }
+ }
+ return m;
+ }
+ }
}
public static void main(String[] args) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|