summaryrefslogtreecommitdiffstats
path: root/cadi/oauth-enduser
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-10-15 08:19:50 -0500
committerInstrumental <jonathan.gathman@att.com>2019-10-15 08:35:35 -0500
commit1296352d8eafee57f982a4342ad79ada4aa56d28 (patch)
tree355cdb89d85530a861319f892b0f24236e6adc50 /cadi/oauth-enduser
parentbdce7667a6e272e2fa32e298d957a0d9090c5bc9 (diff)
Sonar Fixes, Formatting
Issue-ID: AAF-1019 Change-Id: Ica49d9e7323aad9622ff9d95cc21b87430c22c54 Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi/oauth-enduser')
-rw-r--r--cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/ClientFactory.java6
-rw-r--r--cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java12
-rw-r--r--cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java56
-rw-r--r--cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java54
-rw-r--r--cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java44
-rw-r--r--cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/SimpleRestClientExample.java58
6 files changed, 115 insertions, 115 deletions
diff --git a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/ClientFactory.java b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/ClientFactory.java
index 2a1ecdeb..6bdda4e0 100644
--- a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/ClientFactory.java
+++ b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/ClientFactory.java
@@ -7,9 +7,9 @@
* 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.
@@ -41,7 +41,7 @@ public class ClientFactory {
throw new CadiException(e);
}
}
-
+
public ClientFactory(String[] args) throws APIException, CadiException {
this(new PropAccess(args));
}
diff --git a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java
index 107e1d89..2b1003cb 100644
--- a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java
+++ b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,7 +24,7 @@ import org.onap.aaf.cadi.client.Future;
public class RESTException extends Exception {
/**
- *
+ *
*/
private static final long serialVersionUID = -5232371598208651058L;
private Future<?> future;
@@ -32,11 +32,11 @@ public class RESTException extends Exception {
public RESTException(Future<?> future) {
this.future = future;
}
-
+
public int getCode() {
return future.code();
}
-
+
public String getMsg() {
return future.body();
}
@@ -61,6 +61,6 @@ public class RESTException extends Exception {
public String getLocalizedMessage() {
return errorString();
}
-
+
}
diff --git a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java
index c2deb458..3b7ab032 100644
--- a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java
+++ b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java
@@ -7,9 +7,9 @@
* 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.
@@ -56,18 +56,18 @@ public class SimpleRESTClient {
public String[] headers() {
return EMPTY;
}};
-
+
public SimpleRESTClient(final TokenClientFactory tcf, final String tokenURL, final String endpoint, final String[] scope) throws CadiException, LocatorException, APIException {
callTimeout = Integer.parseInt(tcf.access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF));
tokenClient = tcf.newClient(tokenURL);
Result<TimedToken> rtt = tokenClient.getToken(scope);
if (rtt.isOK()) {
restClient = tcf.newTzClient(endpoint);
-
+
if ((client_id = tcf.access.getProperty(Config.AAF_APPID, null))==null) {
if ((client_id = tcf.access.getProperty(Config.CADI_ALIAS, null))==null) {
throw new CadiException(Config.AAF_APPID + " or " + Config.CADI_ALIAS + " needs to be defined");
- }
+ }
}
try {
restClient.setToken(client_id,rtt.value);
@@ -78,7 +78,7 @@ public class SimpleRESTClient {
throw new CadiException(rtt.error);
}
}
-
+
public SimpleRESTClient timeout(int newTimeout) {
callTimeout = newTimeout;
return this;
@@ -98,7 +98,7 @@ public class SimpleRESTClient {
}
return this;
}
-
+
/**
* Single Threaded Class for building up content
* @author Instrumental
@@ -109,24 +109,24 @@ public class SimpleRESTClient {
private String content;
private StringBuilder sb;
-
+
public Input() {
content = null;
sb = null;
}
-
+
public Input(final String content) {
this.content = content;
}
-
+
public void set(final String content) {
this.content = content;
}
-
+
public PrintWriter writer() {
return new PrintWriter(new StringBuilderWriter(builder()));
}
-
+
public StringBuilder builder() {
if (sb==null) {
sb = new StringBuilder();
@@ -134,7 +134,7 @@ public class SimpleRESTClient {
}
return sb;
}
-
+
/**
* Reuse StringBuilder object
*/
@@ -144,7 +144,7 @@ public class SimpleRESTClient {
sb.setLength(0);
}
}
-
+
@Override
public String toString() {
if (content!=null) {
@@ -162,7 +162,7 @@ public class SimpleRESTClient {
if (sb==null) {
rv = EMPTY_STREAM_BYTES;
} else {
- rv = sb.toString().getBytes();
+ rv = sb.toString().getBytes();
}
} else {
rv = content.getBytes();
@@ -173,7 +173,7 @@ public class SimpleRESTClient {
}
/////////////////////////////////////////////////////////////
- //
+ //
// CREATE
//
/////////////////////////////////////////////////////////////
@@ -194,11 +194,11 @@ public class SimpleRESTClient {
});
if (!future.get(callTimeout)) {
throw new RESTException(future);
- }
+ }
}
/////////////////////////////////////////////////////////////
- //
+ //
// READ
//
/////////////////////////////////////////////////////////////
@@ -221,11 +221,11 @@ public class SimpleRESTClient {
return future.value;
} else {
throw new RESTException(future);
- }
+ }
}
-
+
/////////////////////////////////////////////////////////////
- //
+ //
// UPDATE
//
/////////////////////////////////////////////////////////////
@@ -249,18 +249,18 @@ public class SimpleRESTClient {
return future.value;
} else {
throw new RESTException(future);
- }
+ }
}
/////////////////////////////////////////////////////////////
- //
+ //
// DELETE
//
/////////////////////////////////////////////////////////////
public void delete(final String path) throws RESTException, CadiException, LocatorException, APIException {
delete(path,APPLICATION_JSON);
}
-
+
public void delete(final String path, final String contentType) throws RESTException, CadiException, LocatorException, APIException {
Future<Void> future = restClient.best(new Retryable<Future<Void>>() {
@Override
@@ -270,17 +270,17 @@ public class SimpleRESTClient {
});
if (!future.get(callTimeout)) {
throw new RESTException(future);
- }
+ }
}
/////////////////////////////////////////////////////////////
-
+
private static class ETransfer implements EClient.Transfer {
private Input input;
public ETransfer(final Input input) {
this.input = input;
}
-
+
@Override
public void transfer(OutputStream os) throws IOException, APIException {
os.write(input.getBytes());
@@ -290,7 +290,7 @@ public class SimpleRESTClient {
public interface Headers {
String[] headers();
}
-
+
public String[] headers() {
if (chain==null) {
return headers.headers();
diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java
index d0c800bf..0dec0999 100644
--- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java
+++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java
@@ -7,9 +7,9 @@
* 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.
@@ -56,14 +56,14 @@ public class OAuthExample {
public final static void main(final String args[]) {
// These Objects are expected to be Long-Lived... Construct once
-
+
// Property Access
- // This method will allow you to set "cadi_prop_files" (or any other property) on Command line
+ // This method will allow you to set "cadi_prop_files" (or any other property) on Command line
access = new PropAccess(args);
-
+
// access = PropAccess();
// Note: This style will load "cadi_prop_files" from VM Args
-
+
// Token aware Client Factory
try {
tcf = TokenClientFactory.instance(access);
@@ -71,8 +71,8 @@ public class OAuthExample {
access.log(e1, "Unable to setup OAuth Client Factory, Fail Fast");
System.exit(1);
}
-
-
+
+
// Obtain Endpoints for OAuth2 from Properties. Expected is "cadi.properties" file, pointed to by "cadi_prop_files"
try {
Map<String, String> aaf_urls = Agent.loadURLs(access);
@@ -81,9 +81,9 @@ public class OAuthExample {
String tokenIntrospectURL = access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL); // Default to AAF);
// Get Hello Service
final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL);
-
+
final int CALL_TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF));
-
+
//////////////////////////////////////////////////////////////////////
// Scenario 1:
// Get and use an OAuth Client, which understands Token Management
@@ -93,7 +93,7 @@ public class OAuthExample {
TokenClient tc = tcf.newClient(tokenServiceURL); // can set your own timeout here (url, timeoutMilliseconds)
// Set your Application (MicroService, whatever) Credentials here
- // These are how your Application is known, particularly to the OAuth Server.
+ // These are how your Application is known, particularly to the OAuth Server.
// If AAF Token server, then its just the same as your other AAF MechID creds
// If it is the Alternate OAUTH, you'll need THOSE credentials. See that tool's Onboarding procedures.
String client_id = access.getProperty(Config.AAF_APPID);
@@ -103,7 +103,7 @@ public class OAuthExample {
}
String client_secret = access.getProperty(Config.AAF_APPPASS);
tc.client_creds(client_id, client_secret);
-
+
// If you are working with Credentials the End User, set username/password as appropriate to the OAuth Server
// tc.password(end_user_id, end_user_password);
// IMPORTANT:
@@ -114,7 +114,7 @@ public class OAuthExample {
// With AAF, the Scopes you put in are the AAF Namespaces you want access to. Your Token will contain the
// AAF Permissions of the Namespaces (you can put in more than one), the user name (or client_id if no user_name),
// is allowed to see.
-
+
// Here's a trick to get the namespace out of a Fully Qualified AAF Identity (your MechID)
String ns = FQI.reverseDomain(client_id);
System.out.printf("\nNote: The AAF Namespace of FQI (Fully Qualified Identity) %s is %s\n\n",client_id, ns);
@@ -122,23 +122,23 @@ public class OAuthExample {
// Now, we can get a Token. Note: for "scope", use AAF Namespaces to get AAF Permissions embedded in
// Note: getToken checks if Token is expired, if so, then refreshes before handing back.
Result<TimedToken> rtt = tc.getToken(ns,"org.onap.test");
-
+
// Note: you can clear a Token's Disk/Memory presence by
// 1) removing the Token from the "token/outgoing" directory on the O/S
// 2) programmatically by calling "clearToken" with exact params as "getToken", when it has the same credentials set
// tc.clearToken("org.onap.aaf","org.onap.test");
-
+
// Result Object can be queried for success
if (rtt.isOK()) {
TimedToken token = rtt.value;
print(token); // Take a look at what's in a Token
-
+
// Use this Token in your client calls with "Tokenized Client" (TzClient)
// These should NOT be used cross thread.
TzClient helloClient = tcf.newTzClient(endServicesURL);
helloClient.setToken(client_id, token);
-
- // This client call style, "best" call with "Retryable" inner class covers finding an available Service
+
+ // This client call style, "best" call with "Retryable" inner class covers finding an available Service
// (when Multi-services exist) for the best service, based (currently) on distance.
//
// the "Generic" in Type gives a Return Value for the Code, which you can set on the "best" method
@@ -149,20 +149,20 @@ public class OAuthExample {
Future<String> future = client.read("hello","text/plain");
// The "future" calling method allows you to do other processing, such as call more than one backend
// client before picking up the result
- // If "get" matches the HTTP Code for the method (i.e. read HTTP Return value is 200), then
+ // If "get" matches the HTTP Code for the method (i.e. read HTTP Return value is 200), then
if (future.get(CALL_TIMEOUT)) {
// Client Returned expected value
return future.value;
} else {
throw new APIException(future.code() + future.body());
- }
+ }
}
});
-
+
// You want to do something with returned value. Here, we say "hello"
System.out.printf("\nPositive Response from Hello: %s\n",rv);
-
-
+
+
//////////////////////////////////////////////////////////////////////
// Scenario 2:
// As a Service, read Introspection information as proof of Authenticated Authorization
@@ -187,12 +187,12 @@ public class OAuthExample {
} else {
access.printf(Level.ERROR, "Unable to obtain OAuth Token: %d %s\n",rtt.code,rtt.error);
}
-
+
} catch (CadiException | LocatorException | APIException | IOException e) {
e.printStackTrace();
}
}
-
+
/////////////////////////////////////////////////////////////
// Examples of Object Access
/////////////////////////////////////////////////////////////
@@ -207,7 +207,7 @@ public class OAuthExample {
t.getScope(),
t.getRefreshToken());
}
-
+
private static void print(Introspect ti) {
if (ti==null || ti.getClientId()==null) {
System.out.println("Empty Introspect");
@@ -232,7 +232,7 @@ public class OAuthExample {
Chrono.timeStamp(exp),
ti.getScope(),
ti.getContent()==null?"":ti.getContent());
-
+
System.out.println();
}
diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java
index b8cce9e5..2d489f83 100644
--- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java
+++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java
@@ -7,9 +7,9 @@
* 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.
@@ -56,25 +56,25 @@ public class OnapClientExample {
public final static void main(final String args[]) {
// These Objects are expected to be Long-Lived... Construct once
-
+
// Property Access
- // This method will allow you to set "cadi_prop_files" (or any other property) on Command line
+ // This method will allow you to set "cadi_prop_files" (or any other property) on Command line
access = new PropAccess(args);
// Note: This style will load "cadi_prop_files" from VM Args
// access = PropAccess();
try {
Map<String, String> aaf_urls = Agent.loadURLs(access);
Agent.fillMissing(access, aaf_urls);
-
+
// Token aware Client Factory
tcf = TokenClientFactory.instance(access);
} catch (APIException | GeneralSecurityException | IOException | CadiException e1) {
access.log(e1, "Unable to setup OAuth Client Factory, Fail Fast");
System.exit(1);
}
-
+
final int CALL_TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF));
-
+
try {
//////////////////////////////////////////////////////////////////////
// Scenario 1:
@@ -84,7 +84,7 @@ public class OnapClientExample {
// In this example, it is AAF, but it can be the Alternate OAuth
TokenClient tc = tcf.newClient(Config.AAF_OAUTH2_TOKEN_URL); // can set your own timeout here (url, timeoutMilliseconds)
-
+
// Here's a trick to get the namespace out of a Fully Qualified AAF Identity (your MechID)
String ns = FQI.reverseDomain(tc.client_id());
System.out.printf("\nNote: The AAF Namespace of FQI (Fully Qualified Identity) %s is %s\n\n",tc.client_id(), ns);
@@ -92,17 +92,17 @@ public class OnapClientExample {
// Now, we can get a Token. Note: for "scope", use AAF Namespaces to get AAF Permissions embedded in
// Note: getToken checks if Token is expired, if so, then refreshes before handing back.
Result<TimedToken> rtt = tc.getToken(ns,"org.onap.test"); // get multiple scopes
-
+
// Note: you can clear a Token's Disk/Memory presence by
// 1) removing the Token from the "token/outgoing" directory on the O/S
// 2) programmatically by calling "clearToken" with exact params as "getToken", when it has the same credentials set
// tc.clearToken("org.onap.aaf","org.onap.test");
-
+
// Result Object can be queried for success
if (rtt.isOK()) {
TimedToken token = rtt.value;
print(token); // Take a look at what's in a Token
-
+
// Use this Token in your client calls with "Tokenized Client" (TzClient)
// These should NOT be used cross thread.
// Get Hello Service URL... roll your own in your own world.
@@ -111,8 +111,8 @@ public class OnapClientExample {
TzClient helloClient = tcf.newTzClient(endServicesURL);
helloClient.setToken(tc.client_id(), token);
-
- // This client call style, "best" call with "Retryable" inner class covers finding an available Service
+
+ // This client call style, "best" call with "Retryable" inner class covers finding an available Service
// (when Multi-services exist) for the best service, based (currently) on distance.
//
// the "Generic" in Type gives a Return Value for the Code, which you can set on the "best" method
@@ -123,20 +123,20 @@ public class OnapClientExample {
Future<String> future = client.read("hello","text/plain");
// The "future" calling method allows you to do other processing, such as call more than one backend
// client before picking up the result
- // If "get" matches the HTTP Code for the method (i.e. read HTTP Return value is 200), then
+ // If "get" matches the HTTP Code for the method (i.e. read HTTP Return value is 200), then
if (future.get(CALL_TIMEOUT)) {
// Client Returned expected value
return future.value;
} else {
throw new APIException(future.code() + future.body());
- }
+ }
}
});
-
+
// You want to do something with returned value. Here, we say "hello"
System.out.printf("\nPositive Response from Hello: %s\n",rv);
-
-
+
+
//////////////////////////////////////////////////////////////////////
// Scenario 2:
// As a Service, read Introspection information as proof of Authenticated Authorization
@@ -160,12 +160,12 @@ public class OnapClientExample {
} else {
access.printf(Level.ERROR, "Unable to obtain OAuth Token: %d %s\n",rtt.code,rtt.error);
}
-
+
} catch (CadiException | LocatorException | APIException | IOException e) {
e.printStackTrace();
}
}
-
+
/////////////////////////////////////////////////////////////
// Examples of Object Access
/////////////////////////////////////////////////////////////
@@ -180,7 +180,7 @@ public class OnapClientExample {
t.getScope(),
t.getRefreshToken());
}
-
+
private static void print(Introspect ti) {
if (ti==null || ti.getClientId()==null) {
System.out.println("Empty Introspect");
@@ -205,7 +205,7 @@ public class OnapClientExample {
Chrono.timeStamp(exp),
ti.getScope(),
ti.getContent()==null?"":ti.getContent());
-
+
System.out.println();
}
diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/SimpleRestClientExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/SimpleRestClientExample.java
index dc1824fc..c15e434d 100644
--- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/SimpleRestClientExample.java
+++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/SimpleRestClientExample.java
@@ -7,9 +7,9 @@
* 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.
@@ -39,29 +39,29 @@ public class SimpleRestClientExample {
try {
// Note: Expect ClientFactory to be long-lived... do NOT create more than once.
ClientFactory cf = new ClientFactory(args);
-
-
+
+
String urlString = cf.getAccess().getProperty("myurl", null);
if (urlString==null) {
System.out.println("Note: In your startup, add \"myurl=https://<aaf hello machine>:8130\" to command line\n\t"
- + "OR\n\t"
+ + "OR\n\t"
+ " add -Dmyurl=https://<aaf hello machine>:8130 to VM Args\n\t"
+ "where \"aaf hello machine\" is an aaf Installation you know about.");
} else {
-
+
SimpleRESTClient restClient = cf.simpleRESTClient(urlString,"org.osaaf.aaf");
/////////////////////////////////////////////////////////////
- //
+ //
// Creating Content for CREATE/UPDATE
//
/////////////////////////////////////////////////////////////
// Create an object that can be reusable IN THIS THREAD ONLY... Not Thread-safe on purpose
Input input = new SimpleRESTClient.Input();
-
+
// Note: alternate use is to set the input object to an already created String
// Input input = new SimpleRESTClient.Input(aString);
-
+
PrintWriter pw = input.writer();
pw.print("{\"something\": [");
for (int i=0;i<4;++i) {
@@ -73,16 +73,16 @@ public class SimpleRestClientExample {
pw.print('}');
}
pw.println("]}");
-
+
// You can check or log the content
String content = input.toString();
System.out.println(content);
-
- // Good form for Writers is that you should close it...
+
+ // Good form for Writers is that you should close it...
pw.close();
/////////////////////////////////////////////////////////////
- //
+ //
// CREATE/POST
//
/////////////////////////////////////////////////////////////
@@ -100,7 +100,7 @@ public class SimpleRestClientExample {
/////////////////////////////////////////////////////////////
- //
+ //
// READ/GET
//
/////////////////////////////////////////////////////////////
@@ -110,24 +110,24 @@ public class SimpleRestClientExample {
System.out.println("-------- START REST READ/GET --------");
boolean expectException = false;
try {
-
+
// Call with no Queries
String rv = restClient.get("resthello/rest_id");
System.out.println(rv);
-
+
// Same call with "read" style
rv = restClient.read("resthello/rest_id");
System.out.println(rv);
-
-
+
+
// Call with Queries
rv = restClient.get("resthello/rest_id?perm=org.osaaf.people|*|read");
System.out.println(rv);
-
+
// Call setting ID from principal coming from Trans
// Pretend Transaction
HRequest req = new HRequest("demo@people.osaaf.org"); // Pretend Trans has Jonathan as Identity
-
+
// Call with RESTException, which allows obtaining HTTPCode and any Error message sent
rv = restClient.endUser(req.userPrincipal()).get("resthello/rest_id?perm=org.osaaf.people|*|read");
System.out.println(rv);
@@ -150,17 +150,17 @@ public class SimpleRestClientExample {
}
/////////////////////////////////////////////////////////////
- //
+ //
// UPDATE/PUT
//
/////////////////////////////////////////////////////////////
-
+
// If you use "input" object again as a writer, you can clear it on the same thread, and go again
input.clear();
// Here we just set to a String, instead of Writing
input.set("{\"something\" : []}");
-
+
System.out.println("-------- END REST UPDATE/PUT --------");
try {
String rv = restClient.update("resthello/rest_id", input);
@@ -175,7 +175,7 @@ public class SimpleRestClientExample {
}
/////////////////////////////////////////////////////////////
- //
+ //
// DELETE
//
/////////////////////////////////////////////////////////////
@@ -191,14 +191,14 @@ public class SimpleRestClientExample {
} finally {
System.out.println("-------- END REST DELETE --------");
}
- }
+ }
} catch (CadiException | APIException e) {
e.printStackTrace();
}
}
-
- private static class HRequest {
-
+
+ private static class HRequest {
+
public HRequest(String fqi) {
name = fqi;
}
@@ -212,7 +212,7 @@ public class SimpleRestClientExample {
public String getName() {
return name;
}
-
+
};
}
}