summaryrefslogtreecommitdiffstats
path: root/sms-client
diff options
context:
space:
mode:
Diffstat (limited to 'sms-client')
-rw-r--r--sms-client/java/pom.xml2
-rw-r--r--sms-client/java/src/main/example/SmsClientExample.java6
-rw-r--r--sms-client/java/src/main/java/org/onap/aaf/sms/SmsClient.java40
-rw-r--r--sms-client/java/src/test/java/org/onap/aaf/sms/SmsTest.java2
4 files changed, 35 insertions, 15 deletions
diff --git a/sms-client/java/pom.xml b/sms-client/java/pom.xml
index e060feb..f178e55 100644
--- a/sms-client/java/pom.xml
+++ b/sms-client/java/pom.xml
@@ -4,7 +4,7 @@
<groupId>org.onap.aaf.sms</groupId>
<artifactId>sms-client</artifactId>
<packaging>jar</packaging>
- <version>1.0.0-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<name>sms-client</name>
<properties>
diff --git a/sms-client/java/src/main/example/SmsClientExample.java b/sms-client/java/src/main/example/SmsClientExample.java
index dc0e776..ca38adb 100644
--- a/sms-client/java/src/main/example/SmsClientExample.java
+++ b/sms-client/java/src/main/example/SmsClientExample.java
@@ -33,6 +33,11 @@ import java.util.Map;
import org.onap.aaf.sms.SmsClient;
import org.onap.aaf.sms.SmsResponse;
+/*
+ * Sample application demonstrating various operations related
+ * Secret Management Service's APIs
+ */
+
public class SmsClientExample {
public static void main(String[] args) throws Exception {
// Set up the Sun PKCS 11 provider
@@ -66,7 +71,6 @@ public class SmsClientExample {
trustManagerFactory.getTrustManagers(), new SecureRandom());
//Create a socket factory
SSLSocketFactory ssf = context.getSocketFactory();
- SSLSessionContext sessCtx = context.getServerSessionContext();
SmsClient sms = new SmsClient("onap.mydomain.com", 10443, ssf);
SmsResponse resp1 = sms.createDomain("onap.new.test.sms0");
if ( resp1.getSuccess() ) {
diff --git a/sms-client/java/src/main/java/org/onap/aaf/sms/SmsClient.java b/sms-client/java/src/main/java/org/onap/aaf/sms/SmsClient.java
index 17a9f16..8bc88fe 100644
--- a/sms-client/java/src/main/java/org/onap/aaf/sms/SmsClient.java
+++ b/sms-client/java/src/main/java/org/onap/aaf/sms/SmsClient.java
@@ -98,29 +98,45 @@ public class SmsClient implements SmsInterface {
return(jsontomap(jobj));
}
- protected SmsResponse execute(String reqtype, String t, String ins, boolean input, boolean output) {
+
+ /*
+ Inputs reqtype - type of Request, POST, GET, DELETE, PUT
+ urlstr - url to connect to
+ body - json encoded data being sent to SMS server
+ output - expect a response data from SMS server
+ Return SmsResponse Object
+ success or failure
+ response code if connection succeeded, otherwise -1
+ response string if expected.
+ */
+ protected SmsResponse execute(String reqtype, String urlstr, String body,
+ boolean output) {
HttpsURLConnection conn;
int errorcode = -1;
SmsResponse resp = new SmsResponse();
try {
- URL url = new URL(t);
+ URL url = new URL(urlstr);
conn = (HttpsURLConnection)url.openConnection();
conn.setSSLSocketFactory(ssf);
conn.setRequestMethod(reqtype);
- conn.setDoOutput(true);
- conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
- if ( input ) {
+ // If we have any data in body write it out
+ if ( body != null ) {
+ conn.setDoOutput(true);
+ // Implicitly connects and writes data
OutputStream out = conn.getOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(out);
- wr.write(ins);
+ wr.write(body);
wr.flush();
wr.close();
}
+
+ // Parse the response from Server here
+ // An implicit connection happens here
errorcode = conn.getResponseCode();
if ( output && errorcode > 0 ) {
InputStream inputstream = conn.getInputStream();
@@ -154,7 +170,7 @@ public class SmsClient implements SmsInterface {
String t = baset + "/domain";
String input = "{\"name\":\"" + dname + "\"}";
- SmsResponse resp = execute("POST", t, input, true, true);
+ SmsResponse resp = execute("POST", t, input, true);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 )
@@ -169,7 +185,7 @@ public class SmsClient implements SmsInterface {
String t = baset + "/domain/" + dname;
- SmsResponse resp = execute("DELETE", t, null, false, true);
+ SmsResponse resp = execute("DELETE", t, null, true);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 )
@@ -188,7 +204,7 @@ public class SmsClient implements SmsInterface {
cm.put("values", values);
JSONObject jobj = new JSONObject(cm);
- SmsResponse resp = execute("POST", t, jobj.toString(), true, false);
+ SmsResponse resp = execute("POST", t, jobj.toString(), false);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 )
@@ -203,7 +219,7 @@ public class SmsClient implements SmsInterface {
String t = baset + "/domain/" + dname + "/secret";
- SmsResponse resp = execute("GET", t, null, false, true);
+ SmsResponse resp = execute("GET", t, null, true);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 )
@@ -218,7 +234,7 @@ public class SmsClient implements SmsInterface {
String t = baset + "/domain/" + dname + "/secret/" + sname;
- SmsResponse resp = execute("GET", t, null, false, true);
+ SmsResponse resp = execute("GET", t, null, true);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 ) {
@@ -243,7 +259,7 @@ public class SmsClient implements SmsInterface {
String t = baset + "/domain/" + dname + "/secret/" + sname;
- SmsResponse resp = execute("DELETE", t, null, false, true);
+ SmsResponse resp = execute("DELETE", t, null, true);
int errcode = resp.getResponseCode();
if ( errcode > 0 && errcode/100 == 2 )
diff --git a/sms-client/java/src/test/java/org/onap/aaf/sms/SmsTest.java b/sms-client/java/src/test/java/org/onap/aaf/sms/SmsTest.java
index 5277557..fad2579 100644
--- a/sms-client/java/src/test/java/org/onap/aaf/sms/SmsTest.java
+++ b/sms-client/java/src/test/java/org/onap/aaf/sms/SmsTest.java
@@ -43,7 +43,7 @@ public class SmsTest extends SmsClient {
public SmsTest(String host, int port, String version, SSLSocketFactory s) {
super(host, port, version, s);
}
- public SmsResponse execute(String reqtype, String t, String ins, boolean input, boolean output) {
+ public SmsResponse execute(String reqtype, String t, String ins, boolean output) {
Map<String, Object> m;
SmsResponse resp = new SmsResponse();
System.out.println(t);