From 0485f5c43dca4fbb42a71c5c93f7ae893a84180e Mon Sep 17 00:00:00 2001 From: Paolo Antinori Date: Fri, 7 Oct 2016 14:41:57 +0200 Subject: [PATCH] KEYCLOAK-3678 - Fuse examples, added Camel RestDSL --- .../OSGI-INF/blueprint/blueprint.xml | 47 ++++++++++++++++++- .../org/keycloak/example/CamelClient.java | 39 ++++++++++++--- examples/fuse/demorealm.json | 7 +++ examples/fuse/pom.xml | 2 +- 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/examples/fuse/camel/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/fuse/camel/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 698fdd05cf..506adaa428 100644 --- a/examples/fuse/camel/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/examples/fuse/camel/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -18,9 +18,10 @@ + http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint-2.17.1.xsd"> @@ -61,20 +62,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + Hello rest service + + Just an helllo + + + + + + + + + + + (__This second sentence is returned from a Camel RestDSL endpoint__) + + + + + + \ No newline at end of file diff --git a/examples/fuse/customer-app-fuse/src/main/java/org/keycloak/example/CamelClient.java b/examples/fuse/customer-app-fuse/src/main/java/org/keycloak/example/CamelClient.java index 00499e0bd9..ae2eea708f 100644 --- a/examples/fuse/customer-app-fuse/src/main/java/org/keycloak/example/CamelClient.java +++ b/examples/fuse/customer-app-fuse/src/main/java/org/keycloak/example/CamelClient.java @@ -17,6 +17,13 @@ package org.keycloak.example; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import javax.servlet.http.HttpServletRequest; + import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -24,12 +31,6 @@ import org.apache.http.client.methods.HttpGet; import org.keycloak.KeycloakSecurityContext; import org.keycloak.adapters.HttpClientBuilder; -import javax.servlet.http.HttpServletRequest; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - /** * @author Marek Posolda */ @@ -40,7 +41,10 @@ public class CamelClient { HttpClient client = new HttpClientBuilder() .disableTrustManager().build(); + + StringBuilder sb = new StringBuilder(); try { + // Initially let's invoke a simple Camel-Jetty exposed endpoint HttpGet get = new HttpGet("http://localhost:8383/admin-camel-endpoint"); get.addHeader("Authorization", "Bearer " + session.getTokenString()); try { @@ -52,7 +56,26 @@ public class CamelClient { HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); try { - return getStringFromInputStream(is); + sb.append(getStringFromInputStream(is)); + } finally { + is.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + // Here we invoke a Jetty endpoint, published using Camel RestDSL + get = new HttpGet("http://localhost:8484/restdsl/hello/world"); + get.addHeader("Authorization", "Bearer " + session.getTokenString()); + try { + HttpResponse response = client.execute(get); + if (response.getStatusLine().getStatusCode() != 200) { + return "There was a failure processing request with the RestDSL endpoint. You either didn't configure Keycloak properly or you don't have admin permission? Status code is " + + response.getStatusLine().getStatusCode(); + } + HttpEntity entity = response.getEntity(); + InputStream is = entity.getContent(); + try { + sb.append(getStringFromInputStream(is)); } finally { is.close(); } @@ -62,6 +85,8 @@ public class CamelClient { } finally { client.getConnectionManager().shutdown(); } + + return sb.toString(); } private static String getStringFromInputStream(InputStream is) { diff --git a/examples/fuse/demorealm.json b/examples/fuse/demorealm.json index d8a02a8eae..87bdbca36f 100644 --- a/examples/fuse/demorealm.json +++ b/examples/fuse/demorealm.json @@ -230,6 +230,13 @@ "baseUrl": "http://localhost:8383/admin-camel-endpoint", "bearerOnly": true }, + { + "clientId": "admin-camel-restdsl", + "enabled": true, + "adminUrl": "http://localhost:8484/restdsl", + "baseUrl": "http://localhost:8484/restdsl", + "bearerOnly": true + }, { "clientId": "ssh-jmx-admin-client", "enabled": true, diff --git a/examples/fuse/pom.xml b/examples/fuse/pom.xml index 7d3a23a3e8..7212a13eb6 100755 --- a/examples/fuse/pom.xml +++ b/examples/fuse/pom.xml @@ -30,7 +30,7 @@ keycloak-examples-fuse-parent pom - 2.16.1 + 2.17.0 customer-app-fuse