NoSuchMethodError error when using JMS on Websphere 8.5 - java

I have a Java application which is deployed on Websphere 8.5. It gets a message which I am trying to use it but this is the error I get even though I have the right JMS jars on line getBody()
Code Snippet:
if (arg0 instanceof BytesMessage)
{
byte[] payload = arg0.getBody(byte[].class);
myMessage = new String(payload);
}
Jar Files:
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Error from Websphere logs:
Caused by: java.lang.NoSuchMethodError: javax/jms/Message.getBody(Ljava/lang/Class;)Ljava/lang/Object; (loaded from file:/opt/was_static/websphere_8.5.5.15.1/appserver/plugins/javax.j2ee.jms.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader#6d5d04f3) called from class com.mycompany.myapplication.sync.mdb.myapplicationSyncOutboundMDB (loaded from file:/opt/was_static/profiles/appsrv01/installedApps/eaodr01Cell01/myapplication-ear-mydomain.com-editionmyapplication-ear-0.9.6.ear/myapplication-ejb-0.9.6.jar by
com.ibm.ws.classloader.CompoundClassLoader#19abf904[app:myapplication-ear-mydomain.com-editionmyapplication-ear-0.9.6]
Local ClassPath:
Parent: com.ibm.ws.classloader.ExtJarClassLoader#890f8480[PF][server:0]
Delegation Mode: PARENT_FIRST)
Websphere CLassloading:
Any ideas why my application, which compiles fine as it sees javax.jms.Message in the code but the Websphere can't find this?

WebSphere Application Server 8.5.5 supports Java EE 6 which includes JMS 1.1, not JMS 2.0 and the getBody(Class) method was added in JMS 2.0 which is Java EE 7 and newer.
If you want to use JMS 2.0 then you need to upgrade to WebSphere Application Server 9.0.

Related

How do I use an older Keycloak client with Quarkus 2.13, Keycloak 19 client is not backwards compatible with v18 server

Would like to ask how to override the Keycloak version used by the Quarkus 2.13 BOM to Keycloak 18? My quarkus service could not connect to our Keycloak servers which still use v18. I have lost the error message in my logs but it said something about client secret is invalid when using Keycloak v19 client, but when downgrading to v18, there were no issues.
This PR 27387 in Quarkus bumped the Keycloak version and it broke compatibility. I have tried overriding the property <keycloak.version>18.0.2</keycloak.version> in POM but it doesn't work, it keeps using the same dependency org.keycloak:keycloak-core:19.0.2 and I even tried overriding the dependency quarkus-keycloak-authorization like so
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-authorization</artifactId>
<version>2.12.3.Final</version> <!-- last quarkus version that used keycloak 18 -->
</dependency>
but it's still the same thing? I'm using a managed Keycloak server - Cloud IAM (Free tier) so any server upgrades wouldn't be easy. Or are there any alternative configurations I can use with Keycloak to make the client backward compatible, the error I'm encountering is the following during application startup
2022-10-18 06:50:14,785 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile prod):
org.keycloak.authorization.client.util.HttpResponseException: Unexpected response from server:
401 / Unauthorized / Response from server: {"error":"unauthorized_client","error_description":"Invalid client secret"}
at org.keycloak.authorization.client.util.HttpMethod.execute(HttpMethod.java:95)
at org.keycloak.authorization.client.util.HttpMethodResponse$2.execute(HttpMethodResponse.java:50)
I was able to resolve the issue by overriding quarkus bom in pom.xml through <dependencyManagement/> like so, the keycloak pom should be above quarkus for it to override
<dependencyManagement>
<dependencies>
<!-- retain compatibility with keycloak 18 -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-authorization</artifactId>
<!-- last quarkus version that used keycloak 18 -->
<version>2.12.3.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependencies>
</dependencyManagement>
I get a warning during mvn compile though, but as per this Issue #1577, it is intended
[io.quarkus.maven.MavenDevModeLauncher$Builder] io.quarkus:quarkus-bootstrap-maven-
resolver::jar classpath entry C:\Users\Vince\.m2\repository\io\quarkus\quarkus-
bootstrap-maven-resolver\2.13.2.Final\quarkus-bootstrap-maven-resolver-2.13.2.
Final.jar was overriden with C:\Users\Vince\.m2\repository\io\quarkus\
quarkus-bootstrap-maven-resolver\2.12.3.Final\quarkus-bootstrap-maven-resolver-
2.12.3.Final.jar
Hope it can help others that were encountering the same issue, and take a quick read on the PR above, overriding the BOM versions can cause nasty unintended side effects.

