Exemplo n.º 1
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   log.fine("doGet");
   WWindowStatus ws = WWindowStatus.get(request);
   WebDoc doc = null;
   if (ws == null) {
     doc = WebDoc.createPopup("No Context");
     doc.addPopupClose(Env.getCtx());
   } else doc = ws.mWindow.getHelpDoc(false);
   WebUtil.createResponse(request, response, this, null, doc, false);
 }
Exemplo n.º 2
0
  /** Process the HTTP Post request */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    WebDoc doc = null;

    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);

    String data = WebUtil.getParameter(request, "chatinput");
    int CM_ChatID = WebUtil.getParameterAsInt(request, "CM_ChatID");
    int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
    int record_ID = WebUtil.getParameterAsInt(request, "record_ID");
    String description = WebUtil.getParameter(request, "description");

    if (data != null && data.length() > 0) {
      if (CM_ChatID == 0) {
        m_chat = new MChat(wsc.ctx, AD_Table_ID, record_ID, description, null);
        m_chat.save();
      }
      MChatEntry entry = new MChatEntry(m_chat, data);
      entry.save();
    } //	data to be saved

    doc = CreateChatPage(ws, wsc, doc, m_chat.getCM_Chat_ID());
    WebUtil.createResponse(request, response, this, null, doc, false);
  } //  doPost
Exemplo n.º 3
0
 /** Process the HTTP Get request */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   log.fine("doGet");
   WebSessionCtx wsc = WebSessionCtx.get(request);
   WWindowStatus ws = WWindowStatus.get(request);
   //
   WebDoc doc = null;
   if (ws == null) {
     doc = WebDoc.createPopup("No Context");
     doc.addPopupClose(wsc.ctx);
   } else {
     doc = CreateChatPage(ws, wsc, doc, 0);
   }
   //
   WebUtil.createResponse(request, response, this, null, doc, false);
 } //  doGet
Exemplo n.º 4
0
 public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   WebDoc doc = WebDoc.create("Help - Post - Not Implemented");
   WebUtil.createResponse(request, response, this, null, doc, false);
 }
Exemplo n.º 5
0
  /**
   * Stream invoice
   *
   * @param request request
   * @param response response
   * @return "" or error message
   */
  private String streamInvoice(HttpServletRequest request, HttpServletResponse response) {
    int MIN_SIZE = 2000; // 	if not created size is 1015

    //	Get Invoice ID
    int C_Invoice_ID = WebUtil.getParameterAsInt(request, "Invoice_ID");
    if (C_Invoice_ID == 0) {
      log.fine("No ID)");
      return "No Invoice ID";
    }

    //	Get Invoice
    Properties ctx = JSPEnv.getCtx(request);
    MInvoice invoice = new MInvoice(ctx, C_Invoice_ID, null);
    if (invoice.getC_Invoice_ID() != C_Invoice_ID) {
      if (log.isLoggable(Level.FINE)) log.fine("Invoice not found - ID=" + C_Invoice_ID);
      return "Invoice not found";
    }
    //	Get WebUser & Compare with invoice
    HttpSession session = request.getSession(true);
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    if (wu.getC_BPartner_ID() != invoice.getC_BPartner_ID()) {
      log.warning(
          "Invoice from BPartner - C_Invoice_ID="
              + C_Invoice_ID
              + " - BP_Invoice="
              + invoice.getC_BPartner_ID()
              + " = BP_Web="
              + wu.getC_BPartner_ID());
      return "Your invoice not found";
    }

    //	Check Directory
    String dirName = ctx.getProperty("documentDir", ".");
    try {
      File dir = new File(dirName);
      if (!dir.exists()) dir.mkdir();
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Could not create directory " + dirName, ex);
      return "Streaming error - directory";
    }
    //	Check if Invoice already created
    String fileName = invoice.getPDFFileName(dirName);
    File file = new File(fileName);
    if (file.exists() && file.isFile() && file.length() > MIN_SIZE) {
      if (log.isLoggable(Level.INFO))
        log.info("Existing: " + file + " - " + new Timestamp(file.lastModified()));
    } else {
      if (log.isLoggable(Level.INFO)) log.info("New: " + fileName);
      file = invoice.createPDF(file);
      if (file != null) {
        invoice.setDatePrinted(new Timestamp(System.currentTimeMillis()));
        invoice.saveEx();
      }
    }
    //	Issue Error
    if (file == null || !file.exists() || file.length() < MIN_SIZE) {
      log.warning("File does not exist - " + file);
      return "Streaming error - file";
    }

    //	Send PDF
    try {
      int bufferSize = 2048; // 	2k Buffer
      int fileLength = (int) file.length();
      //
      response.setContentType("application/pdf");
      response.setBufferSize(bufferSize);
      response.setContentLength(fileLength);
      //
      if (log.isLoggable(Level.FINE)) log.fine(file.getAbsolutePath() + ", length=" + fileLength);
      long time = System.currentTimeMillis(); // 	timer start
      //
      FileInputStream in = new FileInputStream(file);
      ServletOutputStream out = response.getOutputStream();
      byte[] buffer = new byte[bufferSize];
      double totalSize = 0;
      int count = 0;
      do {
        count = in.read(buffer, 0, bufferSize);
        if (count > 0) {
          totalSize += count;
          out.write(buffer, 0, count);
        }
      } while (count != -1);
      out.flush();
      out.close();
      //
      in.close();
      time = System.currentTimeMillis() - time;
      double speed = (totalSize / 1024) / ((double) time / 1000);
      if (log.isLoggable(Level.FINE))
        log.fine("Length=" + totalSize + " - " + time + " ms - " + speed + " kB/sec");
    } catch (IOException ex) {
      log.log(Level.SEVERE, ex.toString());
      return "Streaming error";
    }

    return null;
  } //	streamInvoice