Package org.xmlBlaster.util.http

Examples of org.xmlBlaster.util.http.HttpResponse


   public HttpResponse service(String urlPath, Map properties) {
          if (log.isLoggable(Level.FINE)) {
         log.fine("Invoking with '" + urlPath + "' urlPath, properties='" + properties + "'");
          }
      if (urlPath == null || urlPath.length() < 1) {
         return new HttpResponse("<html><h2>Empty request, please provide a URL path</h2></html>");
      }
      try {
         String path;
         String parameter = null;
          if (urlPath.indexOf('?') > -1) {
                         // has Parameter
                 path = urlPath.substring(0, urlPath.indexOf('?'));
          parameter = URLDecoder.decode(urlPath.substring(urlPath.indexOf('?') + 1,
                                        urlPath.length()), Constants.UTF8_ENCODING);
                 } else {
                        // has no parameter
                        path = urlPath;
                 }
         byte[] text;
         String mimeType = getMimeType(path.toString());
         if (this.urlPathClasspathSet.contains(path)) { // "/status.html"
            if (urlPath.startsWith("/")) {
               // "status.html": lookup where the java class resides in xmlBlaster.jar
               urlPath = urlPath.substring(1);
            }
            text = ServerScope.getFromClasspath(urlPath, this);
            if (log.isLoggable(Level.FINE)) log.fine("Reading '" + urlPath + "' from CLASSPATH");
         }
         else {
            File f = new File(path);
            // FIXME: check for security
            // dangerous because one could send: ../../../
            String name = f.getName();
            if (log.isLoggable(Level.FINE)) log.fine("Invoking with '" + urlPath + "' urlPath, name='" + name + "'");
            File template = new File(this.documentRoot, name);
            text = FileLocator.readFile(template.toString());
            if (log.isLoggable(Level.FINE)) log.fine("Reading template  '" + template.toString() + "'");
         }
         if (parameter != null && !(parameter.length() < 0)) {
            invokeAction(parameter);
         }
         if (mimeType.startsWith("text")) {
            text = replaceAllVariables(new String(text)).getBytes();
         }
         return new HttpResponse(text, mimeType);
      }
      catch (Throwable e) {
         e.printStackTrace();
         return new HttpResponse("<html><h2>" + e.toString() + "</h2></html>");
      }
   }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.http.HttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.