summaryrefslogtreecommitdiffstats
path: root/wfenginemgrservice/src/main
diff options
context:
space:
mode:
authorZhaoxing <meng.zhaoxing1@zte.com.cn>2017-10-13 15:23:14 +0800
committerZhaoxing <meng.zhaoxing1@zte.com.cn>2017-10-13 15:23:14 +0800
commitda675ef4d11d68ad537390ce99bb4eb5bd7d1bbb (patch)
treefeb14dec47b038698016d5d5e4de9008ff75ba12 /wfenginemgrservice/src/main
parent2150833ba64fd8b339012c7dab1f5b219b7c978d (diff)
Fix the docker build error for vfc-nfvo-wfengine
Change-Id: I136cd06f9b71fa6d51f25cfb2a00cb1d29fbe31c Issue-id: VFC-445 Signed-off-by: Zhaoxing <meng.zhaoxing1@zte.com.cn>
Diffstat (limited to 'wfenginemgrservice/src/main')
-rw-r--r--wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java584
-rw-r--r--wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.java230
2 files changed, 397 insertions, 417 deletions
diff --git a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
index 2eeb2fc..4d92dcb 100644
--- a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
+++ b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
@@ -1,289 +1,295 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.workflow.common;
-
-import java.io.IOException;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
-import org.onap.workflow.tools.Constants;
-import org.onap.workflow.tools.HttpDeleteWithBody;
-import org.onap.workflow.tools.RequestParameters;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gson.Gson;
-
-public class RestClient {
- private static final String HTTP = "http";
- private static final Logger logger = LoggerFactory.getLogger(RestClient.class);
-
- public enum HttpMethod {
- GET, POST, PUT, DELETE
- }
-
- /**
- *
- * @param method
- * @param ip
- * @param port
- * @param url
- * @param body
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse executeHttp(HttpMethod method, String ip, Integer port, String url,
- HttpEntity body) throws ClientProtocolException, IOException {
- logger.info("deployfile method send");
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpResponse httpResponse = null;
- RestResponse result = new RestResponse();
- try {
- if (ip == null) {
- ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
- }
- if (port == null) {
- port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
- }
- HttpHost target = new HttpHost(ip, port, HTTP);
- HttpRequest request = getRequest(method, url, body);
- logger.info("deployfile method send ip" + ip);
- request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
-
- httpResponse = httpclient.execute(target, request);
- HttpEntity entity = httpResponse.getEntity();
- logger.info("deployfile method send");
- if (entity != null && httpResponse.getStatusLine()!=null) {
- result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
- logger.info("reply status code deploy"+httpResponse.getStatusLine().getStatusCode());
- result.setResult(EntityUtils.toString(entity));
- }
- } catch (IOException e) {
- logger.warn("Close httpclient failed.", e);
- } finally {
- if (httpclient != null) {
- try {
- httpclient.close();
- } catch (IOException e) {
- logger.warn("Close httpclient failed.", e);
- }
- }
- }
- return result;
- }
-
- public static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
- HttpRequest request = null;
- switch (method) {
- case GET:
- request = new HttpGet(url);
- break;
- case POST:
- request = new HttpPost(url);
- ((HttpPost) request).setEntity(body);
- break;
- case PUT:
- request = new HttpPut(url);
- ((HttpPut) request).setEntity(body);
- break;
- case DELETE:
- request = new HttpDelete(url);
- break;
- default:
- break;
- }
- return request;
- }
-
- /**
- *
- * @param ip
- * @param port
- * @param url
- * @param requestBody
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse post(String ip, int port, String url, HttpEntity requestBody)
- throws ClientProtocolException, IOException {
- return executeHttp(HttpMethod.POST, ip, port, url, requestBody);
- }
-
-
-
- /**
- *
- * @param method
- * @param ip
- * @param port
- * @param url
- * @param body
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse executeHttpDeleteDeploy(HttpMethod method, String ip, Integer port,
- String url) throws ClientProtocolException, IOException {
- if (ip == null) {
- ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
- }
- if(port==null) {
- port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
- }
- RestResponse result = new RestResponse();
- CloseableHttpClient httpClient = HttpClients.createDefault();
- try {
- httpClient = HttpClients.createDefault();
- // "http://localhost:8080/activiti-rest/service/repository/deployments/167501"
- String deleteUrl = Constants.HTTP_HEADER + ip + Constants.COLON + port + url;
- HttpDeleteWithBody httpDeteTest = new HttpDeleteWithBody(deleteUrl);
- Gson gson = new Gson();
- RequestParameters reqPa = new RequestParameters();
- reqPa.setCasCade(true);
- String jsonStr = gson.toJson(reqPa, RequestParameters.class);
- StringEntity requestEntity = new StringEntity(jsonStr, "UTF-8");
- requestEntity.setContentEncoding("UTF-8");
- httpDeteTest.setHeader("Content-type", "application/json");
- httpDeteTest.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
- httpDeteTest.setEntity(new StringEntity(jsonStr));
- // returnValue = httpClient.execute(httpDeteTest, responseHandler); // 调接口获取返回值时,必须用此方法
- CloseableHttpResponse httpResonse = httpClient.execute(httpDeteTest);
- if(httpResonse!=null && httpResonse.getStatusLine()!=null) {
- int statusCode = httpResonse.getStatusLine().getStatusCode();
- result.setStatusCode(statusCode);
- }
- // result.setResult(EntityUtils.toString(httpResonse.getEntity()));
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- finally {
- try {
- httpClient.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return result;
- }
-
- /**
- *
- * @param method
- * @param ip
- * @param port
- * @param url
- * @param body
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse executeHttpStartIntance(HttpMethod method, String ip, Integer port,
- String url, ActivitiStartProcessRequest object) throws ClientProtocolException, IOException {
- String returnValue = "";
- RestResponse result = new RestResponse();
- CloseableHttpClient httpClient = HttpClients.createDefault();
- ResponseHandler<String> responseHandler = new BasicResponseHandler();
- try {
- httpClient = HttpClients.createDefault();
- if (ip == null) {
- ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
- }
- if(ip==null) {
- port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
- }
- HttpPost httpPost = new HttpPost(Constants.HTTP_HEADER + ip + ":" + port + url);
- Gson gson = new Gson();
- String jsonStr = gson.toJson(object, ActivitiStartProcessRequest.class);
- StringEntity requestEntity = new StringEntity(jsonStr, "utf-8");
- requestEntity.setContentEncoding("UTF-8");
- httpPost.setHeader("Content-type", "application/json");
- httpPost.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
- httpPost.setEntity(requestEntity);
- returnValue = httpClient.execute(httpPost, responseHandler); // 调接口获取返回值时,必须用此方法
- CloseableHttpResponse httpResonse = httpClient.execute(httpPost);
- if(httpResonse!=null && httpResonse.getStatusLine()!=null) {
- int statusCode = httpResonse.getStatusLine().getStatusCode();
- returnValue = EntityUtils.toString(httpResonse.getEntity(), "UTF-8");
- result.setStatusCode(statusCode);
- result.setResult(returnValue);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- finally {
- try {
- httpClient.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return result;
- }
-
- /**
- *
- * @param ip
- * @param port
- * @param url
- * @param requestBody
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse post(String ip, Integer port, String url,
- ActivitiStartProcessRequest requestBody) throws ClientProtocolException, IOException {
- return executeHttpStartIntance(HttpMethod.POST, ip, port, url, requestBody);
- }
-
- /**
- *
- * @param ip
- * @param port
- * @param url
- * @param requestBody
- * @return
- * @throws ClientProtocolException
- * @throws IOException
- */
- public static RestResponse post(String ip, Integer port, String url)
- throws ClientProtocolException, IOException {
- return executeHttpDeleteDeploy(HttpMethod.DELETE, ip, port, url);
- }
-
-}
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.common;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+import org.onap.workflow.tools.Constants;
+import org.onap.workflow.tools.HttpDeleteWithBody;
+import org.onap.workflow.tools.RequestParameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+public class RestClient {
+ private static final String HTTP = "http";
+ private static final Logger logger = LoggerFactory.getLogger(RestClient.class);
+ public static boolean isTest = false;
+
+ public enum HttpMethod {
+ GET, POST, PUT, DELETE
+ }
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttp(HttpMethod method, String ip, Integer port, String url,
+ HttpEntity body) throws ClientProtocolException, IOException {
+ if (isTest) {
+ return new RestResponse();
+ }
+
+ logger.info("deployfile method send");
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpResponse httpResponse = null;
+ RestResponse result = new RestResponse();
+ try {
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ if (port == null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
+ HttpHost target = new HttpHost(ip, port, HTTP);
+ HttpRequest request = getRequest(method, url, body);
+ logger.info("deployfile method send ip" + ip);
+ request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+
+ httpResponse = httpclient.execute(target, request);
+ HttpEntity entity = httpResponse.getEntity();
+ logger.info("deployfile method send");
+ if (entity != null && httpResponse.getStatusLine() != null) {
+ result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
+ logger.info("reply status code deploy" + httpResponse.getStatusLine().getStatusCode());
+ result.setResult(EntityUtils.toString(entity));
+ }
+ } catch (IOException e) {
+ logger.warn("Close httpclient failed.", e);
+ } finally {
+ closeHttpClient(httpclient);
+ }
+ return result;
+ }
+
+ public static boolean closeHttpClient(CloseableHttpClient httpclient) {
+ if (httpclient != null) {
+ try {
+ httpclient.close();
+ return true;
+ } catch (IOException e) {
+ logger.warn("Close httpclient failed.", e);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
+ HttpRequest request = null;
+ switch (method) {
+ case GET:
+ request = new HttpGet(url);
+ break;
+ case POST:
+ request = new HttpPost(url);
+ ((HttpPost) request).setEntity(body);
+ break;
+ case PUT:
+ request = new HttpPut(url);
+ ((HttpPut) request).setEntity(body);
+ break;
+ case DELETE:
+ request = new HttpDelete(url);
+ break;
+ default:
+ break;
+ }
+ return request;
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, int port, String url, HttpEntity requestBody)
+ throws ClientProtocolException, IOException {
+ return executeHttp(HttpMethod.POST, ip, port, url, requestBody);
+ }
+
+
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttpDeleteDeploy(HttpMethod method, String ip, Integer port,
+ String url) throws ClientProtocolException, IOException {
+ if (isTest) {
+ return new RestResponse();
+ }
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ if (port == null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
+ RestResponse result = new RestResponse();
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ try {
+ httpClient = HttpClients.createDefault();
+ // "http://localhost:8080/activiti-rest/service/repository/deployments/167501"
+ String deleteUrl = Constants.HTTP_HEADER + ip + Constants.COLON + port + url;
+ HttpDeleteWithBody httpDeteTest = new HttpDeleteWithBody(deleteUrl);
+ Gson gson = new Gson();
+ RequestParameters reqPa = new RequestParameters();
+ reqPa.setCasCade(true);
+ String jsonStr = gson.toJson(reqPa, RequestParameters.class);
+ StringEntity requestEntity = new StringEntity(jsonStr, "UTF-8");
+ requestEntity.setContentEncoding("UTF-8");
+ httpDeteTest.setHeader("Content-type", "application/json");
+ httpDeteTest.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+ httpDeteTest.setEntity(new StringEntity(jsonStr));
+ // returnValue = httpClient.execute(httpDeteTest, responseHandler); // 调接口获取返回值时,必须用此方法
+ CloseableHttpResponse httpResonse = httpClient.execute(httpDeteTest);
+ if (httpResonse != null && httpResonse.getStatusLine() != null) {
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ result.setStatusCode(statusCode);
+ }
+ // result.setResult(EntityUtils.toString(httpResonse.getEntity()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeHttpClient(httpClient);
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttpStartIntance(HttpMethod method, String ip, Integer port,
+ String url, ActivitiStartProcessRequest object) throws ClientProtocolException, IOException {
+ if (isTest) {
+ return new RestResponse();
+ }
+ String returnValue = "";
+ RestResponse result = new RestResponse();
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ ResponseHandler<String> responseHandler = new BasicResponseHandler();
+ try {
+ httpClient = HttpClients.createDefault();
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ if (port == null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
+ HttpPost httpPost = new HttpPost(Constants.HTTP_HEADER + ip + ":" + port + url);
+ Gson gson = new Gson();
+ String jsonStr = gson.toJson(object, ActivitiStartProcessRequest.class);
+ StringEntity requestEntity = new StringEntity(jsonStr, "utf-8");
+ requestEntity.setContentEncoding("UTF-8");
+ httpPost.setHeader("Content-type", "application/json");
+ httpPost.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+ httpPost.setEntity(requestEntity);
+ returnValue = httpClient.execute(httpPost, responseHandler); // 调接口获取返回值时,必须用此方法
+ CloseableHttpResponse httpResonse = httpClient.execute(httpPost);
+ if (httpResonse != null && httpResonse.getStatusLine() != null) {
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ returnValue = EntityUtils.toString(httpResonse.getEntity(), "UTF-8");
+ result.setStatusCode(statusCode);
+ result.setResult(returnValue);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ finally {
+ closeHttpClient(httpClient);
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, Integer port, String url,
+ ActivitiStartProcessRequest requestBody) throws ClientProtocolException, IOException {
+ return executeHttpStartIntance(HttpMethod.POST, ip, port, url, requestBody);
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, Integer port, String url)
+ throws ClientProtocolException, IOException {
+ return executeHttpDeleteDeploy(HttpMethod.DELETE, ip, port, url);
+ }
+
+}
diff --git a/wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.java b/wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.java
index 593f382..3af7f66 100644
--- a/wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.java
+++ b/wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.java
@@ -1,128 +1,102 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.workflow.externalservice.service.activitiservice;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.http.client.ClientProtocolException;
-import org.onap.workflow.common.Config;
-import org.onap.workflow.common.EnumModuleUrl;
-import org.onap.workflow.common.RestClient;
-import org.onap.workflow.common.RestClientUtils;
-import org.onap.workflow.common.RestResponse;
-import org.onap.workflow.common.ToolUtil;
-import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
-import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
-import org.onap.workflow.tools.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gson.Gson;
-
-/**
- *
- * @author 10090474
- *
- */
-public class ActivitiServiceConsumer {
- private static final Logger logger = LoggerFactory.getLogger(ActivitiServiceConsumer.class);
- private static final String DEPLOY_BPMNFILE_URL =
- EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/repository/deployments";
-
- public static RestResponse undeploybpmnfile(String deploymentId) {
- /*
- * IActivitiRestService activitiProxy = getActivitiService();
- * activitiProxy.undeployBpmnFile(deploymentId);
- */
- RestResponse res = deleteDeployProcess(deploymentId);
- // activitiProxy.startProcess(request);
-
- return res;
- }
-
- public static RestResponse startBpmnProcess(ActivitiStartProcessRequest request) {
- // IActivitiRestService activitiProxy = getActivitiService();
- // startProcess( request);
- // activitiProxy.startProcess(request);
- return startProcess(request);
- }
-
- public static RestResponse deleteDeployProcess(String deploymentId) {
- // TODO Auto-generated method stub
- RestResponse res = null;
- try {
- res = RestClient.post(null, null, Constants.DEPLOY_BPMNFILE_URL + "/" + deploymentId);
- } catch (ClientProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return res;
- }
-
- public static RestResponse startProcess(ActivitiStartProcessRequest request) {
- // TODO Auto-generated method stub
- RestResponse res = null;
- try {
- res = RestClient.post(null, null, Constants.ACITIVI_START_INSTANCE_URL, request);
- } catch (ClientProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- // if (Response.Status.OK.getStatusCode() == res.getStatusCode()
- // || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
- // Response response = new Gson().fromJson(res.getResult(), Response.class);
- // return response;
- // }
- return res;
- }
-
- public static ActivitiDeployResponse deploybpmnfile(InputStream ins, String filename)
- throws ClientProtocolException, IOException {
- try {
- return deployPackage2Activiti(ins, filename);
- } finally {
- ToolUtil.closeInputStream(ins);
- }
- }
-
- private static ActivitiDeployResponse deployPackage2Activiti(InputStream ins, String filename)
- throws ClientProtocolException, IOException {
- String ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
- int port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
- RestResponse res = RestClient.post(ip, port, DEPLOY_BPMNFILE_URL,
- RestClientUtils.buildMultipartRequest(ins, filename));
- logger.info("deployfile to activiti return. {}", res);
-
- if (Response.Status.OK.getStatusCode() == res.getStatusCode()
- || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
- ActivitiDeployResponse response =
- new Gson().fromJson(res.getResult(), ActivitiDeployResponse.class);
- return response;
- }
- return null;
- }
-}
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.externalservice.service.activitiservice;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.http.client.ClientProtocolException;
+import org.onap.workflow.common.Config;
+import org.onap.workflow.common.EnumModuleUrl;
+import org.onap.workflow.common.RestClient;
+import org.onap.workflow.common.RestClientUtils;
+import org.onap.workflow.common.RestResponse;
+import org.onap.workflow.common.ToolUtil;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+import org.onap.workflow.tools.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+/**
+ *
+ * @author 10090474
+ *
+ */
+public class ActivitiServiceConsumer {
+ private static final Logger logger = LoggerFactory.getLogger(ActivitiServiceConsumer.class);
+ private static final String DEPLOY_BPMNFILE_URL =
+ EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/repository/deployments";
+
+ public static RestResponse undeploybpmnfile(String deploymentId) {
+ return deleteDeployProcess(deploymentId);
+ }
+
+ public static RestResponse startBpmnProcess(ActivitiStartProcessRequest request) {
+ return startProcess(request);
+ }
+
+ public static RestResponse deleteDeployProcess(String deploymentId) {
+ RestResponse res = null;
+ try {
+ res = RestClient.post(null, null, Constants.DEPLOY_BPMNFILE_URL + "/" + deploymentId);
+ } catch (Exception e) {
+ return null;
+ }
+
+ return res;
+ }
+
+ public static RestResponse startProcess(ActivitiStartProcessRequest request) {
+ RestResponse res = null;
+ try {
+ res = RestClient.post(null, null, Constants.ACITIVI_START_INSTANCE_URL, request);
+ } catch (Exception e) {
+ return null;
+ }
+ return res;
+ }
+
+ public static ActivitiDeployResponse deploybpmnfile(InputStream ins, String filename)
+ throws ClientProtocolException, IOException {
+ try {
+ return deployPackage2Activiti(ins, filename);
+ } finally {
+ ToolUtil.closeInputStream(ins);
+ }
+ }
+
+ private static ActivitiDeployResponse deployPackage2Activiti(InputStream ins, String filename)
+ throws ClientProtocolException, IOException {
+ String ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ int port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ RestResponse res = RestClient.post(ip, port, DEPLOY_BPMNFILE_URL,
+ RestClientUtils.buildMultipartRequest(ins, filename));
+ logger.info("deployfile to activiti return. {}", res);
+
+ if (Response.Status.OK.getStatusCode() == res.getStatusCode()
+ || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
+ ActivitiDeployResponse response =
+ new Gson().fromJson(res.getResult(), ActivitiDeployResponse.class);
+ return response;
+ }
+ return null;
+ }
+}