From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: Replaced int sysKey Item identifier with UUID, which is now portable. ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers. --- .../java/com/c2kernel/process/ItemHTTPBridge.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/c2kernel/process/ItemHTTPBridge.java') diff --git a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java index 6ad8e01..86e3659 100644 --- a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java +++ b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java @@ -1,8 +1,12 @@ 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 @@ -25,21 +29,26 @@ public class ItemHTTPBridge extends HTTPRequestHandler { public String processRequest() { System.out.println("ItemHTTPBridge::ProcessRequest()"); StringTokenizer tok = new StringTokenizer(resource, "?"); - //String itemPath = tok.nextToken(); + String path = tok.nextToken(); String query = tok.nextToken(); - int sysKey = -1; - //Path path = Gateway.getLDAPLookup().; + 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 { - //DomainPath domPath = new DomainPath(itemPath); - //EntityPath entityPath = domPath.getEntity(); - - if (sysKey > -1) { - C2KLocalObject response = Gateway.getStorage().get(sysKey, query, null); - return Gateway.getMarshaller().marshall(response); - } - else - return error("404 Not Found", "The entity "+sysKey+" you requested was not found."); + 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()); -- cgit v1.2.3