如何使我的oracle过程等到我从被调用的servlet得到响应?

时间:2012-02-09 12:26:09

标签: oracle

我们使用以下过程来调用servlet,该servlet将通过从表中提取记录来创建“PDF报告”。由于该表格很大(约40GB),因此创建PDF报告需要15分钟。直到那时我需要运行一个循环来检查servlet请求是否已成功完成。

如果成功,那么我们需要调用一个程序,该程序将发送带有生成的PDF文件附件的邮件。

问题:在获取/检查响应之前,此过程正在调用Send Mail过程。所以邮件没有附件。

请给我一些解决这个问题的想法。

    PROCEDURE batch_generate_report_prc
  (
  pi_date     IN   DATE,
  po_filename OUT  VARCHAR2
   )
IS
  p_paramval       VARCHAR2(500);
  p_filename    VARCHAR2(500);
  v_url            VARCHAR2(2000);
  p_key            VARCHAR2(500);
  p_spool                  VARCHAR2(500);
  p_rep_seq           NUMBER;
  p_strfilename       VARCHAR2(500);
  v_run_report      VARCHAR2 (2000);
  vn_block         NUMBER(5,2);
  Po_status           NUMBER;
  vs_errmsg              VARCHAR2(500);

 BEGIN
  BEGIN

     Po_status := 1;

     vn_block := 10;
     SELECT lrepseq
     INTO p_rep_seq
     FROM com_reports_m
     WHERE strrepname = 'NBR050';

     vn_block := 11;
     p_paramval := pi_date || '~' || 'SYSTEM';
     -- p_paramval := p_paramval||'~'||c1_rec.strcompanycd;
     v_url :=
        com_rep_let_output_pkg.om_build_url_fnc (p_rep_seq,
                                                 p_paramval,
                                                 3,
                                                 'repletbatchprocess',
                                                 NULL,
                                                 p_strfilename
                                                );
     vn_block := 12;
     SELECT strparamvalue
     INTO p_key
     FROM om_configuration
     WHERE nparamkey = 78;

     vn_block := 13;
     SELECT strparamvalue
     INTO p_spool
     FROM om_configuration
     WHERE nparamkey = 61;

     vn_block := 14;
     --DBMS_OUTPUT.put_line (v_url);
     p_filename :=
           'NBR050'
        || '_SYSTEM_'
        || TO_CHAR (pi_date, 'DD-MON-RRRR')
        || TO_CHAR (SYSTIMESTAMP, '_HH24MISSFF6')
        || '.pdf';
     v_url :=
           v_url
        || '&cmdkey='
        || p_key
        || '&P_FILE_FORMAT=1&DESFORMAT=PDF&DESTYPE=FILE&'
        || '&desname='
        || p_spool
        || p_filename;
  --DBMS_OUTPUT.put_line (v_url);                              --Run the report

   vn_block := 14;
   UTL_HTTP.set_transfer_timeout (5000);
   v_run_report := UTL_HTTP.request (v_url);

   EXCEPTION
   WHEN OTHERS
   THEN
     po_filename := NULL;
     vs_errmsg := 'Error Occured while Generating Excep Rep NBR050 ' || SUBSTR (SQLERRM, 1, 110);
     com_insert_exception_prc
                      (11,
                       992,
                       SYSDATE,
                       'MAIL',
                       NULL,
                          '9 Error occurred at block no='
                       || vn_block
                       || ' in Mail process while executing BPM Report NR050:'
                       || ' '
                       || SUBSTR (SQLERRM, 1, 110)
                      );
       --dbms_output.put_line(SUBSTR (SQLERRM, 1, 110));
      Po_status := 2;
  END;
  --Added by Muktad For Serch at FE.
  IF Po_status = 1
  THEN

     INSERT INTO COM_CONTACT_HST (lcontactseq,lrepseq,dtcontact,nstatus,dtstatus,strfilename,leventseq,strcreatedby,DTCREATED)
     VALUES
     (COM_CONTACT_HST_SEQ.nextval,p_rep_seq,pi_date,Po_status,pi_date,p_filename,9,'BATCH',sysdate);

     COMMIT;

  END IF;

  BEGIN --This sends mail but doubt ful to get the details how it sent.
     BATCH_MAIL_SEND_REPORT_PRC(pi_date,p_filename,po_status);
  END;

  po_filename := p_filename;

  EXCEPTION

  WHEN OTHERS
  THEN

     po_filename := NULL;

     com_insert_exception_prc
     (
         pi_nmoduleid       =>   10
        ,pi_nprocessid      =>   877
        ,pi_dtprocess       =>   SYSDATE
        ,pi_strpolnbr       =>   'Mail'
        ,pi_npolcheckdigit  =>   NULL
        ,pi_strerrordesc    =>   '10 Unable to send mail in batch_mail_pkg.batch_generate_report_prc at block no :'||vn_block||' Oracle Error :'||Substr(Sqlerrm,1,100)
        ,pi_nmessagelevel   =>   0
     );
    END;

2 个答案:

答案 0 :(得分:1)

从未使用过这个utl_http的东西,但是(根据this UTL_HTTP reference)你不应该等待utl_http.get_response的回复吗?

答案 1 :(得分:0)

在发送电子邮件过程中,检查是否存在生成的PDF,如果文件存在,则我们知道servlet已完成处理请求。