Primefaces push on glassfish 3.1.2 Exception - jsf-2

this is my config.xml
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.0.RC1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.5</version>
</dependency>
web.xml
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
is the counter example, when clic after 3 or 7 then:
WARNING: GRIZZLY0024: Terminate process interrupted.
java.lang.InterruptedException at
java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1325)
at java.util.concurrent.Semaphore.tryAcquire(Semaphore.java:414) at
com.sun.grizzly.http.ProcessorTask.terminateProcess(ProcessorTask.java:1021)
at
com.sun.grizzly.arp.DefaultAsyncExecutor.finishResponse(DefaultAsyncExecutor.java:186)
at
com.sun.grizzly.arp.DefaultAsyncExecutor.finishExecute(DefaultAsyncExecutor.java:210)
at
com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:133)
at
com.sun.grizzly.comet.CometEngine.flushPostExecute(CometEngine.java:426)
at com.sun.grizzly.comet.CometEngine.interrupt0(CometEngine.java:405)
at com.sun.grizzly.comet.CometEngine.interrupt(CometEngine.java:383)
at
com.sun.grizzly.comet.CometContext.resumeCometHandler(CometContext.java:442)
at
org.atmosphere.container.GrizzlyCometSupport.resume(GrizzlyCometSupport.java:172)
at
org.atmosphere.container.GrizzlyCometSupport.action(GrizzlyCometSupport.java:184)
at
org.atmosphere.container.GrizzlyCometSupport.action(GrizzlyCometSupport.java:81)
at
org.atmosphere.cpr.AtmosphereResourceImpl.resume(AtmosphereResourceImpl.java:317)
at
org.atmosphere.handler.AbstractReflectorAtmosphereHandler.onStateChange(AbstractReflectorAtmosphereHandler.java:146)
at
org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:853)
at
org.atmosphere.cpr.DefaultBroadcaster.executeAsyncWrite(DefaultBroadcaster.java:768)
at
org.atmosphere.cpr.DefaultBroadcaster$3.run(DefaultBroadcaster.java:801)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

I haven't tried primefaces-push but I just use Atmosphere (primefaces-push is using Atmosphere too). To make it work I have to add those JVM options:
-Dv3.grizzly.cometSupport=true
-Djava.net.preferIPv4Stack=true (I am not sure if this option is still required with the last versions of Atmosphere)
Maybe it could help you.

Related

NullPointerException during initFaces of a MyFaces 2.0 application while migrating from WLS to Tomcat

