package th.co.muangthai.endrprint.model.wfservice; import th.co.muangthai.endrprint.util.VSMUtil; import th.co.muangthai.endrprint.wfurlxml.MTLGetUrlWS; import th.co.muangthai.endrprint.wfurlxml.MTLGetUrlWS_Service; import th.co.muangthai.endrprint.wfurlxml.RequestMessage; import th.co.muangthai.endrprint.wfurlxml.ResponseMessage; import th.co.muangthai.endrprint.wfxml.*; import java.lang.Exception; import java.util.concurrent.*; /** * Created by noname on 2/17/16. */ public class MTLGetUrlService { public String querySearchPolicyDetail(String applicationNumber,String documentType){ String txtUrl = ""; try { // set parameter final MTLGetUrlWS_Service qsService = new MTLGetUrlWS_Service(); final RequestMessage param = new RequestMessage(); // set parameter //param.setPPolicyNo(policyNo); param.setApplicationNumber(applicationNumber); param.setDocumentType(null); if(VSMUtil.isNotEmpty(documentType)){ param.setDocumentType(documentType); } param.setPageNumber("1"); param.setPermission("1003"); param.setPosition("0,0,800,1050"); param.setTemplateId("6162D2C1F67454404163F094B086B571"); param.setVersionNumber(""); ExecutorService executor = Executors.newCachedThreadPool(); Callable task = new Callable(){ public ResponseMessage call() { MTLGetUrlWS queryPtt = qsService.getMTLGetUrlWSPort(); return queryPtt.getUrl(param); } }; Future future = executor.submit(task); ResponseMessage vwCollection = new ResponseMessage(); //DbAdapterAlphAIRTypeQueryOutputCollection vwCollection = queryPtt.SearchPolicyDetailAdapterOutputCollection(param); //log.info("*** Return Start > " + DateUtil.toFormatString(new Date(),"dd/MM/yyyy HH:mm:ss")); try { Object obj2 = future.get(30, TimeUnit.SECONDS); if(obj2 != null){ vwCollection = (ResponseMessage)obj2; } } catch (TimeoutException ex) { vwCollection = new ResponseMessage(); future.cancel(true); return ""; } catch (ExecutionException e) { // handle other exceptions } catch (InterruptedException e) { e.printStackTrace(); } finally { executor.shutdown(); } if(null != vwCollection){ txtUrl = vwCollection.getUrl(); } }catch (Exception e){ txtUrl = ""; } return txtUrl; } }