1 package org.sapia.ubik.rmi.server.transport.http; 2 3 import java.io.File ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 7 import simple.http.ProtocolHandler; 8 import simple.http.Request; 9 import simple.http.Response; 10 import simple.http.load.Service; 11 import simple.http.serve.Context; 12 import simple.http.serve.FileContext; 13 import simple.http.serve.FileEngine; 14 import simple.util.parse.URIParser; 15 16 17 27 public class ServiceMapper implements ProtocolHandler { 28 private FileContext _context; 29 private FileEngine _engine = new FileEngine(_context = new FileContext( 30 new File (System.getProperty("user.dir")))); 31 private Map _services = new HashMap (); 32 33 public ServiceMapper() { 34 } 35 36 39 public Context getContext() { 40 return _context; 41 } 42 43 public void setBaseDir(File baseDir) { 44 _engine = new FileEngine(_context = new FileContext(baseDir)); 45 } 46 47 54 public void addService(String contextPath, Service svc) { 55 if (contextPath == null) { 56 contextPath = "/"; 57 } 58 59 if (!contextPath.startsWith("/")) { 60 contextPath = "/" + contextPath; 61 } 62 63 _services.put(contextPath, svc); 64 } 65 66 69 public void handle(Request req, Response res) { 70 URIParser uri = new URIParser(); 71 uri.parse(req.getURI()); 72 73 if (uri.getPath() != null) { 74 Service svc = (Service) _services.get(uri.getPath().getPath()); 75 76 if (svc != null) { 77 svc.handle(req, res); 78 } 79 } 80 } 81 } 82 | Popular Tags |