JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java & XML、Web Service » Web Services  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 webservice invoke問題
dream1978





發文: 8
積分: 0
於 2016-06-05 08:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public void invokeProcess(String pJndiName,List pResults,int pNumber) throws Exception {
    System.out.println("==============================");
    System.out.println("pNumber = " + pNumber);
    System.out.println("==============================");
    //建立表單XMLValue的Template
    String tXMLTemplate = "<SecondarySignoff>";
    tXMLTemplate += "<SerialNumber id=\"SerialNumber\" dataType=\"java.lang.String\"/>";
    tXMLTemplate += "<txt_Company id=\"txt_Company\" dataType=\"java.lang.String\" perDataProId=\"\">#Company</txt_Company>";
    tXMLTemplate += "<txt_Branch id=\"txt_Branch\" dataType=\"java.lang.String\" perDataProId=\"\">#Branch</txt_Branch>";
    tXMLTemplate += "<check_Approval id=\"check_Approval\" dataType=\"java.lang.String\"/>";
    tXMLTemplate += "<href_Content id=\"href_Content\" dataType=\"java.lang.String\" perDataProId=\"\"/>";
    tXMLTemplate += "<hdn_userOID id=\"hdn_userOID\" dataType=\"java.lang.String\" perDataProId=\"\"/>";
    tXMLTemplate += "<hdn_Approval id=\"hdn_Approval\" dataType=\"java.lang.String\" perDataProId=\"\"/>";
    tXMLTemplate += "<hdn_Link id=\"hdn_Link\" dataType=\"java.lang.String\" perDataProId=\"\"/>";    
    tXMLTemplate += "<Grid0 id=\"Grid0\">";
    tXMLTemplate += "<records>";
    for(int i = 0; i < pNumber; i++){
      tXMLTemplate += "<record id=\"Grid0_" + i + "\">";
      tXMLTemplate += "<item id=\"g_Approval\" dataType=\"java.lang.String\" perDataProId=\"\">#Approval</item>";
      tXMLTemplate += "<item id=\"g_FormNumber\" dataType=\"java.lang.String\" perDataProId=\"\">#FormNumber" + i + "</item>";
      tXMLTemplate += "<item id=\"g_Single\" dataType=\"java.lang.String\" perDataProId=\"\">#Single" + i + "</item>";
      tXMLTemplate += "<item id=\"g_Consultant\" dataType=\"java.lang.String\" perDataProId=\"\">#Consultant" + i + "</item>";
      tXMLTemplate += "<item id=\"g_CustomerName\" dataType=\"java.lang.String\" perDataProId=\"\">#CustomerName" + i + "</item>";
      tXMLTemplate += "<item id=\"g_Category\" dataType=\"java.lang.String\" perDataProId=\"\">#Category" + i + "</item>";
      tXMLTemplate += "<item id=\"g_Payment\" dataType=\"java.lang.String\" perDataProId=\"\">#Payment" + i + "</item>";
      tXMLTemplate += "<item id=\"g_SigningBonus\" dataType=\"java.lang.String\" perDataProId=\"\">#SigningBonus" + i + "</item>";
      tXMLTemplate += "<item id=\"g_EntryFee\" dataType=\"java.lang.String\" perDataProId=\"\">#EntryFee" + i + "</item>";
      tXMLTemplate += "<item id=\"g_FormContent\" dataType=\"java.lang.String\" perDataProId=\"\">#FormContent" + i + "</item>";
      tXMLTemplate += "</record>";
    }
    tXMLTemplate += "</records>";
    tXMLTemplate += "</Grid0>";
    tXMLTemplate += "</SecondarySignoff>";
    //System.out.println("表單組合XML語法");
    //System.out.println("tXMLTemplate = " + tXMLTemplate);
    
    String tFormFieldValue = tXMLTemplate;
    int i = 0;
    if(pResults.size()>0){
      String[] tResult = null;    //宣告--表單資料內容陣列
      DataSource tDataSource = null;  //宣告--tDataSource
      Connection tConnection = null;  //宣告--Connection
      Statement tStatement = null;  //宣告--Statement
      
      try{
        //透過DataSource取得Connection
        tDataSource = getJndiDataSource(pJndiName);
        tConnection = tDataSource.getConnection();
        tStatement = tConnection.createStatement();
        
        //呼叫WebServices發起流程變數宣告
        Service tService = new Service();
        Call tCall = null;
        String tServerHost = "192.168.1.124";
        String tServerPort = "8086";
        Object[] tParams = null;
        Object tObject = null;
        String tSerialNo = null;
        String tFormOIDs = null;
        //String tWorkItem = null;
        
        //將要放到表單中的資料一筆一筆取出來做流程的發起
        for(Iterator tIter=pResults.iterator();tIter.hasNext(); ){
          //取得一筆表單資料
          tResult = (String[])tIter.next();
          //將template取代成實際表單欄位值
          tFormFieldValue = tFormFieldValue.replace("#Company",tResult[0]);
          tFormFieldValue = tFormFieldValue.replace("#Branch",tResult[1]);
          tFormFieldValue = tFormFieldValue.replace("#Approval","Yes");
          //tFormFieldValue = tFormFieldValue.replace("#Approval","是");
          tFormFieldValue = tFormFieldValue.replace("#FormNumber"+i,tResult[2]);
          tFormFieldValue = tFormFieldValue.replace("#Single"+i,tResult[3]);
          tFormFieldValue = tFormFieldValue.replace("#Consultant"+i,tResult[4]);
          tFormFieldValue = tFormFieldValue.replace("#CustomerName"+i,tResult[5]);
          tFormFieldValue = tFormFieldValue.replace("#Category"+i,tResult[6]);
          tFormFieldValue = tFormFieldValue.replace("#Payment"+i,tResult[7]);
          tFormFieldValue = tFormFieldValue.replace("#SigningBonus"+i,tResult[8]);
          tFormFieldValue = tFormFieldValue.replace("#EntryFee"+i,tResult[9]);
          tFormFieldValue = tFormFieldValue.replace("#FormContent"+i,tResult[10]);
          i++;
        }
        System.out.println("=============Replace XML ============");
        System.out.println("tFormFieldValue = " + tFormFieldValue);
        System.out.println("==================================");
        
        try{
          System.out.println("==============================");
          System.out.println(" WebService ");
          System.out.println("==============================");
          //取得WebServices服務
          tCall = (Call) tService.createCall();
          tCall.setTargetEndpointAddress("http://" + tServerHost + ":" + tServerPort + "/NaNaWeb/services/WorkflowService?wsdl");            
          //設定呼叫取得流程中表單OID的服務
          tCall.setOperationName(new QName("WorkflowService","findFormOIDsOfProcess"));
          //設定所要呼叫的method傳入參數(參數,流程代號)
          tParams = new Object[] { "SecondarySignoff" };            //將參數傳入呼叫取得表單OID的服務
          tObject = tCall.invoke(tParams);
          //完成流程發起後回傳流程序號
          tFormOIDs = tObject.toString();
          System.out.println("==============================");
          System.out.println("tFormOIDs = " + tFormOIDs);
          System.out.println("==============================");          
          //設定呼叫發起流程的服務
          tCall.setOperationName(new QName("WorkflowService","invokeProcess"));
          //設定所要呼叫的method傳入參(參數:流程代號、發起人代號、發起部門代號、FormFieldValues、主旨)
          tParams = new Object[] {"SecondarySignoff","100081","111050",tFormOIDs,tFormFieldValue,"佣金結算表二次簽核"};
          
          //將參數傳入呼叫發起流程服務
          tObject = tCall.invoke(tParams);
          //完成流程發起後回傳流程序號
          tSerialNo = tObject.toString();
            
          System.out.println("Complete Process Invoke:processSerialNumber = " + tSerialNo);
          
        }catch(Exception e){
          e.printStackTrace();
          System.out.println("Invoke Process Fail, id:" + tResult[0]);
        }
          
      }catch(Exception e){
        e.printStackTrace();      
      }finally{
        //無論執行成功與否皆將使用完畢的Connection關閉
        if(tConnection != null){
          try{
            tConnection.close();            
          }
          catch(Exception ex){
            ex.printStackTrace();
            System.out.println("Close Connection Fail!!!");
          }
          tConnection = null;
        }
        //無論執行成功與否皆將使用完畢的Statement關閉
        if(tStatement != null){
          try{
            tStatement.close();            
          }
          catch(Exception ex){
            ex.printStackTrace();
            System.out.println("Close Statement Fail!!!");
          }
        }
      }
      
    }

  }

目前用webservice發起流程,將傳入的參數,透過xml組合之後再去發起新的流程,但是發起的時候已經取得新的表單單號,但是在發起流程的時候,都會出現錯誤,請問大大們我是哪邊的問題呢?(errorlog如附件)


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
506 webservice invoke問題 dream1978 7208 2016-06-05 08:58
» JWorld@TW »  Java & XML、Web Service » Web Services

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8