示例#1
0
  private final void callDirect(HttpServletRequest request, HttpServletResponse response) {

    String service = request.getParameter("service");
    if (service == null) {

      logRequestParams(request);
      return;
    }

    // PrintWriter out = response.getWriter();

    Navajo tbMessage = null;
    DispatcherInterface dis = null;
    dis = DispatcherFactory.getInstance();
    try {

      tbMessage = constructFromRequest(request);
      Navajo resultMessage = handleTransaction(dis, tbMessage, null, null);
      sendResponse(request, response, resultMessage);

    } catch (Exception ce) {
      logger.error("Error: ", ce);
    } finally {
      dis = null;
    }
  }
示例#2
0
  public void setAccessId(String id) throws UserException {

    this.accessId = id;
    if (accessId == null) {
      throw new UserException(-1, "Set accessId first");
    }
    Set<Access> all = com.dexels.navajo.server.DispatcherFactory.getInstance().getAccessSet();
    Iterator<Access> iter = all.iterator();
    while (iter.hasNext()) {
      Access a = iter.next();
      if (a.accessID.equals(accessId)) {
        this.myAccess = a;
        showDetails = true;
      }
    }
    if (!(showDetails)) { // Try async store
      myAccess = com.dexels.navajo.mapping.AsyncStore.getInstance().accessStore.get(id);
      if (myAccess != null) {
        showDetails = true;
      }
    }
  }