Using Spring Data 2.6.1 with Eclipselink and Jakarta 3, is it possible?

We are currently bumping dependency versions of a Spring project with persistence based on JPA with Eclipselink. During the upgrade process I learned about Eclipselink switching to Jakarta namespace starting with version 3.0 due to legal reasons as explained in this thread.
We succeeded in updating the code so that we use Jakarta Persistence API 3.0.0 independently from Spring Data. The migration is quite straight forward:
Bump Eclipselink version to 3.0.x
Add an explicit dependency to Jakarta 3
Replace javax.persistence with jakarta.persistence in the code and in persistence.xml
Now I am looking into configuring Spring Data to use Eclipselink with Jakarta 3.0.0, but I noticed Spring still depends on JAXB 2.2.3. When I override the version in my Maven project, Spring Data complains on startup:
java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory
at org.springframework.data.jpa.util.BeanDefinitionUtils.<clinit>(BeanDefinitionUtils.java:57)
at org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor.postProcessBeanFactory(EntityManagerBeanDefinitionRegistrarPostProcessor.java:72)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:191)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
at com.mycompany.sandbox.springjpaeclipselinkfix.SpringApp.main(SpringApp.java:12)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityManagerFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 18 common frames omitted
Apparently, it tries to create a persistence unit called default and fails to load javax/persistence/EntityManagerFactory (obviously, it is now in the jakarta.persistence package).
My understanding is that Spring Data's code depends on Jakarta 2 and using Jakarta 3 is not supported. However, it should be possible to use Eclipselink as Spring Data persistence provider and Eclipselink does support Jakarta 3. I am puzzled at this point and I cannot find any current examples for this, only old stuff relating to javax.persistence.
Is it possible to configure Spring Data to use Eclipselink 3 and Jakarta 3, or should I stick to the old namespace for now?
And if it's possible, can you point me to some current examples?
Obviously, one could fork Spring Data JPA's code and do the migration but I have not enough resources to maintain a branch.
I am posting also the relevant parts of my pom.xml (the rest resembles a standard Spring Data project):
<project>
...
<properties>
...
<jakarta-persistence.version>3.0.0</jakarta-persistence.version>
<eclipselink.version>3.1.0-M1</eclipselink.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
...
</dependencies>
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink.version}</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta-persistence.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
...
</project>
Other tags: Jakarta EE 9, Jakarta Persistence 3.0, Java 17.
I found the answer in the Spring blog. Apparently the roadmap includes switching to the jakarta namespace "in Q4 2022":
As announced at SpringOne yesterday, Spring Framework 6 and Spring
Boot 3 are planned towards a high-end baseline for their general
availability in Q4 2022:
Java 17+ (from Java 8-17 in the Spring Framework 5.3.x line)
Jakarta EE 9+ (from Java EE 7-8 in the Spring Framework 5.3.x line)
This forward-looking baseline will provide significant benefits in our
API design and integration efforts, shining through to your
application code and future-proofing the framework as well as your
applications for many years to come. However, it comes at a cost, of
course: Spring Framework 6 and Spring Boot 3 based applications will
require a minimum of JDK 17 at runtime, as well as a minimum of Tomcat
10 / Jetty 11 (for Jakarta EE 9 compatibility). Even more importantly,
there might be some changes required in your application source code:
e.g. the javax to jakarta namespace change in Jakarta EE 9 wherever
you’re touching the Servlet API, JPA, Bean Validation, etc.
It is thus a matter of waiting until the change is rolled out by Spring.

