Search in sources :

Example 6 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class SystemExpressionJobUtils method executeJobForManualFromRestServiceUrl.

public static SysExprJobLogVO executeJobForManualFromRestServiceUrl(SysExprJobVO sysExprJob, String accountId, HttpServletRequest request) throws ServiceException, Exception {
    SysExprJobLogVO result = new SysExprJobLogVO();
    // 注意 executeJob/ 請參考 ManualJobServiceImpl.java @Path("/executeJob/") 設定是否有變更, 如果有變更的話, 這裡的 url 也要修改
    String url = ApplicationSiteUtils.getBasePath(sysExprJob.getSystem(), request);
    if (!url.endsWith("/")) {
        url += "/";
    }
    //url += "services/jaxrs/executeJob/";
    url += Constants.getCxfWebServiceMainPathName() + Constants.getJAXRSServerFactoryBeanAddress() + "executeJob/";
    String encUploadOidStr = SystemExpressionJobUtils.getEncUploadOid(accountId, sysExprJob.getOid());
    url += encUploadOidStr;
    InputStreamReader isr = null;
    BufferedReader reader = null;
    try {
        HttpClient httpClient = new HttpClient();
        PostMethod post = new PostMethod(url);
        /*
	        NameValuePair[] data = {
	        		new NameValuePair("uploadOid", encUploadOidStr)
	        };
	        post.setRequestBody(data);
	        */
        post.setParameter("uploadOid", encUploadOidStr);
        int statusCode = httpClient.executeMethod(post);
        if (statusCode != 200 && statusCode != 202) {
            throw new Exception("error, http status code: " + statusCode);
        }
        isr = new InputStreamReader(post.getResponseBodyAsStream());
        reader = new BufferedReader(isr);
        String line = "";
        StringBuilder str = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            str.append(line);
        }
        ObjectMapper mapper = new ObjectMapper();
        result = mapper.readValue(str.toString(), SysExprJobLogVO.class);
    } catch (IOException e) {
        e.printStackTrace();
        result.setFaultMsg(e.getMessage().toString());
    } catch (Exception e) {
        e.printStackTrace();
        result.setFaultMsg(e.getMessage().toString());
    } finally {
        if (reader != null) {
            reader.close();
        }
        if (isr != null) {
            isr.close();
        }
        reader = null;
        isr = null;
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with SysExprJobLogVO

use of com.netsteadfast.greenstep.vo.SysExprJobLogVO in project bamboobsc by billchen198318.

the class SystemExpressionJobUtils method executeJobForManualWebClient.

public static SysExprJobLogVO executeJobForManualWebClient(SysExprJobVO sysExprJob, String accountId, HttpServletRequest request) throws ServiceException, Exception {
    SysExprJobLogVO result = new SysExprJobLogVO();
    // 注意 executeJob/ 請參考 ManualJobServiceImpl.java @Path("/executeJob/") 設定是否有變更, 如果有變更的話, 這裡的 url 也要修改
    String url = ApplicationSiteUtils.getBasePath(sysExprJob.getSystem(), request);
    if (!url.endsWith("/")) {
        url += "/";
    }
    //url += "services/jaxrs/";
    url += Constants.getCxfWebServiceMainPathName() + Constants.getJAXRSServerFactoryBeanAddress();
    String encUploadOidStr = SystemExpressionJobUtils.getEncUploadOid(accountId, sysExprJob.getOid());
    WebClient client = WebClient.create(url);
    Response response = client.accept("application/json").path("executeJob/{uploadOid}", encUploadOidStr).post(encUploadOidStr);
    int statusCode = response.getStatus();
    if (statusCode != 200 && statusCode != 202) {
        throw new Exception("error, http status code: " + statusCode);
    }
    String responseStr = response.readEntity(String.class);
    ObjectMapper mapper = new ObjectMapper();
    result = mapper.readValue(responseStr, SysExprJobLogVO.class);
    return result;
}
Also used : Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SysExprJobLogVO (com.netsteadfast.greenstep.vo.SysExprJobLogVO)7 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)6 SysExprJobVO (com.netsteadfast.greenstep.vo.SysExprJobVO)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 TbSysExprJob (com.netsteadfast.greenstep.po.hbm.TbSysExprJob)3 ISysExprJobService (com.netsteadfast.greenstep.service.ISysExprJobService)3 IOException (java.io.IOException)3 ExpressionJobObj (com.netsteadfast.greenstep.model.ExpressionJobObj)2 TbSysExpression (com.netsteadfast.greenstep.po.hbm.TbSysExpression)2 ISysExpressionService (com.netsteadfast.greenstep.service.ISysExpressionService)2 SysExpressionVO (com.netsteadfast.greenstep.vo.SysExpressionVO)2 HashMap (java.util.HashMap)2 TbSysExprJobLog (com.netsteadfast.greenstep.po.hbm.TbSysExprJobLog)1 ISysExprJobLogService (com.netsteadfast.greenstep.service.ISysExprJobLogService)1 ShiroLoginSupport (com.netsteadfast.greenstep.sys.ShiroLoginSupport)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 WebMethod (javax.jws.WebMethod)1