コード例 #1
0
  public JSRequest(Request request, Context cx, Scriptable scope) {
    this();

    ESXX esxx = ESXX.getInstance();

    this.request = request;

    requestURI = (JSURI) cx.newObject(scope, "URI", new Object[] {request.getRequestURI()});
    scriptURI = (JSURI) cx.newObject(scope, "URI", new Object[] {request.getScriptURI()});

    env = cx.newObject(scope);
    headers = cx.newObject(scope);
    cookies = cx.newObject(scope);
    accept = cx.newObject(scope);
    query = cx.newObject(scope);
    args = null;
    params = cx.newObject(scope);

    acceptValueOf = new FunctionObject("valueOf", acceptValueOfMethod, accept);

    for (String name : request.getProperties().stringPropertyNames()) {
      String value = request.getProperties().getProperty(name).trim();

      // Add environtment variable to esxx.env
      ScriptableObject.putProperty(env, name, value);

      // If this is an HTTP header, get the original name back
      String hdr = esxx.cgiToHTTP(name);

      if (hdr != null) {
        // Add real HTTP header to this.headers
        addHeader(hdr, value);

        // Decode cookies
        handleCookieHeader(hdr, value);

        // Decode Accept* HTTP headers
        handleAcceptHeader(hdr, value, cx, accept);

        // Decode Content-* HTTP headers
        handleContentHeader(hdr, value);

        // Handle SOAPAction
        if (hdr.equals("SOAPAction")) {
          soapAction = value;
        }
      }

      if (name.equals("QUERY_STRING")) {
        try {
          StringUtil.decodeFormVariables(value, query);
        } catch (UnsupportedEncodingException ex) {
          throw new ESXXException("Unable to parse request entity: " + ex.getMessage(), ex);
        }
      }
    }

    logger = JSESXX.newObject(cx, scope, "Logger", new Object[] {request, request.getScriptName()});
  }
コード例 #2
0
  private Object parseMessage() {
    // Consume SOAP message, if any
    // TODO: Add a SOAP handler in Parser.java
    if (soapAction != null) {
      try {
        MimeHeaders mime_headers = new MimeHeaders();

        for (Object k : headers.getIds()) {
          if (k instanceof String) {
            String name = (String) k;
            String value = Context.toString(ScriptableObject.getProperty(headers, name));

            mime_headers.addHeader(name, value);
          }
        }

        return MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL)
            .createMessage(mime_headers, request.getInputStream());
      } catch (IOException ex) {
        throw new ESXXException("Unable to read SOAP message stream: " + ex.getMessage());
      } catch (SOAPException ex) {
        throw new ESXXException(400 /* Bad Request */, "Invalid SOAP message: " + ex.getMessage());
      } finally {
        try {
          request.getInputStream().close();
        } catch (Exception ignored) {
        }
      }
    } else if (contentType != null && contentLength > 0) {
      try {
        ESXX esxx = ESXX.getInstance();
        return esxx.parseStream(
            contentType,
            request.getInputStream(),
            URI.create("urn:x-esxx:incoming-request-entity"),
            null,
            new java.io.PrintWriter(request.getErrorWriter()),
            Context.getCurrentContext(),
            this);
      } catch (Exception ex) {
        throw new ESXXException(
            400 /* Bad Request */, "Unable to parse request entity: " + ex.getMessage(), ex);
      } finally {
        try {
          request.getInputStream().close();
        } catch (Exception ignored) {
        }
      }
    } else {
      // Return a dummy object
      return Context.getCurrentContext().newObject(this);
    }
  }
