Minimal dependency on RestEasy when using Keycloak Java admin api - java

Keycloak Java Admin api works nice, however, including RestEasy dependencies in our pom.xml causing issues like this:
RESTEASY002307: Failed to execute
javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/
I wonder is there any configuration for RestEasy to work with "minimal" settings which are required by Keycloak Java Admin api? Nothing more than that.
What we have tried so far without success:
Disabling rest easy scanning in web.xml
Map RestEasy to dummy url like /restdummy
Our pom.xml:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>4.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.6.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.6.2.Final</version>
</dependency>
Any advice is welcome.

You can find the dependencies from mvnrepository for keycloak-admin-client

It seems that downgrading to earlier versions like 3.1.0. solved mentioned issue. However, it would be nice not to depend on whole framework just to use client functionalities.

Related

Is there a way to use both auth0-spring-security-api and java-jwt in the same project?

I'm trying to use auth0 and JWT in my Spring Boot project. I have imported these dependencies:
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0-spring-security-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
I also use JwtWebSecurityConfigurer to configure spring security.
If I use only auth0-spring-security-api, JwtWebSecurityConfigurer works correctly and checks my token. But I can't use the JWT class that is contained in java-jwt artifact.
If I import both dependencies in pom, it stops working and when Spring security checks my token, I get an error:
java.lang.NoSuchMethodError: com.auth0.jwt.interfaces.Verification.withIssuer(Ljava/lang/String;)Lcom/auth0/jwt/interfaces/Verification;
Also, I know that java-jwt library is a dependency of auth0-spring-security-api, I think that there's a sort of collision with two libraries. Does anyone have a solution? Thanks
Solved! If anyone has this problem, the solution is:
Check your pom.xml and the pom of auth0-spring-security-api. The java-jwt dependency imported from auth0-spring-security-api must be the same of java-jwt in your pom.

java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException

I have created a Web Service using Spring. It works fine when running it on my embedded tomcat server. However when I package it as a JAR file and run it with java -jar command, I am receiving this exception.
My service sends a simple soap request and the server response is:
"exception": "java.lang.NoClassDefFoundError",
"message": "javax/xml/soap/SOAPException",
That's the response I get in Postman.
Any ideas where I can look for the problem.
Adding the following in pom file solved the issue
<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
JavaSE 8 includes package java.xml.soap.
JavaSE 9 moved package javax.xml.soap to the module java.xml.ws.
Modules shared with JEE (like java.xml.ws) are included in JavaSE 9, but are
- deprecated for removal from a future version of JavaSE, and
- not on the default module path.
A quick workaround is to either
- run the jar with JRE 8: $MY_JRE8_HOME/bin/java -jar my.jar, or
- add a module for JRE 9: java --add-modules java.xml.ws -jar my.jar
Longer term, JavaSE projects that use modules like java.xml.ws must explicitly include the module like other libraries.
See https://stackoverflow.com/a/46359097
See JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default
(Reproduced NoClassDefError and workarounds with zipped SOAP web service project at https://spring.io/guides/gs/producing-web-service/)
Yes, In Java 11 java.xml.soap was completely removed.
java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException can be removed by adding the
following dependency.
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>2.0.0-RC3</version>
</dependency>
But later, you will encounter , javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found.
This can be solved by adding the following dependency.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
Hope, it helps!
Add the following dependencies, it should work then
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.6</version>
</dependency>
Refer the following links for a running piece of code (SpringBootSOAPWS + Java10)
Github- SpringBoot Soap Server
Github- SpringBoot Soap Client
I imported this one to sort out the issue: https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api/1.4.0
Adding this dependency will solve the issue.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
The JAX-WS dependency library “jaxws-api.jar” is missing.
Try:
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - for gradle or:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
I know this is already closed for all above people but I am still facing this issue even though I have added
jakarta-xml.soap-api and saaj jars in classpath.
Anything that I am missing to make it work.Tried out using javax-.xml-soap-api as well instead of jakarta jar but still same error.Somehow its not able to identify the jar.

Maven - how to work with multiple versions of dependencies?

I have project which used JIRA REST Java Client. It worked fine until I tried to integrate it with Spring Boot. Since that I am not able to invoke createWithBasicHttpAuthentication from AsynchronousJiraRestClientFactory without error. I get:
ClassNotFoundException: org.apache.http.util.Args
So I added HttpComponents Core blocking I/O(httpcore) dependency to my pom.xml, but I after that I got
ClassNotFoundException: org.apache.http.nio.NHttpMessageParserFactory
Which I resolved with adding HttpComponents Core non-blocking I/O(httpcore-nio) to pom.xml. Now I have
NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V
I've compared dependency:tree when project has spring boot parent and when it's commented out. It shown me that adding spring boot parent changes versions of my dependencies. You can check diff here( on left without spring boot, on right with spring boot)
It seems that JIRA REST Java Client need older versions of some dependencies.
How can I solve this problem?
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
...
I was able to fix runtime in my Spring Boot application by overriding these properties in my pom.xml
<properties>
<httpasyncclient.version>4.0-beta3-atlassian-1</httpasyncclient.version>
<httpclient.version>4.2.1-atlassian-2</httpclient.version>
</properties>
Note that there can be other problems if you decide to use http-client and/or httpassync client in your project (eg. using RestTemplate).
Atlassian should definitely upgrade the dependencies.

Which dependencies to create REST services on Tomcat7 (Netbeans project with Maven)

My webapp includes REST web services and is running on GlassFish 3.1.2.
I would like to run this app on Tomcat 7 instead of GlassFish. What dependencies should I add and remove to enable REST services on Tomcat?
(At the moment I just changed "GlassFish" to "Tomcat" in the "Run" menu of Netbeans, but my http requests give a 404.)
Note: this is a Maven project on Netbeans.
Ok here is the list of dependencies you may need. Please note I just put latest version but you may want to use a different version. Please also check for compatibility of these versions with each other.
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
Needed if you are using jackson to parse json
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.3.3</version>
</dependency>
This is what I am using on my tomcat but little bit older versions
Now about your 404
First check if the dependencies fix your problem. 404 may be an issue from some thing not configured right in your web.xml as well.
I hope it helps you solve your problem :)

Resteasy with Google App Engine

I have a working Rest web service that use JBoss Resteasy however when I tried to port it to use GAE I'm getting this error when executing:
java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
I used resteasy successfully on GAE.
As csturtz mentioned make sure your project has the resteasy dependency.
If yo uare using Maven this should be something like:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
</dependency>
And optionally you also would like to use:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-hibernatevalidator-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
it would seem you're missing the Resteasy JAR file in your GAE WAR file. Locate this jar file, add it to your GAE WAR build, and you should be good to go (or at least past this specific error).
Is the resteasy jar file in /war/WEB-INF/lib ? It needs to be copied there AND put on your classpath.

Categories

Resources