WELD CDI Exception in Glassfish 4 - jackson

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

Related

Azure Keyvault library to Atlassian Confluence plugin pom.xml

I am trying to combine these 2 tutorials - Confluence Hello World Macro & Azure keyvault quick start:
https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-confluence-hello-world-macro/
https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-java?tabs=azure-cli
After having added the 2 Azure dependencies to the pom.xml of the maven project and running atlas-mvn clean package I receive an error message about 3 banned dependencies.
I looked for the newest Azure packages at the maven portal. Then it was reduced to one.
Found Banned Dependency: org.slf4j:slf4j-api:jar:1.7.25
Then I added added exclusions to the dependency section:
This resulted that the build ran successfully, however, the Confluence plugin produces a runtime error:
java.lang.NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
at com.azure.security.keyvault.secrets.SecretClientBuilder.(SecretClientBuilder.java:110)
Can you please help, how can I achieve this?
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.3.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.4.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
error: java.lang.NoClassDefFoundError Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger at com.azure.security.keyvault.secrets.SecretClientBuilder.(SecretClientBuilder.java:110)
The above error indicates that JVM is not able to found org/slf4j/Logger class in your application's path.The simplest reason for this error is the missing Slf4j.jar file.
If the problem is caused due to the missing slf4j.jar file then you can fix it by adding a relevant version of slf4j.jar into your path.
Use the latest version of the jar in which version of the JAR file you should add will depend upon the application.
In Maven , you can also add the following dependency in your pom.xml file to download sl4j.jar
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
Reference:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory - Stack Overflow

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>

CDI error: Ambiguous dependencies trying to inject EntityManager

I'm facing a strange error while trying to deploy my EJB 3.1 application in a JBoss 7.1.1 application server: WELD-001409 Ambiguous dependencies for type [EntityManager] with qualifiers [#Default] at injection point [[parameter 1] of [constructor] #Inject public br.com.sigga.siot.dao.masterdata.impl.ProfileDAOImpl(EntityManager)]. Possible dependencies [[Resource Producer Field [EntityManager] with qualifiers [#Any #Default] declared as [[field] #PersistenceContext #Produces private br.com.sigga.siot.cdi.JPAProducer.entityManager], Resource Producer Field [EntityManager] with qualifiers [#Any #Default] declared as [[field] #PersistenceContext #Produces private br.com.sigga.siot.cdi.JPAProducer.entityManager]]]
As you can see, the "possible dependencies" points twice to the same EntityManager producer: br.com.sigga.siot.cdi.JPAProducer.entityManager. This field is declared as follows:
#PersistenceContext(unitName = "siotMobility")
#Produces
private EntityManager entityManager;
A similar case was related in WELD-001409 Ambiguous dependencies but I cannot change my application server to Glassfish 4.1. :-)
My development environment: Eclipse Luna, Java 7, Maven 3.x (eclipse's embedded version). I have one Maven project (siot-mobility) with 3 modules (siot-mobility-[ear|ejb|web]).
The EAR module's POM declares the following dependencies:
<dependencies>
<dependency>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-web</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
Maven EAR plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-web</artifactId>
</webModule>
<ejbModule>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-ejb</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
Feel free to ask me about any more info that could help you help me. :-) Thanks in advance.
Error found: the EJB module was present twice in the generated EAR, once on the root path of the EAR file and a second time in the WEB-INF/lib folder of the WAR file.
I changed the dependency declaration in the WAR project's POM file from:
<dependency>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-ejb</artifactId>
</dependency>
to:
<dependency>
<groupId>br.com.sigga</groupId>
<artifactId>siot-mobility-ejb</artifactId>
<scope>provided</scope>
</dependency>
This way, the EJB module is not copied to the WEB-INF/lib folder of the WAR file and I have only one EntityManager producer in the generated EAR file.

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.