-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBaseController.java
More file actions
executable file
·66 lines (54 loc) · 2.54 KB
/
BaseController.java
File metadata and controls
executable file
·66 lines (54 loc) · 2.54 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
//
//
package SecureNetRestApiSDK.Api.Controllers;
import java.io.InputStream;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Properties;
import SNET.Core.APIContext;
import SNET.Core.Helper;
import SecureNetRestApiSDK.Api.Models.DeveloperApplication;
import SecureNetRestApiSDK.Api.Requests.SecureNetRequest;
import SecureNetRestApiSDK.Api.Responses.SecureNetResponse;
import com.google.gson.Gson;
public abstract class BaseController {
public SecureNetResponse processRequest(APIContext apiContext, SecureNetRequest secureNetRequest, Class<? extends SecureNetResponse> responseClazz) throws Exception {
try{
if (secureNetRequest == null) {
throw new IllegalArgumentException("secureNetRequest");
}
Properties config = new Properties();
Dictionary<String, String> props = new Hashtable<String, String>();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream stream = cl.getResourceAsStream("config.properties");
if (stream == null) {
ClassLoader applicationClassLoader = BaseController.class.getClassLoader();
stream = applicationClassLoader.getResourceAsStream("config.properties");
}
if (stream == null) {
throw new IllegalArgumentException("config.properties not found");
}
config.load(stream);
props.put("secureNetId", config.getProperty("secureNetId"));
props.put("secureKey", config.getProperty("secureKey"));
props.put("mode", config.getProperty("mode"));
props.put("endpoint", config.getProperty("endpoint"));
props.put("timeout", config.getProperty("timeout"));
props.put("connectionTimeout", config.getProperty("connectionTimeout"));
props.put("developerId", config.getProperty("developerId"));
props.put("versionId", config.getProperty("versionId"));
apiContext.setConfig(props);
DeveloperApplication devApp = new DeveloperApplication();
devApp.setDeveloperId(new Integer(config.getProperty("developerId")));
devApp.setVersion(config.getProperty("versionId"));
secureNetRequest.setDeveloperApplication( devApp );
String payLoad =new Gson().toJson(secureNetRequest);
String response = Helper.configureAndExecute(apiContext, secureNetRequest.getMethod(), secureNetRequest.getUri(), payLoad);
return (SecureNetResponse) new Gson().fromJson(response,responseClazz);
}
catch(Exception ex){
ex.printStackTrace();
throw ex;
}
}
}