Upgrading my weld-servlet dependency from 1.1 to 2.2.9 .. common error shows up - cdi

I'm getting started with some CDI stuff (coming from a Spring background.) I'm following some war examples online and they typically use an older dependency of weld-servlet such as 1.1.10.Final.
When I use this dependency my sample app works just fine [Tomcat 7]. However, when I try to upgrade to 2.2.9.Final, I end up getting startup error:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserTransaction with qualifiers #Default
This happens only when I upgrade.
Currently in this simple webapp I have a single beans.xml file located under WEB-INF (although I also tried adding an extra one under META-INF as well.)
Any ideas what I might be be doing wrong.
It just seems so odd that it works fine under 1.1 but not 2.2 ?
My beans.xml I've tried defining two ways (not sure which one is better.. I've seen both)
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated"
>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_1.xsd">
</beans>

Related

How to set elementFormDefault when publising a javax.jws.WebService in JBoss EAP 7

I've just switched my webapp from Weblogic 10.3.6 to JBoss EAP 7.3 and it tourns out that when asking for wsdl once the app is deployed the wsdl is generated with elementFormDefault="unqualified" :
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://business.fornitori.infogroup.it/"
elementFormDefault="unqualified"
targetNamespace="http://business.fornitori.infogroup.it/"
version="1.0">
where the same WS deployed on WebLogic doesn't appear.
This cause the error at runtime :
SEVERE [com.sun.xml.messaging.saaj.soap.impl] (default task-7) SAAJ0131: HeaderElements must be namespace qualified
does any one runned into this error and knows how to solve it ?
I've tryied switching from Jaxws-rt 2.1.7 to Jaxws-rt 2.2.8 but didn't sole the problem

JSF faces flow throws the error "Flow already exists"

My environment:
JSF 2.3, Mojarra 2.3.9.payara-p2
PrimeFaces 7.0
Payara 5.192
OmniFaces 3.3
Project Java EE 8 Maven
NetBeans 11.1
I have created a Faces flow:
folder "flotTransfer" containing only 2 files (for the moment) flotTransfert-flow.xml and flotTransfert.xhtml.
I can't deploy the application. I receive this message:
"
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.IllegalStateException: Flow with id "flotTransfert" and definingDocumentId "" already exists.|#]
".
I don't understand why I get this error (why "already exists"?). No other application deployed on the server.
The content of flotTransfert-flow.xml:
<faces-config version="2.3"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">
<flow-definition id="flotTransfert">
<flow-return id="sortieFlot">
<from-outcome>/listeComptes</from-outcome>
</flow-return>
</flow-definition>
</faces-config>
If I rename this file, no more error and the application is deployed on the server but, obviously, the faces flow does not work.
If I keep the file but remove all the content of the file (I comment out all the lines), I get the same error.
I have almost the same faces flow (just more pages in the folder) in another application but with Java EE 7 and Payara 5.184 and without OmniFaces and the flow works.
Sorry, I made a mistake: I added the file flotTransfert-flow.xml with a wizard of my IDE and I didn't notice that this wizard added a <context-param> in the file web.xml, referencing the definition file of the flow. If I remove this <context-param>, all is working.
The lines I removed from web.xml:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/flotTransfert/flotTransfert-flow.xml</param-value>
</context-param>

Changing faces-config.xml from 2.2 to 2.3 causes javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null