示例#3
0
  /**
   * Handle a request.
   *
   * @param request
   * @param response
   * @throws IOException
   * @throws ServletException
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    MDC.clear();
    Date created = new java.util.Date();
    long start = created.getTime();

    String sendEncoding = request.getHeader("Accept-Encoding");
    String recvEncoding = request.getHeader("Content-Encoding");

    MDC.put("Accept-Encoding", sendEncoding);
    MDC.put("Content-Encoding", recvEncoding);
    DispatcherInterface dis = null;
    BufferedReader r = null;
    BufferedWriter out = null;
    try {

      Navajo in = null;

      if (streamingMode) {
        if (sendEncoding != null && sendEncoding.equals(COMPRESS_JZLIB)) {
          r =
              new BufferedReader(
                  new java.io.InputStreamReader(new InflaterInputStream(request.getInputStream())));
        } else if (sendEncoding != null && sendEncoding.equals(COMPRESS_GZIP)) {
          r =
              new BufferedReader(
                  new java.io.InputStreamReader(
                      new java.util.zip.GZIPInputStream(request.getInputStream()), "UTF-8"));
        } else {
          r = new BufferedReader(request.getReader());
        }
        in = NavajoFactory.getInstance().createNavajo(r);
        r.close();
        r = null;
      } else {
        logger.info(
            "Warning: Using non-streaming mode for "
                + request.getRequestURI()
                + ", file written: "
                + logfileIndex
                + ", total size: "
                + bytesWritten);
        InputStream is = request.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copyResource(bos, is);
        is.close();
        bos.close();
        byte[] bytes = bos.toByteArray();
        try {
          if (sendEncoding != null && sendEncoding.equals(COMPRESS_JZLIB)) {
            r =
                new BufferedReader(
                    new java.io.InputStreamReader(
                        new InflaterInputStream(new ByteArrayInputStream(bytes))));
          } else if (sendEncoding != null && sendEncoding.equals(COMPRESS_GZIP)) {
            r =
                new BufferedReader(
                    new java.io.InputStreamReader(
                        new java.util.zip.GZIPInputStream(new ByteArrayInputStream(bytes)),
                        "UTF-8"));
          } else {
            r = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes)));
          }
          in = NavajoFactory.getInstance().createNavajo(r);
          if (in == null) {
            throw new Exception("Invalid Navajo");
          }
          r.close();
          r = null;
        } catch (Throwable t) {
          // Write request to temp file.
          File f = DispatcherFactory.getInstance().getTempDir();

          if (f != null) {
            bytesWritten += bytes.length;
            logfileIndex++;
            FileOutputStream fos = new FileOutputStream(new File(f, "request-" + logfileIndex));
            copyResource(fos, new ByteArrayInputStream(bytes));
            fos.close();
            PrintWriter fw =
                new PrintWriter(new FileWriter(new File(f, "exception-" + logfileIndex)));
            t.printStackTrace(fw);
            fw.flush();
            fw.close();
          }

          dumHttp(request, logfileIndex, f);
          throw new ServletException(t);
        }
      }

      long stamp = System.currentTimeMillis();
      int pT = (int) (stamp - start);

      if (in == null) {
        throw new ServletException("Invalid request.");
      }

      Header header = in.getHeader();
      if (header == null) {
        throw new ServletException("Empty Navajo header.");
      }

      dis = DispatcherFactory.getInstance();
      if (dis == null) {
        System.err.println(
            "SERIOUS: No dispatcher found. The navajo context did not initialize properly, check the logs to find out why!");
        return;
      }
      // Check for certificate.
      Object certObject = request.getAttribute("javax.servlet.request.X509Certificate");

      // Call Dispatcher with parsed TML document as argument.
      ClientInfo clientInfo =
          new ClientInfo(
              request.getRemoteAddr(),
              "unknown",
              recvEncoding,
              pT,
              (recvEncoding != null
                  && (recvEncoding.equals(COMPRESS_GZIP) || recvEncoding.equals(COMPRESS_JZLIB))),
              (sendEncoding != null
                  && (sendEncoding.equals(COMPRESS_GZIP) || sendEncoding.equals(COMPRESS_JZLIB))),
              request.getContentLength(),
              created);

      Navajo outDoc = handleTransaction(dis, in, certObject, clientInfo);

      response.setContentType("text/xml; charset=UTF-8");
      response.setHeader("Accept-Ranges", "none");
      response.setHeader("Connection", "close");

      if (recvEncoding != null && recvEncoding.equals(COMPRESS_JZLIB)) {
        response.setHeader("Content-Encoding", COMPRESS_JZLIB);
        out =
            new BufferedWriter(
                new OutputStreamWriter(
                    new DeflaterOutputStream(response.getOutputStream()), "UTF-8"));
      } else if (recvEncoding != null && recvEncoding.equals(COMPRESS_GZIP)) {
        response.setHeader("Content-Encoding", COMPRESS_GZIP);
        out =
            new BufferedWriter(
                new OutputStreamWriter(
                    new java.util.zip.GZIPOutputStream(response.getOutputStream()), "UTF-8"));
      } else {
        out = new BufferedWriter(response.getWriter());
      }

      outDoc.write(out);
      out.flush();
      out.close();

      if (in.getHeader() != null
          && outDoc.getHeader() != null
          && !Dispatcher.isSpecialwebservice(in.getHeader().getRPCName())) {
        statLogger.info(
            "("
                + dis.getApplicationId()
                + "): "
                + new java.util.Date()
                + ": "
                + outDoc.getHeader().getHeaderAttribute("accessId")
                + ":"
                + in.getHeader().getRPCName()
                + "("
                + in.getHeader().getRPCUser()
                + "):"
                + (System.currentTimeMillis() - start)
                + " ms. (st="
                + (outDoc.getHeader().getHeaderAttribute("serverTime")
                    + ",rpt="
                    + outDoc.getHeader().getHeaderAttribute("requestParseTime")
                    + ",at="
                    + outDoc.getHeader().getHeaderAttribute("authorisationTime")
                    + ",pt="
                    + outDoc.getHeader().getHeaderAttribute("processingTime")
                    + ",tc="
                    + outDoc.getHeader().getHeaderAttribute("threadCount")
                    + ",cpu="
                    + outDoc.getHeader().getHeaderAttribute("cpuload")
                    + ")"
                    + " ("
                    + sendEncoding
                    + "/"
                    + recvEncoding
                    + ")"));
      }

      out = null;

    } catch (Throwable e) {
      logger.error("Error: ", e);
      dumHttp(request, -1, null);
      if (e instanceof FatalException) {
        FatalException fe = (FatalException) e;
        if (fe.getMessage().equals("500.13")) {
          // Server too busy.
          throw new ServletException("500.13", e);
        }
      }
      throw new ServletException(e);
    } finally {
      dis = null;
      if (r != null) {
        try {
          r.close();
        } catch (Exception e) {
          // NOT INTERESTED.
        }
      }
      if (out != null) {
        try {
          out.close();
        } catch (Exception e) {
          // NOT INTERESTED.
        }
      }
    }
  }
示例#4
0
 public boolean iAmTheSender() {
   return sender.equals(DispatcherFactory.getInstance().getNavajoConfig().getInstanceName());
 }
示例#5
0
 public void load(Access access) throws MappableException, UserException {
   this.config = DispatcherFactory.getInstance().getNavajoConfig();
 }