31 |
import org.nongnu.storm.impl.p2p.*; |
import org.nongnu.storm.impl.p2p.*; |
32 |
import org.nongnu.storm.http.*; |
import org.nongnu.storm.http.*; |
33 |
import org.nongnu.storm.http.server.*; |
import org.nongnu.storm.http.server.*; |
34 |
|
import org.nongnu.storm.pointers.*; |
35 |
import java.io.*; |
import java.io.*; |
36 |
import java.net.*; |
import java.net.*; |
37 |
import java.util.Iterator; |
import java.util.Iterator; |
117 |
|
|
118 |
/* At this point, only the block URN is left of URL */ |
/* At this point, only the block URN is left of URL */ |
119 |
|
|
120 |
BlockId id = new BlockId(uri); |
BlockId id = getBlockId(uri); |
121 |
|
|
122 |
if((!rewrite && !backlinks) || |
if((!rewrite && !backlinks) || |
123 |
!id.getContentType().equals("text/html")) |
!id.getContentType().equals("text/html")) |
230 |
protected HTTPResponse serveBlock(String uri, |
protected HTTPResponse serveBlock(String uri, |
231 |
HTTPResponse.Factory resf) |
HTTPResponse.Factory resf) |
232 |
throws Exception { |
throws Exception { |
233 |
BlockId id = new BlockId(uri); |
BlockId id = getBlockId(uri); |
234 |
Block block = pool.get(id); |
Block block = pool.get(id); |
235 |
|
|
236 |
HTTPResponse resp = resf.makeResponse(200, "Ok"); |
HTTPResponse resp = resf.makeResponse(200, "Ok"); |
318 |
} |
} |
319 |
} |
} |
320 |
|
|
321 |
|
protected BlockId getBlockId(String uri) { |
322 |
|
uri = uri.toLowerCase(); |
323 |
|
if(uri.startsWith("urn:x-storm:1.0:")) |
324 |
|
return new BlockId(uri); |
325 |
|
else if(uri.startsWith("urn:x-storm:pointer-0.1:")) { |
326 |
|
PointerIndex idx = |
327 |
|
(PointerIndex)pool.getIndex(PointerIndex.uri); |
328 |
|
try { |
329 |
|
return idx.get(new PointerId(uri)); |
330 |
|
} catch(Exception _) { |
331 |
|
_.printStackTrace(); |
332 |
|
throw new Error("Exception while getting key XXX"); |
333 |
|
} |
334 |
|
} else { |
335 |
|
throw new Error("Malformed Storm URN: "+uri); |
336 |
|
} |
337 |
|
} |
338 |
|
|
339 |
protected class Factory extends HTTPConnection.Factory { |
protected class Factory extends HTTPConnection.Factory { |
340 |
public HTTPConnection newConnection(Socket s) throws IOException { |
public HTTPConnection newConnection(Socket s) throws IOException { |
341 |
return new StormConnection(s); |
return new StormConnection(s); |
345 |
public static void main(String[] args) throws Exception { |
public static void main(String[] args) throws Exception { |
346 |
dbg = true; |
dbg = true; |
347 |
IndexedPool pool; |
IndexedPool pool; |
348 |
java.util.Set empty = java.util.Collections.EMPTY_SET; |
java.util.Set indexTypes = |
349 |
pool = new DirPool(new File(args[0]), empty); |
java.util.Collections.singleton(PointerIndex.type); |
350 |
|
pool = new DirPool(new File(args[0]), indexTypes); |
351 |
|
|
352 |
new HTTPProxy(pool, 5555).run(); |
new HTTPProxy(pool, 5555).run(); |
353 |
} |
} |