-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathServiceUtil.java
More file actions
74 lines (61 loc) · 2.38 KB
/
Copy pathServiceUtil.java
File metadata and controls
74 lines (61 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* © Copyright IBM Corporation 2016.
* © Copyright HCL Technologies Ltd. 2017.
* LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/
package com.hcl.appscan.sdk.utils;
import java.io.File;
import java.io.IOException;
import javax.net.ssl.HttpsURLConnection;
import org.apache.wink.json4j.JSONArtifact;
import org.apache.wink.json4j.JSONException;
import org.apache.wink.json4j.JSONObject;
import com.hcl.appscan.sdk.CoreConstants;
import com.hcl.appscan.sdk.http.HttpClient;
import com.hcl.appscan.sdk.http.HttpResponse;
/**
* Provides scan service utilities.
*/
public class ServiceUtil implements CoreConstants {
/**
* Gets the SAClientUtil package used for running static analysis.
*
* @param destination The file to save the package to.
* @throws IOException
*/
public static void getSAClientUtil(File destination) throws IOException {
String request_url = SystemUtil.getDefaultServer() + String.format(API_SACLIENT_DOWNLOAD, API_SCX, SystemUtil.getOS());
HttpClient client = new HttpClient();
HttpResponse response = client.get(request_url, null, null);
if (response.getResponseCode() == HttpsURLConnection.HTTP_OK || response.getResponseCode() == HttpsURLConnection.HTTP_CREATED) {
if(!destination.getParentFile().isDirectory())
destination.getParentFile().mkdirs();
response.getResponseBodyAsFile(destination);
}
else
throw new IOException(response.getResponseBodyAsString());
}
/**
* Gets the latest available version of the SAClientUtil package used for running static analysis.
*
* @return The current version of the package.
* @throws IOException
*/
public static String getSAClientVersion() throws IOException {
String request_url = SystemUtil.getDefaultServer() + String.format(API_SACLIENT_VERSION, API_SCX, SystemUtil.getOS(), "true"); //$NON-NLS-1$
HttpClient client = new HttpClient();
HttpResponse response = client.get(request_url, null, null);
if (response.getResponseCode() == HttpsURLConnection.HTTP_OK || response.getResponseCode() == HttpsURLConnection.HTTP_CREATED) {
try {
JSONArtifact responseContent = response.getResponseBodyAsJSON();
if (responseContent != null) {
JSONObject object = (JSONObject) responseContent;
return object.getString(VERSION_NUMBER);
}
} catch (JSONException e) {
return "0"; //$NON-NLS-1$
}
}
return null;
}
}