Have the following code snippets:
Bean:
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named(value = "directoryBean")
#ViewScoped
public class DirectoryBean implements Serializable {
private static final long serialVersionUID = 1L;
....
}
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
....
</faces-config>
group.xhtml
<ui:composition ...>
<f:metadata>
<f:viewParam name="id" value="#{directoryBean.id}" />
</f:metadata>
</ui:composition>
In result getting the exception:
javax.el.PropertyNotFoundException: /group.xhtml #6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
Got it after changing faces-config.xml from ver 2.2 to ver 2.3 syntax.
Meaning, with faces-config.xml with the following content everything works fine:
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
....
</faces-config>
JSF 2.3.2 deployed on the Payara 4.1.2.172 (Full) server, and also added to pom.xml with "provided" scope.
....
<dependencies>
...
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
...
</dependencies>
....
I have checked all solutions that I was able to find during several hours, including different version of beans.xml:
initially beans.xml was not present in the project - issue
persist;
added empty beans.xml - issue persist;
added beans.xml with two different options of bean-discovery-mode - "all"
and "annotated" - issue persist;
Content of \WEB-INF\beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
Tested on local instances of Payara 4.1.2.172, GlassFish 5 (java ver 1.8.0_144), and remote instance of Payara 4.1.2.172 (java ver 1.8.0_131).
Thanks!
Note: Example projects like this one https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23InjectInConverterValidator give the same error.
===
Update as of 2022-03-31:
Got another error related to this issue on Payara 5.2022.1:
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type UIViewRoot with qualifiers #Default
So seems even on the latest version of Payara JSF 2.3 is not enabled by default, as was mentioned in one of the comments below.
Adding it here for better searching visibility. :)
I would like to post a complete solution, what should be done in order to make JSF 2.3 libs work in JSF v2.3 mode. Code samples below are based on GlassFish 5.0 server environment.
1) Upgrade JSF libs to the version 2.3.3 at least (it fixes some bugs related to jsf 2.3 mode activation)
2) The beans.xml should look like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all" version="2.0">
</beans>
3) faces-config.xml should look like:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">
....
</faces-config>
4) And the key-player in all this setup - is specially formed Java class that actually activates JSF 2.3 mode, in my case it has name Jsf23Activator and absolutely empty content:
package ua.local.beans;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;
#ApplicationScoped
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class Jsf23Activator {
}
The annotation #FacesConfig(version = FacesConfig.Version.JSF_2_3) is added once per project, no need to add it several times.
Basically the need to add this annotation was mentioned several times by others, but in my case it didn't work until I declared this class as CDI bean by adding annotation #ApplicationScoped. Only after I declared the class as CDI bean, cleared project / restarted server - the JSF 2.3 mode finally got activated and now I am able to inject JSF classes / utilize other JSF 2.3 features!
I had this problem because after the update of JSF i still had this jar in my classpath :
el-impl-2.1.2.jar
After deleting this one the problem went away.
in DirectoryBean add this line:
// Activates CDI build-in beans
#FacesConfig(
version = JSF_2_3
)
and in beans.xml change bean-discovery-mode to "all". faces-config.xml set version 2.3
Solution 2:
switch to Payara 5.183, it works out of the box. No need for solution 1: Jsf23Activator

can't customize tomcat7 404 error page

I am trying to customize tomcat7 error page. I need global settings for all the context paths, so I've end up with the configuration inside global /etc/tomcat/web.xml file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<error-page>
<error-code>404</error-code>
<location>/custom-pages/error.jsp</location>
</error-page>
Tomcat succeeds in returning the page when I ask it:
curl -s 127.0.0.1:8080/custom-pages/error.jsp
<html><body>Sorry, the page you requested were not found.</html></body>
However when I request some page which does not exist I get a default error page comes with tomcat, but not the my one:
curl 127.0.0.1:8080/not-exist
<html><head><title>Error report</title></head>
<body><h1>HTTP Status 404 - /not-exist</h1></body>
</html>
Here is the layout of tomcat web directories:
tree /usr/share/tomcat7/webapps/
/usr/share/tomcat7/webapps/
└── ROOT
└── custom-pages
└── error.jsp
And the content of custom error page:
cat /usr/share/tomcat7/webapps/ROOT/custom-pages/error.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html><body>Sorry, the page you requested were not found.</body></html>
Any ideas? Thanks in advance.
Well, meanwhile I have found the answer. I had to comment org.apache.catalina.valves.ErrorReportValve directive inside /etc/tomcat7/context.xml and it did the trick. Looks like this directive "overrides" any custom error pages! Hopefully will be useful for others ... :
<!--
<Valve className="org.apache.catalina.valves.ErrorReportValve"
showReport="false" showServerInfo="false" />
-->

OmniFaces complains about missing CDI and empty beans.xml

I like to add omnifaces to my tomcat8 webapp but omnifaces seems to complain either about a missing CDI implementation or about not being able to parse beans.xml (some SAXParserException). Currently I have the following libraries under WEB-INF/lib:
BootsFaces-OSP-0.8.1-dist-default.jar
cdi-api-1.2.jar
javax.el-api-3.0.1-b04.jar
javax.inject-1.jar
javax.interceptor-api-1.2.jar
jsf-api-2.2.11.jar
jsf-impl-2.2.11.jar
jstl-1.2.jar
omnifaces-2.2.jar
primefaces-5.3.jar
weld-core-2.3.3.Final.jar
weld-servlet-2.3.3.Final.jar
weld-servlet-core-2.3.3.Final.jar
Currently I have two issues with this setup:
a real emtpy beans.xml leads to the "nope, please install CDI" error
the following "empty" beans.xml leads to a "cannot parse beans.xml" error
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org /xml/ns/javaee/beans_1_2.xsd"
bean-discovery-mode="annotated"></beans>
The documentation how to install CDI is from 2013 which is kind of outdated in my eyes.
What is wrong or missing in my setup and where to read on how to get omnifaces running in tomcat8?

Resources