package com.c2kernel.process; import java.util.StringTokenizer; import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.utils.server.HTTPRequestHandler; /* QueryData over HTTP Socket Handler * Processes an HTTP request consisting of // * and returns that kernel object as XML * Currently supports GET requests. * REVISIT: POST calls Item.request() */ public class ItemHTTPBridge extends HTTPRequestHandler { public ItemHTTPBridge() { } @Override public String getName() { return "Item HTTP Server"; } @Override public String processRequest() { System.out.println("ItemHTTPBridge::ProcessRequest()"); StringTokenizer tok = new StringTokenizer(resource, "?"); String path = tok.nextToken(); String query = tok.nextToken(); ItemPath itemPath; try { itemPath = new ItemPath(UUID.fromString(path)); } catch (IllegalArgumentException ex) { DomainPath domPath = new DomainPath(path); if (!domPath.exists()) return error("404 Not Found", "The path "+path+" you requested was not found."); try { itemPath = domPath.getItemPath(); } catch (ObjectNotFoundException e) { return error("404 Not Found", "The path "+path+" you requested was not found."); } } if (method.equals("GET")) { try { C2KLocalObject response = Gateway.getStorage().get(itemPath, query, null); return Gateway.getMarshaller().marshall(response); } catch (Exception e) { return error("400 Bad Request", "Usage: GET <path to item>?<path to kernel object>
"+e.getClass().getName()); } } return(super.processRequest()); } }