I'm new to JSF and have been entrusted with the task of migrating what appears to me as an old MyFaces 2.0 webapp from WebLogic Server 12.1.3 to Tomcat (I chose Tomcat 9 and OpenWebBeans 2.0.20).
I followed the instructions at BalusC's page to integrate OpenWebBeans with Tomcat/webapp since just cdi-api-1.0.jar didn't do the trick.
I am seeing the following exception (please see the full stack trace further down).
20-Jun-2022 19:46:25.718 INFO [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces ServletContext 'C:\apache-tomcat-9.0.63\webapps\app1\' initialized.
20-Jun-2022 19:46:25.767 INFO [main] org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 4.0
20-Jun-2022 19:46:25.802 INFO [main] org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory.getLifecycleProvider Using LifecycleProvider org.apache.myfaces.config.annotation.AllAnnotationLifecycleProvider
20-Jun-2022 19:46:25.808 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.myfaces.application.DefaultResourceHandlerSupport.calculateFacesServletMapping(DefaultResourceHandlerSupport.java:211)
Update #1:
After #tandraschko's suggestion to upgrade MyFaces from 2.0.0 to 2.0.25 & OpenWebBeans from 2.0.20 to 2.0.27, the above exception has evolved as follows:
28-Jun-2022 11:02:58.128 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
Update #2:
After #tandraschko's suggestion to upgrade MyFaces from 2.0.0 to 2.3.10 and add StartupServletContextListener in web.xml, the latest exception is similar to the one above:
28-Jun-2022 12:20:17.674 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
Update #3:
After #tandraschko's suggestion to match my pom.xml with that of the sample project, primefaces-test, there's no exception anymore!
However, launching the app on the browser resulted in the following exceptions being thrown (not related to the original question though):
30-Jun-2022 18:52:23.743 INFO [http-nio-8080-exec-6] org.apache.myfaces.extensions.cdi.jpa.impl.JpaModuleStartupObserver.logJpaModuleConfiguration [Started] MyFaces CODI JPA-Module v1.0.5
30-Jun-2022 18:52:23.781 INFO [http-nio-8080-exec-6] org.apache.myfaces.extensions.cdi.jsf2.impl.Jsf2ModuleStartupObserver.logJsfModuleConfiguration [Started] MyFaces CODI JSF-Module v1.0.5 for JSF 2.0
Used JSF implementation: MyFaces Core v2.3.10
config implementation: org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig
method: isInitialRedirectEnabled
value: true
method: isAlwaysKeepMessages
value: true
method: isUseViewConfigsAsNavigationCasesEnabled
value: true
method: isInvalidValueAwareMessageInterpolatorEnabled
value: true
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig
method: getWindowContextTimeoutInMinutes
value: 60
method: isUnknownWindowIdsAllowed
value: false
method: isCloseWindowContextEventEnabled
value: false
method: getMaxWindowContextCount
value: 64
method: isUrlParameterSupported
value: true
method: isAddWindowIdToActionUrlsEnabled
value: false
method: isCreateWindowContextEventEnabled
value: false
method: isEagerWindowContextDetectionEnabled
value: true
method: isCloseEmptyWindowContextsEnabled
value: false
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig
method: isStartConversationEventEnabled
value: false
method: isConversationRequiredEnabled
value: true
method: isCloseConversationEventEnabled
value: false
method: getConversationTimeoutInMinutes
value: 30
method: isAccessBeanEventEnabled
value: false
method: isUnscopeBeanEventEnabled
value: false
method: isScopeBeanEventEnabled
value: false
method: isRestartConversationEventEnabled
value: false
MessageContextConfig class: org.apache.myfaces.extensions.cdi.message.impl.DefaultMessageContextConfig
MessageInterpolator class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.FacesMessageInterpolator
MessageResolver class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareApplicationMessagesMessageResolver
MessageHandler class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareMessageHandler
LocaleResolver class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareLocaleResolver
FormatterFactory class: class org.apache.myfaces.extensions.cdi.message.impl.DefaultFormatterFactory
18:52:25.189 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception:class javax.faces.FacesException
18:52:25.190 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception component:null
18:52:25.192 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception phaseid:RENDER_RESPONSE(6)
18:52:25.200 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception: attributes{}
After scouring through post after post in SO, I wasn't able to find a similar issue nor any clue to crack my issue.
After decompiling myfaces-impl-2.0.0.jar, it seems that externalContext.getRequestServletPath() is returning null.
The webapp has extension mapping in web.xml (kindly see snippet further down) but I'm not sure if I'm looking at the right suspect.
Exception (Full Stack Trace after Update #2)
28-Jun-2022 12:20:17.674 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
at org.apache.webbeans.jsf.OwbApplication.getExpressionFactory(OwbApplication.java:48)
at org.apache.myfaces.config.ManagedBeanBuilder.coerceToType(ManagedBeanBuilder.java:364)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:347)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:163)
at org.apache.myfaces.webapp.AbstractFacesInitializer._createEagerBeans(AbstractFacesInitializer.java:339)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:218)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4768)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1024)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1911)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:825)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1618)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:946)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Configuration (as deduced & set up accordingly)
MyFaces 2.0
CODI 1.0.5
PrimeFaces 4.0
OpenWebBeans 2.0.20 (CDI 2.0 but beans_1_0 in beans.xml)
Tomcat 9
Java 8
Update 3: No jars were added to Tomcat's lib.
Update 3: The webapp's lib has the following 13 manually-added jars (with my notes against them):
Interestingly, everything works only if the 13 jars are placed in the webapp's lib (WEB-INF\lib) and not in Tomcat's lib!
Are there any recommendations or best practices on how to manage these 13 dependent jars?
commons-digester-1.8.jar
javax.ejb-api-3.2.2.jar
javax.persistence-api-2.2.jar
javax.ws.rs-api-2.0.1.jar
jersey-client-1.18.jar
jersey-core-1.18.jar (provided scope)
jersey-multipart-1.18.jar (provided scope)
jersey-server-1.18.jar (provided scope)
jersey-servlet-1.18.jar (provided scope)
myfaces-api-2.3.10.jar (one of the profile dependencies; should it be added to the POM as mentioned [here][2])
myfaces-impl-2.3.10.jar (one of the profile dependencies; should it be added to the POM as mentioned [here][2])
weblogic.jaxrs.internal.common_1.2.0.0.jar (need to be replaced with another JAX-RS provider?)
weblogic.jaxrs.server_3.0.0.0.jar (need to be replaced with another JAX-RS provider?)
pom.xml (abridged; modified now after years for Update #3)
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TMapp1</groupId>
<artifactId>app1</artifactId>
<version>5.0</version>
<packaging>war</packaging>
<name>TM app1 Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<owb.version>2.0.27</owb.version>
</properties>
<dependencies>
<!-- app1 uses PrimeFaces 4.0 instead of 11.0.0 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>org.primefaces</groupId> -->
<!-- <artifactId>primefaces</artifactId> -->
<!-- <version>11.0.0</version> -->
<!-- </dependency> -->
<!-- javax.* APIs -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.6</version>
</dependency>
<!-- app1 uses 3.1.0 instead of 4.0.1 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>javax.servlet</groupId> -->
<!-- <artifactId>javax.servlet-api</artifactId> -->
<!-- <version>4.0.1</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- app1 uses 2.2.4 instead of 3.0.0 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>javax.el</groupId> -->
<!-- <artifactId>javax.el-api</artifactId> -->
<!-- <version>3.0.0</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- OpenWebBeans -->
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<!-- start of apache-commons -->
<!-- Used by: app1 -->
<dependency>
<groupId<!-- ... -->
</dependency>
<!-- end of apache-commons -->
<dependency>
<!-- Used by: TODO: app1 -->
<groupId>org.apache.myfaces.extensions.cdi.bundles</groupId>
<artifactId>myfaces-extcdi-bundle-jsf20</artifactId>
<version>1.0.5</version>
</dependency>
<!-- primefaces? -->
<!-- Used by: app1 -->
<dependency> <!-- not used at compile time -->
<groupId>org.atmosphere</groupId>
<!-- ... -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<!-- Used by: app1 -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- start of jersey libs -->
<dependency>
<!-- ... -->
</dependency>
<!-- end of jersey libs -->
<dependency>
<!-- Used by: app1 -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>primefaces</id>
<name>PrimeFaces Maven Repository</name>
<url>https://repository.primefaces.org</url>
<layout>default</layout>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<finalName>app1</finalName>
<plugins>
<!-- ... -->
</plugins>
<resources>
<!-- ... -->
</resources>
</build>
<profiles>
<profile>
<id>myfaces22</id>
<!-- ... -->
</profile>
<profile>
<id>myfaces23</id>
<!-- ... -->
</profile>
<profile>
<id>myfaces23next</id>
<!-- ... -->
</profile>
<profile>
<id>coverage</id>
<!-- ... -->
</profile>
</profiles>
</project>
web.xml
I removed what seems to be an old Mojarra remnant (following an error reported during startup):
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
from the web.xml below leaving me with only the 2 newly added listeners, WebBeansConfigurationListener (for OWB) and StartupServletContextListener (since Update #2: explicitly demanded it), in that order. Finally, cleaned it up to match the sample project, primefaces-test (Update #3).
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >
<display-name>app1</display-name>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>casablanca</param-value>
</context-param>
<!-- Enable PostConstruct on JSF ManagedBeans on Jetty (and Tomcat as well?) -->
<context-param>
<param-name>org.apache.myfaces.config.annotation.LifecycleProvider</param-name>
<param-value>org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider</param-value>
</context-param>
<listener>
<listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.company.app1.enterprise.service.health</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/health/*</url-pattern>
</servlet-mapping>
<session-config> <!-- set the default session time out to 60 minutes -->
<session-timeout>60</session-timeout>
<!-- set the Session Cookie as httpOnly -->
<!-- <cookie-config>
<http-only>true</http-only>
</cookie-config> -->
<!-- Added this for SPR HCSDM00273622 - Links to sign up new users not working properly -->
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<filter>
<filter-name>ParameterEscapeFilter</filter-name>
<filter-class>com.company.app1.enterprise.filter.ParameterEscapeFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>ParameterEscapeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>primeFacesFileUploadFilter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>primeFacesFileUploadFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>GzipFilter</filter-name>
<filter-class>com.axeda.qpublic.filter.GZipServletFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>GzipFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<!-- ... -->
</filter-mapping>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<mime-mapping>
<extension>xhtml</extension>
<mime-type>text/xhtml</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
beans.xml (untouched for years)
<?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_0.xsd">
<interceptors>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.security.SecurityInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.listener.phase.ViewControllerInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.CloseConversationGroupInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.config.view.PageParameterInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.config.view.PageParameterListInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jpa.impl.transaction.TransactionalInterceptor</class>
</interceptors>
</beans>
Why not use the latest MyFaces version? There is even a 2.0.24...
EDIT #1 - from the comments
I'd perform the following more steps based on the instructions from user #tandraschko in the comment thread below.
Side Note: I'm grateful to #tandraschko for the timely response & clear instructions.
Upgraded MyFaces version initially from 2.0.20 --> 2.0.24 but later to 2.3.10.
Upgraded OpenWebBeans version from 2.0.20 to 2.0.27.
Added the MyFaces listener StartupServletContextListener AFTER the OpenWebBeans one.
Cleaned up Maven dependencies to include all dependencies in the webapp's WEB-INF\lib (in contrast to a few at the sample which are of scope provided).

Spring Security not working over RestServices

I have a RestController working and I want to learn how to enable Basic Auth with Spring Security.
I've created a class that extends WebSecurityConfigurerAdapter and for what I understand, it should be enough. Sadly I can call the resources without providing credentials.
Here is my code:
Configurer Adapter
package es.ieci.test.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
#Configuration
#EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
public static final String REALM = "TEST_REALM";
#Override
protected void configure(HttpSecurity http) throws Exception{
http
.csrf().disable()
.authorizeRequests().antMatchers("/services/**").hasRole("ADMIN").and()
.httpBasic().realmName(REALM).authenticationEntryPoint(getBasicAuthEntryPoint()).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
#Bean
public CustomBasicAuthenticationEntryPoint getBasicAuthEntryPoint(){
return new CustomBasicAuthenticationEntryPoint();
}
}
Spring Config file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="es.ieci.test.security, es.ieci.test.controller, es.ieci.test.services, es.ieci.test.utils" />
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TestRestSpring</display-name>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
And my pom file
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
I'm using a Tomcat v6.0m and the server logs looks good:
nov 17, 2016 2:00:32 PM
org.springframework.security.web.DefaultSecurityFilterChain
INFORMACIÓN: Creating filter chain:
org.springframework.security.web.util.matcher.AnyRequestMatcher#1,
[org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#f671723,
org.springframework.security.web.context.SecurityContextPersistenceFilter#2b8af779,
org.springframework.security.web.header.HeaderWriterFilter#49d0b86,
org.springframework.security.web.authentication.logout.LogoutFilter#6f7b847c,
org.springframework.security.web.authentication.www.BasicAuthenticationFilter#3b022cae,
org.springframework.security.web.savedrequest.RequestCacheAwareFilter#1eebd4a2,
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#4cb106be,
org.springframework.security.web.authentication.AnonymousAuthenticationFilter#392002bb,
org.springframework.security.web.session.SessionManagementFilter#e13b2fb,
org.springframework.security.web.access.ExceptionTranslationFilter#6b4187ba,
org.springframework.security.web.access.intercept.FilterSecurityInterceptor#241377b6]
But if I call to
http://localhost:8383/TestRestSpring/services/echo
Without providing user credentials the server response is 200 instead of the expected Auth error
I've been able to get 401 code adding a filter to web.xml
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
But I'm not sure if this is the right way.
It seems you missed to add context config file in your web.xml,so component scanning of security configuration is not done.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

JSF + Weld CDI + WebService (over Jetty9) does not work

I just don't get what the big mistake is that I'm doing...
It's just not possible for me to get Weld CDI to work. Before I integrated CDI into my webapp (JSF + PrimeFaces + DB4O + Jersey), everything worked mostly fine.
Since I replaced the #ManagedBean stuff with #Named and so on and did changed my pom for using CDI, Jetty does not start anymore.
SOLVED (see UPDATE #1)
I used ManagedBeans in the past, but needed the CDI for injection withing webservices.
See UPDATE 2 for that.
My project-structure:
My Exception:
org.jboss.weld.exceptions.WeldException: WELD-001524 Unable to load proxy class for bean Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [#Default] with class interface javax.enterpr
ise.inject.Instance using classloader WebAppClassLoader=343602030#147af36e
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:318)
at org.jboss.weld.bean.builtin.AbstractFacadeBean.initializeAfterBeanDiscovery(AbstractFacadeBean.java:60)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:129)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:120)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by:
java.lang.LinkageError: loader constraint violation: loader (instance of org/codehaus/plexus/classworlds/realm/ClassRealm) previously initiated loading for a different type with name "javax/enterpris
e/util/TypeLiteral"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.privateGetPublicMethods(Class.java:2641)
at java.lang.Class.getMethods(Class.java:1457)
at org.jboss.weld.bean.proxy.ProxyFactory.addMethodsFromClass(ProxyFactory.java:523)
at org.jboss.weld.bean.proxy.ProxyFactory.addMethods(ProxyFactory.java:478)
at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:412)
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:311)
at org.jboss.weld.bean.builtin.AbstractFacadeBean.initializeAfterBeanDiscovery(AbstractFacadeBean.java:60)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:129)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:120)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is the project descriptor for the examples of my components -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>DB4O-webapp</artifactId>
<packaging>war</packaging>
<name>DB4O-Web</name>
<parent>
<groupId>DB4O-Test</groupId>
<artifactId>DB4O-Test-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.db4o</groupId>
<artifactId>db4o-full-java5</artifactId>
<version>8.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.0.3.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.0.4.v20130625</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<!-- Repository for jstl 1.2 -->
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
<repository>
<id>db4o-repo</id>
<url>http://source.db4o.com/maven/</url>
<layout>default</layout>
</repository>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<finalName>DB4O-Test</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.4.v20130625</version>
<configuration>
<!--option>weld</option-->
<scanIntervalSeconds>2</scanIntervalSeconds>
<reload>automatic</reload>
<webApp>
<contextPath>/${project.build.finalName}</contextPath>
</webApp>
<jettyXml>src/main/webapp/WEB-INF/jetty-env.xml</jettyXml>
<contextXml>src/main/webapp/WEB-INF/jetty-context.xml</contextXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<description>debug web.xml</description>
<context-param>
<description>State saving method: "client" or "server" (= default)
See JSF Specification 2.5.3
</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<!--listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.mypackage.guide.ws</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
My beans.xml:
<?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_0.xsd">
</beans>
My jetty-config.xml:
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>org.eclipse.jetty.servlet.ServletContextHandler.Decorator</Item>
</Array>
</Set>
</Configure>
My jetty-env.xml:
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>
<Ref id="webAppCtx" />
</Arg>
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg />
</New>
</Arg>
</New>
</Configure>
Example class:
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import de.mypackage.guide.model.Device;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.core.MediaType;
import java.io.Serializable;
import java.util.Collection;
/**
* Created with IntelliJ IDEA.
* Date: 08.08.13
* Time: 08:21
*/
#Named
#RequestScoped
public class DeviceService implements Serializable {
#Inject
private DatabaseService databaseService;
public DeviceService() {}
#PostConstruct
public void init() {
}
public void sendDevice() {
Client create = Client.create();
WebResource service = create.resource( "http://localhost:8080/ws" );
System.out.println( service.path( "register" ).path( "device" ).path( "meinDevice" )
.type( MediaType.TEXT_PLAIN ).put(String.class) );
}
public Collection<Device> getAllDevices() {
return this.databaseService.retrieveAll(Device.class);
}
public DatabaseService getDatabaseService() {
return databaseService;
}
public void setDatabaseService(DatabaseService databaseService) {
this.databaseService = databaseService;
}
public Device getDevice(String deviceName) {
return this.databaseService.retrieveFiltered(Device.class, "regId", deviceName).toArray(new Device[0])[0];
}
public void saveDevice(Device device) {
this.databaseService.store(device);
}
}
Thanks in advance for any help!
UPDATE #1:
After solving my exception above by following the commentary below the first answer from John Ament, I have another problem.
Now I get a NPE. Seems that my service won't get injected at all. By reading my log output it says that CDI support is enabled, so maybe it's some configuration (beans.xml etc.) problem?
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
at de.mypackage.guide.ws.RegistrationService.device(RegistrationService.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:258)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)
2013-08-09 07:52:43.853:WARN:oejs.ServletHandler:qtp1061696789-23: /ws/register/device/meinDevice
java.lang.NullPointerException
at de.mypackage.guide.ws.RegistrationService.device(RegistrationService.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:258)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)
UPDATE #2
I checked the injection within the services and they work (getting some test-output from another service), so the problem lies within the webservice <---> CDI stuff.
Could there be a problem with the different contexts of cdi, webservices and jsf?
#Path("/register")
public class RegistrationService {
#Inject
private DeviceService deviceService;
#GET
#Produces( MediaType.TEXT_PLAIN )
#Path("/get/{device}")
public String getDevice(#PathParam("device") String device) {
return this.deviceService.getDevice(device).getRegId();
}
#PUT
#Path( "/device/{device}" )
#Consumes( MediaType.TEXT_PLAIN )
#Produces( MediaType.TEXT_PLAIN )
public String device(#PathParam("device") String device) {
this.deviceService.saveDevice(new Device(device));
System.out.println("Erfolgreich!");
return "Device: " + device;
}
public DeviceService getDeviceService() {
return deviceService;
}
public void setDeviceService(DeviceService deviceService) {
this.deviceService = deviceService;
}
}
Which Maven version are you using? 3.1?? I had the same problem when trying to run my app through jetty:run goal (maven-jetty-plugin 9.x) and Maven 3.1. I've just revert my Maven to 3.0.x version and now it goes well.
It looks like the api jars for CDI aren't being loaded, you have them as provided which excludes them from runtime.

