Glassfish4 Jersey 2.22. CDI1x ClassCastException - glassfish

Please consider the following issue.
While trying to deploy my simple REST application on GlassFish 4.1.1 (Java EE 7 Full Platform) I get the error specified below . My application comprises glassfish-web.xml for configuring class loading delegation so as application uses it's own jersey bundle which is version 2.22
The error I get is the following:
[2016-03-28T13:30:58.035-0400] [glassfish 4.1] [SEVERE] [] [javax.enterprise.web] [tid: _ThreadID=43 _ThreadName=admin-listener(3)] [timeMillis: 1459186258035] [levelValue: 1000] [[
WebModule[/device-backend]Servlet /device-backend threw load() exception
java.lang.ClassCastException: Cannot cast org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionInterceptorProvider to org.glassfish.jersey.server.spi.ComponentProvider
at java.lang.Class.cast(Class.java:3186)
Jersey dependency from pom are as follows:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.22</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.22</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
Without glassfish-web.xml everything deploys fine.

Related

Mule: Error creating bean with name 'Secure_Property_Placeholder':

I am trying to use Secure Property Placeholder in mavenized project.
downloaded 1.3.3 secure property connector in anypoint.
loaded 1.3.3 maven dependency in pom.xml
<dependency>
<groupId>com.mulesoft.security</groupId>
<artifactId>mule-module-security-property-placeholder</artifactId>
<version>1.3.3</version>
</dependency>
still getting below error:
Caused by: org.mule.api.lifecycle.InitialisationException: Error creating bean with name 'Secure_Property_Placeholder': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/mule/security/encryption/MuleEncryptionException
what should i do?
That looks like an old version of the artifact.
Try using this instead:
<dependency>
<groupId>com.mulesoft.security</groupId>
<artifactId>mule-module-security-property-placeholder</artifactId>
<version>1.6.0</version>
</dependency>
Can you check if by adding the following dependencies to your POM file, the issue gets resolved?
`<dependency>
<groupId>com.mulesoft.security</groupId>
<artifactId>security-api</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk16</artifactId>
<version>1.45</version>
</dependency>
<dependency>
<groupId>com.mulesoft.security</groupId>
<artifactId>mule-module-security-encryption</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.mulesoft.security</groupId>
<artifactId>mule-module-security-property-placeholder</artifactId>
<version>1.4.0</version>
</dependency>`

jax-rs ClientBuilder in MobileFirst adapter on IBM Liberty

My goal is to use the jax-rs client to connect to a back-end inside the MobileFirst Java adapter, but I'm really stuck and need help.
The code that throws the exception:
javax.ws.rs.client.Client client = javax.ws.rs.client.ClientBuilder.newClient();
The Exception that was thrown:
java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder`
The code is inside the Java adapter on MobileFirst server version 8.0 deployed on IBM Liberty server.
jaxrsClient-2.0 and jaxrs-2.0 features are enabled in the server feature manager in server.xml.
<feature>jaxrs-2.0</feature>
<feature>jaxrsClient-2.0</feature>
The application class is loaded configured like this:
<application id="mfp" name="mfp" location="mfp-server.war" type="war">
<classloader delegation="parentLast" apiTypeVisibility="spec, ibm-api, third-party"></classloader>
</application>
Here is the exception trace:
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at
...............................
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:929)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1018)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at com.ibm.mfp.server.core.shared.ParentLastClassLoader.findClass(ParentLastClassLoader.java:192)
at com.ibm.mfp.server.core.shared.ParentLastClassLoader.loadClass(ParentLastClassLoader.java:165)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:113)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:206)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
... 69 more
Please, help!
I was working on a similar requirement, I did try out a number of combinations before resolving the exception.
I am not sure why liberty is not providing with client implementation classes..
you could try including jersey-client through maven pom.xml..
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.6.1</version>
</dependency>
In Server.xml remove the features
<feature>jaxrs-2.0</feature>
<feature>jaxrsClient-2.0</feature>
and just add below feature.
<feature>beanValidation-1.1</feature>
Liberty IS providing a client implementation, but the parentLast classloader delegation is preventing it from being used.
It would appear that MobileFirst is packaging Jersey, in which case, the Liberty's JAX-RS features should be disabled so that Jersey is used instead. This may require you to change how dependencies are declared in the maven/gradle artifacts.
This looks like a bug in WebSphere Liberty that was fixed in 16.0.0.4. If the classes that are creating a new instance of the JAX-RS client is packaged in an OSGi bundle (either in an OSGi application or as part of a Liberty feature), then the JAX-RS client runtime cannot find the META-INF/services file that specifies Liberty's JAX-RS client implementation class (based on CXF) -- and so the JAX-RS runtime will fall back to the Jersey implementation, which won't be found unless you package it with your app.
The fix for this issue is described here. Basically, Liberty makes the META-INF/services file available to OSGi bundles.
The fix from Suresh worked. I just needed to add more dependencies in my pom.xml though. I don't think I need Moxy here.. will optimize further.
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-core</artifactId>
<version>2.5.0-b61</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>2.5.0-b42</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>

WELD CDI Exception in Glassfish 4

i want to deploy an jax-rs 2.0 (jersey 2.0) webservice to my glassfish 4, but i get an weld CDI exception.
I have no beans.xml in my project.
SEVERE: Undeployment failed for context /restExample
SEVERE: Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [#Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] #Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [#Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] #Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:325)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:177)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:208)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:519)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:505)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:480)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:536)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:216)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
My pom.xml
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
If i set the dependencies to scope provided, i get no exception but than i have no massageBodyWriter etc. in my project/webservice and get then an exception.
I try to exclude the guava
Any ideas?
EDIT: On my notebook i dont get that exception and found the reason: If i use JDK 7_21 i dont get weld-exception, but with JDL 7_25 the glassfish throws the exception!!!
With the actual JDK 7_40 the same result!
If you can, please upgrade Guava to version 16.0.1, which removed the #Inject and #Singleton annotation. That should work, at least for me. Good luck.
I had same problem and solved it by manualy adding dependencies using the actual jar files from GF4 modules folder. seems maven version is not the same as GF4 version.
now for me com.fasterXML is a problem seems GF4 does not support it

How to use httpclient 4.1.x with Maven

httpclient version 4.0 works in my pom.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0</version>
</dependency>
...but versions > 4.0 don't compile:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1</version>
</dependency>
The error:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: unknown:httpclient
Reason: Parent: null:httpmime:jar:null of project: unknown:httpclient has wrong
packaging: jar. Must be 'pom'. for project unknown:httpclient
Any idea how to use httpclient 4.1 with Maven?
confirmed, use Maven 3.0.x and it works! here is example from working pom.xml
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
</dependencies>
I just tried same configurations
jar got downloaded from following location which is one of default repos
http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1
Just try after mentioning http://repo1.maven.org/maven2 explicitly in your pom file
and try using command line
and apache http client 4.1.1 version is also available now
It was a Maven issue: Using Maven 3.0.3 instead of 2.2.1 solved the problem.

Do I need to install glassfish server to use it as embedded server in application?

I am trying to use glassfish as a embedded server in my ejb3.1 project.
below are my maven dependencies..
But when I run my tests it fails to deploy ejb modules.
do I need to set javaee.home or some more variable ?
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1-SNAPSHOT</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>3.1-SNAPSHOT</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
The exception is..
Caused by: org.omg.CORBA.DATA_CONVERSION: vmcid: SUN minor code: 214 completed: No
.
.
.
Caused by: java.lang.IllegalStateException: java.lang.RuntimeException: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key iiop.cannot_find_keyalias
No. even you dont need glassfish-embedded-static-shell.jar.
If you want to use EJB3.1 only glassfish-embedded-all jar is enough.
If you want to access jpa data sources from ejb3 then you need a domain.xml file in classpath.
You will need to pass property "org.glassfish.ejb.embedded.glassfish.installation.root" while creating a EJB container in client code.(like EJBContainer.createEJBContainer(prop)). value of this property should be a folder name (ex. glassfish).
The folder should have domains\domain1\config\domain.xml file.
You can download and install glassfish v3 and from installation you can copy this file.