import org.apache.http.HttpHost;\r
import org.apache.http.HttpRequest;\r
import org.apache.http.HttpResponse;\r
-import org.apache.http.client.ClientProtocolException;\r
import org.apache.http.client.ResponseHandler;\r
import org.apache.http.client.methods.CloseableHttpResponse;\r
import org.apache.http.client.methods.HttpDelete;\r
public class RestClient {\r
private static final String HTTP = "http";\r
private static final Logger logger = LoggerFactory.getLogger(RestClient.class);\r
+\r
+ //PublicExposureUsedInTest\r
public static boolean isTest = false;\r
\r
public enum HttpMethod {\r
* @throws IOException\r
*/\r
public static RestResponse executeHttp(HttpMethod method, String ip, Integer port, String url,\r
- HttpEntity body) throws ClientProtocolException, IOException {\r
+ HttpEntity body) throws IOException {\r
if (isTest) {\r
return new RestResponse();\r
}\r
HttpHost target = new HttpHost(ip, port, HTTP);\r
HttpRequest request = getRequest(method, url, body);\r
logger.info("deployfile method send ip" + ip);\r
- request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());\r
+ if(null != request)\r
+ request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());\r
\r
httpResponse = httpclient.execute(target, request);\r
HttpEntity entity = httpResponse.getEntity();\r
* @throws IOException\r
*/\r
public static RestResponse post(String ip, int port, String url, HttpEntity requestBody)\r
- throws ClientProtocolException, IOException {\r
+ throws IOException {\r
return executeHttp(HttpMethod.POST, ip, port, url, requestBody);\r
}\r
\r
* @throws IOException\r
*/\r
public static RestResponse executeHttpDeleteDeploy(HttpMethod method, String ip, Integer port,\r
- String url) throws ClientProtocolException, IOException {\r
+ String url) throws IOException {\r
if (isTest) {\r
return new RestResponse();\r
}\r
port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();\r
}\r
RestResponse result = new RestResponse();\r
- CloseableHttpClient httpClient = HttpClients.createDefault();\r
- try {\r
- httpClient = HttpClients.createDefault();\r
+ try(CloseableHttpClient httpClient = HttpClients.createDefault()){\r
// "http://localhost:8080/activiti-rest/service/repository/deployments/167501"\r
/* String deleteUrl =\r
Constants.HTTP_HEADER + ip + Constants.COLON + port + url + "?cascade=true";*/\r
}\r
// result.setResult(EntityUtils.toString(httpResonse.getEntity()));\r
} catch (Exception e) {\r
- e.printStackTrace();\r
- } finally {\r
- closeHttpClient(httpClient);\r
- }\r
-\r
+ logger.error("executeHttpDeleteDeploy ",e);\r
+ } \r
return result;\r
}\r
\r
* @throws IOException\r
*/\r
public static RestResponse executeHttpStartIntance(HttpMethod method, String ip, Integer port,\r
- String url, ActivitiStartProcessRequest object) throws ClientProtocolException, IOException {\r
+ String url, ActivitiStartProcessRequest object) throws IOException {\r
if (isTest) {\r
return new RestResponse();\r
}\r
String returnValue = "";\r
RestResponse result = new RestResponse();\r
- CloseableHttpClient httpClient = HttpClients.createDefault();\r
ResponseHandler<String> responseHandler = new BasicResponseHandler();\r
- try {\r
- httpClient = HttpClients.createDefault();\r
+ try (\r
+ CloseableHttpClient httpClient = HttpClients.createDefault()){\r
if (ip == null) {\r
ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();\r
}\r
result.setResult(returnValue);\r
}\r
} catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
-\r
- finally {\r
- closeHttpClient(httpClient);\r
+ logger.error("executeHttpStartIntance :",e);\r
}\r
+ \r
\r
return result;\r
}\r
* @throws IOException\r
*/\r
public static RestResponse post(String ip, Integer port, String url,\r
- ActivitiStartProcessRequest requestBody) throws ClientProtocolException, IOException {\r
+ ActivitiStartProcessRequest requestBody) throws IOException {\r
return executeHttpStartIntance(HttpMethod.POST, ip, port, url, requestBody);\r
}\r
\r
* @throws IOException\r
*/\r
public static RestResponse post(String ip, Integer port, String url)\r
- throws ClientProtocolException, IOException {\r
+ throws IOException {\r
return executeHttpDeleteDeploy(HttpMethod.DELETE, ip, port, url);\r
}\r
\r