blob: 8ef2e5862fbe530866a8d14a04b1d7cd6959261d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package com.c2kernel.process;
import java.util.StringTokenizer;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.server.HTTPRequestHandler;
/* QueryData over HTTP Socket Handler
* Processes an HTTP request consisting of /<path to item>/<path to kernel object>
* and returns that kernel object as XML
* Currently supports GET requests.
* REVISIT: POST calls Item.request()
*/
public class ItemHTTPBridge extends HTTPRequestHandler {
public ItemHTTPBridge() { }
public String getName() {
return "Item HTTP Server";
}
public String processRequest() {
System.out.println("ItemHTTPBridge::ProcessRequest()");
StringTokenizer tok = new StringTokenizer(resource, "?");
String itemPath = tok.nextToken();
String query = tok.nextToken();
int sysKey = -1;
//Path path = Gateway.getLDAPLookup().;
if (method.equals("GET")) {
try {
DomainPath domPath = new DomainPath(itemPath);
EntityPath entityPath = domPath.getEntity();
if (sysKey > -1) {
C2KLocalObject response = Gateway.getStorage().get(sysKey, query, null);
return CastorXMLUtility.marshall(response);
}
else
return error("404 Not Found", "The entity "+sysKey+" you requested was not found.");
}
catch (Exception e) {
return error("400 Bad Request", "Usage: GET <path to item>?<path to kernel object><br>"+e.getClass().getName());
}
}
return(super.processRequest());
}
}
|