java.lang.IllegalAccessError: tried to access class com.sun.faces.context.ApplicationMap

i ve a jsf application which works fine on eclipse with tomcat 7. The problem happened when i packaged it (with mvn package..) and put the .war file in the tomcat webapps directory to deploy it.
in the tomcat console i got :
SEVERE: Error listenerStart
Nov 2, 2012 12:38:09 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/jsf_prime_ldap] startup failed due to previous errors
Nov 2, 2012 12:38:09 AM org.apache.catalina.loader.WebappClassLoader checkThread
LocalMapForLeaks
SEVERE: The web application [/jsf_prime_ldap] created a ThreadLocal with key of
type [com.sun.faces.config.ConfigureListener$1] (value [com.sun.faces.config.Con
figureListener$1#6972f1]) and a value of type [com.sun.faces.config.ConfigureLis
tener.ServletContextAdapter] (value [com.sun.faces.config.ConfigureListener$Serv
letContextAdapter#18fee4f]) but failed to remove it when the web application was
stopped. Threads are going to be renewed over time to try and avoid a probable
memory leak.
for more details about this problem, in the localhost's tomcat log file i have :
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.IllegalAccessError: tried to access class com.sun.faces.context.ApplicationMap from class com.sun.faces.config.InitFacesContext$ServletContextAdapter
at com.sun.faces.config.InitFacesContext$ServletContextAdapter.getApplicationMap(InitFacesContext.java:331)
at javax.faces.FactoryFinder$FactoryManagerCacheKey.<init>(FactoryFinder.java:850)
at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:719)
at javax.faces.FactoryFinder$FactoryManagerCache.access$100(FactoryFinder.java:691)
at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:373)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:666)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:417)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:348)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Nov 2, 2012 12:38:09 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.IllegalAccessError: com/sun/faces/context/ApplicationMap
at com.sun.faces.config.InitFacesContext$ServletContextAdapter.getApplicationMap(InitFacesContext.java:331)
at javax.faces.FactoryFinder$FactoryManagerCacheKey.<init>(FactoryFinder.java:850)
at javax.faces.FactoryFinder$FactoryManagerCache.removeApplicationFactoryManager(FactoryFinder.java:810)
at javax.faces.FactoryFinder.releaseFactories(FactoryFinder.java:395)
at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:378)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
in the tomcat lib directory i have added these jars :
commons-beanutils-1.8.3/
commons-collections-3.2.1/
commons-digester-1.5/
commons-logging-1.1.1/
el-impl-2.2/
jsf-api-2.1.11/
jsf-impl-2.1.11/
jsp-api-2.1/jstl-1.2/
primefaces-3.4.1
The application's pom file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsfprimeldap</groupId>
<artifactId>jsf_prime_ldap</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jsf_prime_ldap Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4.1</version>
</dependency>
<!-- JSF 2 -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<!-- EL -->
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.1_02</version>
</dependency>
<!-- Tomcat 6 need this <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId>
<version>1.0</version> </dependency> -->
</dependencies>
<build>
<finalName>jsf_prime_ldap</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
and my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsf_prime_ldap</display-name>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
i didn't find any similar problem in google.. i wish to find the solution for this problem here.
thanks for help
in the tomcat lib directory i have added these jars : commons-beanutils-1.8.3/ commons-collections-3.2.1/ commons-digester-1.5/ commons-logging-1.1.1/ el-impl-2.2/ jsf-api-2.1.11/ jsf-impl-2.1.11/ jsp-api-2.1/jstl-1.2/ primefaces-3.4.1
Undo this step. Reinstall Tomcat altogether if you're uncertain. Do not ever touch it unless you really understand what you're doing. This is the cause of the whole problem. The classpath has become a messup and the duplicate JARs/classes are conflicting each other.
Webapp-specific JARs doesn't belong in there. They belong in /WEB-INF/lib, expect of the EL and JSP JARs; Tomcat has as being a JSP/Servlet/EL container already its own implementations for this. You should not put JSP/Servlet/EL libraries of a different container make/version in the classpath at all.
Technically, at least the both JSF JARs, the JSTL JAR and the PrimeFaces JAR should be in /WEB-INF/lib. However, as you're using Maven, it should already have taken care about this. You don't need to do anything regard this. So all you need to do is to free Tomcat from illegal JARs/classes.