コード例 #3
0
  private static Properties createCGIEnvironment(
      HttpServletRequest sreq, URI root_uri, File canonical_script_file) throws URISyntaxException {

    URI full_request_uri =
        new URI(
            sreq.getScheme(),
            null,
            sreq.getServerName(),
            sreq.getServerPort(),
            sreq.getRequestURI(),
            sreq.getQueryString(),
            null);

    Properties p =
        createCGIEnvironment(
            sreq.getMethod(),
            sreq.getProtocol(),
            full_request_uri,
            new InetSocketAddress(sreq.getLocalAddr(), sreq.getLocalPort()),
            new InetSocketAddress(sreq.getRemoteAddr(), sreq.getRemotePort()),
            sreq.getContextPath() + "/",
            root_uri,
            canonical_script_file);

    // Add request headers

    for (Enumeration e = sreq.getHeaderNames(); e.hasMoreElements(); ) {
      String h = (String) e.nextElement();
      p.setProperty(ESXX.httpToCGI(h), sreq.getHeader(h));
    }

    return p;
  }
コード例 #4
0
ファイル: JSURI.java プロジェクト: BackupTheBerlios/esxx-svn
  public static Object jsFunction_remove(
      Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception {
    JSURI js_this = checkInstance(thisObj);
    String type = null;
    HashMap<String, String> params = new HashMap<String, String>();

    if (args.length >= 1 && args[0] != Context.getUndefinedValue()) {
      type = ESXX.parseMIMEType(Context.toString(args[0]), params);
    }

    return js_this.protocolHandler.remove(cx, thisObj, type, params);
  }
コード例 #5
0
 public void close() {
   try {
     sql.close();
   } catch (SQLException ex) {
     // Log and ignore
     ESXX.getInstance()
         .getLogger()
         .log(
             java.util.logging.Level.WARNING,
             "Failed to close statement: " + ex.getMessage(),
             ex);
   }
 }
コード例 #6
0
  public Integer handleError(ESXX esxx, Context cx, Throwable ex) {
    String title = "ESXX Server Error";
    int code = 500;

    if (ex instanceof ESXXException) {
      code = ((ESXXException) ex).getStatus();
    }

    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);

    out.println(esxx.getHTMLHeader());
    out.println("<h2>" + title + "</h2>");
    out.println("<h3>Unhandled exception: " + ex.getClass().getSimpleName() + "</h3>");
    if (ex instanceof ESXXException
        || ex instanceof javax.xml.stream.XMLStreamException
        || ex instanceof javax.xml.transform.TransformerException) {
      out.println("<p><tt>" + encodeXMLContent(ex.getMessage()) + "</tt></p>");
    } else if (ex instanceof RhinoException) {
      out.println("<pre>");
      out.println(ex.getClass().getSimpleName() + ": " + encodeXMLContent(ex.getMessage()));
      out.println(((RhinoException) ex).getScriptStackTrace(new ESXX.JSFilenameFilter()));
      out.println("</pre>");
    } else {
      out.println("<pre>");
      ex.printStackTrace(out);
      out.println("</pre>");
    }
    out.println(esxx.getHTMLFooter());
    out.close();

    try {
      return handleResponse(
          esxx, cx, new Response(code, "text/html; charset=UTF-8", sw.toString(), null));
    } catch (Exception ex2) {
      // Hmm
      return 20;
    }
  }
コード例 #7
0
ファイル: JSURI.java プロジェクト: BackupTheBerlios/esxx-svn
  public static Object jsFunction_modify(
      Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception {
    JSURI js_this = checkInstance(thisObj);
    String type = null;
    HashMap<String, String> params = new HashMap<String, String>();

    if (args.length < 1 || args[0] == Context.getUndefinedValue()) {
      throw Context.reportRuntimeError("Missing append() argument");
    }

    if (args.length >= 2 && args[1] != Context.getUndefinedValue()) {
      type = ESXX.parseMIMEType(Context.toString(args[1]), params);
    }

    return js_this.protocolHandler.modify(cx, thisObj, args[0], type, params);
  }
コード例 #8
0
    public void close() {
      // Close all statements
      queryCache.filterEntries(
          new LRUCache.EntryFilter<String, Query>() {
            public boolean isStale(String key, Query app, long created) {
              return true;
            }
          });

      // Close connection
      try {
        connection.close();
      } catch (SQLException ex) {
        // Log and ignore
        ESXX.getInstance()
            .getLogger()
            .log(
                java.util.logging.Level.WARNING,
                "Failed to close pooled connection: " + ex.getMessage(),
                ex);
      }
    }