Created
October 6, 2015 07:39
-
-
Save sauthieg/5135a0d9c976778f350a to your computer and use it in GitHub Desktop.
Demonstrate usage of ForgeRock CREST Http Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.forgerock.http.handler.HttpClientHandler | |
import org.forgerock.services.context.RootContext | |
import static org.forgerock.json.JsonValue.json | |
import static org.forgerock.json.resource.Requests.* | |
import static org.forgerock.json.resource.http.CrestHttp.newConnectionFactory | |
import static org.forgerock.util.query.QueryFilter.alwaysTrue | |
def handler = new HttpClientHandler() | |
connection = newConnectionFactory(handler, new URI("http://localhost:8080/")).connection | |
def context = new RootContext() | |
// Clear all users just to make sure :) | |
connection.action(context, newActionRequest("users", "clear")) | |
// Create operation | |
def alice = [:] | |
alice.uid = "alice" | |
alice.email = "[email protected]" | |
def bob = [:] | |
bob.uid = "bob" | |
bob.email = "[email protected]" | |
[alice, bob].each { | |
connection.createAsync(context, newCreateRequest("users", (String) it.uid, json(it))) | |
.thenOnResult { println "Resource created $it.content" }.get() | |
} | |
// Asynchronous query operation | |
def query = newQueryRequest("users") | |
query.queryFilter = alwaysTrue() | |
query.additionalParameters._prettyPrint = 'true' | |
connection.queryAsync(context, query) { | |
println "Queried $it.content" | |
return true | |
}.thenFinally { | |
handler.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment