I have almost exactly the same problem:
I run the keycloak server in a wildfly 14 distribution. When I try to get a token from a
call within a deployed webapp (same wildfly) I get the same NPE. When running exactly the
same code from an external application all runs fine, no NPE.
I suppose running the code from within a war/ear file does not exactly the same like
running the code from single class. It worked versions ago (keycloak 2.1). For know I
don't have an idea what's the difference ...
Trying this code I receive a null token:
Keycloak keycloak =
Keycloak.getInstance("http://localhost:8180/auth",<http://localhost:8180/auth%22,>
"master", "admin", "admin", "admin-cli");
keycloak.tokenManager().getAccessTokenString();
> Il 17 dicembre 2018 alle 17.23 Luca Stancapiano
<luca.stancapiano at
vige.it<https://lists.jboss.org/mailman/listinfo/keycloak-user>> ha scritto:
>
>
> I'm triing a simple call via Rest to my keycloak 4.7.0.Final
server distribution. I created an admin user through the admin web console:
>
> user: admin
> pass: admin
>
> The server works on the 8180 port and it starts through the
command:
>
> ./standalone.sh -Djboss.socket.binding.port-offset=100
>
> I try to do a simple call using the admin client api imported
through the dependency in the pom:
>
> > <dependencies
> > <dependency
> > <groupId>org.keycloak</groupId
> > <artifactId>keycloak-admin-client</artifactId
> > <version>4.7.0.Final</version
> > <scope>test</scope
> > </dependency
> > </dependencies
>
> Here the java code:
>
>
Keycloak keycloak =
Keycloak.getInstance("http://localhost:8180/auth",<http://localhost:8180/auth%22,>
"master", "admin", "admin", "admin-cli");
> keycloak.realm("master").clients().findAll();
>
> when the findAll method is executed I receive the Exception:
>
> javax.ws.rs.ProcessingException: java.lang.NullPointerException
> at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:599)
> at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:436)
> at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
> at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
> at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
> at com.sun.proxy.$Proxy29.findAll(Unknown Source)
> at
it.vige.school.resttest.schoolmodule.test.PresenceTest.setPresence(PresenceTest.java:42)
> at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at
java.base/java.lang.reflect.Method.invoke(Method.java:566)
> at
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
> at
org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
> at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171)
> at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
> at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167)
> at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)
> at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
> at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
> at
java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
> at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
> at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
> at
java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
> at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
> at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
> at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
> at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
> at
org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
> at
org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
> at
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
> at
org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
> at
org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
> at
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
> at
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
> at
org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:142)
> at
org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:117)
> at
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
> at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
> at
org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
> at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
> Caused by: java.lang.NullPointerException
> at
org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:53)
> at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:586)
> ... 47 more
>
>
>
> What i miss?