Glassfish - java.lang.NoClassDefFoundError: org/primefaces/model/UploadedFile

I have a maven based project. This is how the project looks like in eclipse:
So I have separate front and back end that are packed into one EAR. The application were deployed on Weblogic 12c server but now I have to move it to Glassfish. I can deploy to Glassfish and my application is running. But, i got an error message when I invoke a method which use Primefaces UploadFile class. This is the error message:
java.lang.NoClassDefFoundError: org/primefaces/model/UploadedFile
javax.ejb.EJBException: java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: org/primefaces/model/UploadedFile
This two dependency:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>
Are in both POM.xml (front and back end) And the maven dependency is in my classpath as you can see in this picture:
My question is, where should I put the Primefaces jar, to make visible for Glassfish in runtime?
You'll either need to add the dependencies to the /lib folder of Glassfish as this is where the container will check for them, or bundle them up with the deployable artifact - in your case the .ear file. As you are using maven there are a couple of plugins available that may help you e.g. the Maven Assembly or Maven Ear plugins.
-Answer based on my comment above.

JBoss Wildfly 10: xnio ClassCastException when calling EJB3.1 on JBoss 7

I'm trying to remote call an EJB3.1 application on a JBoss 7 from a Wildfly 10 via JNDI.
Executing the code from a stand alone java client works perfectly well, deployed in the Wildfly, I receive a ClassCastException:
java.lang.ClassCastException: org.xnio.SingleOption cannot be cast to org.xnio.Option
Here are the properties I'm using:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=true
remote.connectionprovider.create.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connections=default
remote.connection.default.host=some.server
remote.connection.default.port=4647
remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED=true
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.clusters=ejbremote.cluster.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.cluster.ejb.connect.options.org.xnio.Options.SSL_ENABLED=true
remote.connection.default.username=user
remote.connection.default.password=password
org.jboss.ejb.client.scoped.context=true
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
Project has the jboss-as-ejb-client-bom dependency:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.2.0.Final</version>
<type>pom</type>
</dependency>
Lookup looks standard:
Context ctx = new InitialContext(properties);
Service service = (Service) ctx.lookup(Service.JNDI_PATH);
Any ideas?
Add an jboss-deployment-structure.xml with the following contents to the top level of your WAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.jboss.xnio"></module>
</dependencies>
</deployment>
</jboss-deployment-structure>
check how you package the application, I suppose that you include the org.xnio libraries in the deployed archives.
In this case it will be loaded by different classloaders that cause this error.

Can't start WebSocket container with Tomcat and Maven's tomcat7-websocket plug-in

I am trying to get a Tomcat server (7.0.54) to support WebSocket and having a hard time deploying it. I have a simple endpoint:
#ServerEndpoint(value = "/test")
public class TestEndpoint {
In order to have this endpoint processed, I need to include a container (which uses ServiceLoader to start, introspect all the classes with endpoint annotations, etc...). I use the following:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat7-websocket</artifactId>
<version>7.0.47</version>
</dependency>
However, mvn tomcat7:run then fails to start with:
SEVERE: Parse error in application web.xml file at jndi:/localhost/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/WEB-INF/web.xml; lineNumber: 13; columnNumber: 12; Error at (13, 12) : org.apache.catalina.deploy.WebXml addFilter
If instead, I specify the scope as system and I point it to my local file system:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat7-websocket</artifactId>
<version>7.0.47</version>
<scope>system</scope>
<systemPath>${somewhere}/tomcat7-websocket-7.0.54.jar</systemPath>
</dependency>
... then everything works fine, but of course, this can't be reliably deployed on a live server.
What can I do to start my WebSocket container properly?
You need to use this dependency and marked it as provided (and not the one coming from org.apache.tomcat never included tomcat dependency as it's all provided by the container). That's similar to servlet-api:
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

Categories