/[storm]/storm/org/nongnu/storm/util/HTTPProxy.java
ViewVC logotype

Diff of /storm/org/nongnu/storm/util/HTTPProxy.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by benja, Fri May 9 10:54:56 2003 UTC revision 1.29 by benja, Fri May 9 15:52:47 2003 UTC
# Line 31  import org.nongnu.storm.impl.*; Line 31  import org.nongnu.storm.impl.*;
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;
# Line 116  public class HTTPProxy implements Runnab Line 117  public class HTTPProxy implements Runnab
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"))
# Line 229  public class HTTPProxy implements Runnab Line 230  public class HTTPProxy implements Runnab
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");
# Line 317  public class HTTPProxy implements Runnab Line 318  public class HTTPProxy implements Runnab
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);
# Line 326  public class HTTPProxy implements Runnab Line 345  public class HTTPProxy implements Runnab
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      }      }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26