private void serve(
     HttpServletRequest req, HttpServletResponse resp, IHostedSite site, URI[] mappedURIs)
     throws ServletException, IOException {
   for (int i = 0; i < mappedURIs.length; i++) {
     URI uri = mappedURIs[i];
     // Bypass a 404 if any workspace or remote paths remain to be checked.
     boolean failEarlyOn404 = i + 1 < mappedURIs.length;
     if (uri.getScheme() == null) {
       if ("GET".equals(req.getMethod())) { // $NON-NLS-1$
         if (serveOrionFile(req, resp, site, new Path(uri.getPath()), failEarlyOn404)) return;
       } else {
         String message = "Only GET method is supported for workspace paths";
         handleException(
             resp,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_METHOD_NOT_ALLOWED,
                 NLS.bind(message, mappedURIs),
                 null));
       }
     } else {
       if (proxyRemotePath(
           req, new LocationHeaderServletResponseWrapper(req, resp, site), uri, failEarlyOn404))
         return;
     }
   }
 }
Esempio n. 2
0
  /**
   * Constructor.
   *
   * @param rq request
   * @param rs response
   * @param servlet calling servlet instance
   * @throws IOException I/O exception
   */
  public HTTPContext(
      final HttpServletRequest rq, final HttpServletResponse rs, final BaseXServlet servlet)
      throws IOException {

    req = rq;
    res = rs;
    params = new HTTPParams(this);

    method = rq.getMethod();

    final StringBuilder uri = new StringBuilder(req.getRequestURL());
    final String qs = req.getQueryString();
    if (qs != null) uri.append('?').append(qs);
    log('[' + method + "] " + uri, null);

    // set UTF8 as default encoding (can be overwritten)
    res.setCharacterEncoding(UTF8);
    segments = decode(toSegments(req.getPathInfo()));

    // adopt servlet-specific credentials or use global ones
    final GlobalOptions mprop = context().globalopts;
    user = servlet.user != null ? servlet.user : mprop.get(GlobalOptions.USER);
    pass = servlet.pass != null ? servlet.pass : mprop.get(GlobalOptions.PASSWORD);

    // overwrite credentials with session-specific data
    final String auth = req.getHeader(AUTHORIZATION);
    if (auth != null) {
      final String[] values = auth.split(" ");
      if (values[0].equals(BASIC)) {
        final String[] cred = org.basex.util.Base64.decode(values[1]).split(":", 2);
        if (cred.length != 2) throw new LoginException(NOPASSWD);
        user = cred[0];
        pass = cred[1];
      } else {
        throw new LoginException(WHICHAUTH, values[0]);
      }
    }
  }
Esempio n. 3
0
 /**
  * Constructor.
  *
  * @param r HTTP servlet request
  */
 BXServletRequest(final HttpServletRequest r) {
   req = r;
   method = Method.valueOf(r.getMethod());
   url = r.getRequestURL().toString(); // MiltonUtils.stripContext(r);
   REQUEST.set(r);
 }