JSF2 on Jetty gives randomly 'zip file closed' but works when running from maven jetty plugin (jetty:run)

my JSF web app is giving randomly error: "zip file closed" when accessing files (like images, css, js). It is deployed on Jetty 7. It looks like some of those files are not loaded (some images are missing on a page).
java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:403)
at java.util.zip.ZipFile.entries(ZipFile.java:298)
at java.util.jar.JarFile.entries(JarFile.java:217)
at org.eclipse.jetty.util.resource.JarFileResource.list(JarFileResource.java:261)
at org.eclipse.jetty.util.resource.ResourceCollection.list(ResourceCollection.java:421)
at org.eclipse.jetty.util.resource.Resource.getListHTML(Resource.java:509)
at org.eclipse.jetty.servlet.DefaultServlet.sendDirectory(DefaultServlet.java:741)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:564)
When I run it from maven plugin (7.x) with jetty:run or jetty:run-war then I do not get any error.
What's more, accessing root path of web context gives that "zip file closed" error only when running on standalone jetty, but no such error when running from maven pluging, then is those directory view.
My web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
pom.xml:
....
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
....
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.5.1.v20110908</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
</plugin>
Any idea what could it be?
This issue has been fixed in jetty-7.6.0.RC2. The bug is caused by the JVM caching jar url connection streams.
According to the bug report, you will need to also add the following to the jetty.xml:
<Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>
Jetty looks for your resources in the jar files in WEB-INF/lib. When it searches jsf-impl.jar it is somehow closed, probably by a JSF request. Perhaps jsf does its own resource handling and messes about with the files itself.
Anyway, the solution seems to be to move the jsf jars out of the war-file. Set your jsf dependency scope to provided so maven does not package them in the war file, and get them on the server, probably in the lib folder in jetty standalone.
I had the same issue and managed to solve it by going to etc\webdefault.xml and changing this param to false:
<init-param>
<param-name>gzip</param-name>
<param-value>true</param-value>
</init-param>

Resources