12

i have a basic setup using spring boot and joinfaces to use primefaces and bootsfaces in my application.

Using for example bootsfaces components and perform ajax calls works like a charm. When i add a simple primefaces component which uses ajax, the call fails and i get the following exception:

    2018-06-01 11:49:22.479 ERROR 11868 --- [nio-8080-exec-2] j.e.r.webcontainer.jsf.application       : Error Rendering View[/datatest-prime.xhtml]

java.lang.IllegalArgumentException: Unrecognized Content Type.
    at com.sun.faces.renderkit.RenderKitImpl.createResponseWriter(RenderKitImpl.java:283) ~[javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1160) ~[javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:438) ~[javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:194) [javax.faces-2.3.4.jar:2.3.4]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:151) [javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:126) [javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) [javax.faces-2.3.4.jar:2.3.4]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223) [javax.faces-2.3.4.jar:2.3.4]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671) [javax.faces-2.3.4.jar:2.3.4]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.28.jar:8.5.28]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]

It does not matter if i just use a button like in this example:

<h:form>
   <p:commandButton value="Add" ajax="true" actionListener="#{pingResultBean.onAction}" />
</h:form>

or using any other primefaces component which fires ajax calls.

I have Spring security enabled and using following configuration:

http
        .authorizeRequests()
            .antMatchers("/login*").permitAll()
            .antMatchers("/logout*").permitAll()
            .antMatchers("/js/**").permitAll()
            .antMatchers("/css/**").permitAll()
            .antMatchers("/javax.faces.resource/**").permitAll()
            .anyRequest().authenticated()
        .and()
            .formLogin()
            .loginPage("/login.xhtml")
            .defaultSuccessUrl("/index.xhtml")
            .failureUrl("/login.xhtml?error=1")
        .and()
            .csrf().disable()
            .logout().logoutSuccessUrl("/login.xhtml?logout");

All other ajax calls are working. Would be nice if someone can help me.

Edited: Same error when i disable spring security.

The bug can easily be reproduces when cloning the official joinfaces starter https://github.com/joinfaces/joinfaces-gradle-jar-example

and add a primefaces button

Roland
  • 184
  • 1
  • 14
TosKen
  • 481
  • 5
  • 20
  • 1
    Sure this is the whole stacktrace? – Kukeltje Jun 01 '18 at 09:26
  • 1
    i have updated the stack trace – TosKen Jun 01 '18 at 09:51
  • can you debug and set a breakpoint and see what the content type actually is? – Kukeltje Jun 01 '18 at 10:25
  • desiredContent is "text/html" but i think should be text/xml because of partial ajax request – TosKen Jun 01 '18 at 10:35
  • The bug can easily be reproduces when cloning the official joinfaces starter https://github.com/joinfaces/joinfaces-gradle-jar-example and add a primefaces button – TosKen Jun 01 '18 at 10:58
  • Sorry, too much work. I want to help narrow down the problem but I'm not going to install/deploy/ full new apps (not a spring user myself) – Kukeltje Jun 01 '18 at 11:15
  • Even with plain JSF 2.3.1 + Primefaces 6.2 this error comes and it has the same fix. – Roland Aug 25 '18 at 20:18
  • There is no primefaces method in the stacktrace. Debug network traffic and find the differences. This does work on a plain non-joinfaces/springboot application. – Kukeltje Aug 26 '18 at 07:13

4 Answers4

27

I have the same setup and the same problem. It was caused by f:view tag in my main template.

<f:view contentType="text/html">

Removing it fixed the problem.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
  • This fix works too for ```` component using jsf .2.2 and primefaces 6. Thanks – TuGordoBello Jul 20 '18 at 15:44
  • 5
    I had the same problem running a stable application with the recently released WildFly 14, and I was also able to fix it removing the contentType of the f:view (the f:view tag remains). – Jorge Campins Sep 04 '18 at 19:15
  • 3
    OMG. Had the same - but needed the f:view for the locale settings. I removed "contentType" and then it worked. Thanks – cljk Mar 05 '19 at 10:33
3

I had a similar problem migrating existing primefaces 6.2 webapp to wildfly 14. My fix is to add process="@this" to all p:menuitem

2

Exactly what Tom Bombadil say! If you had @this at the prossess property it will work! In my case, since I load menus from the database using the DefaultMenuModel, I have this:

DefaultMenuItem mi = new DefaultMenuItem();
mi.setValue(m.getDescription());
mi.setProcess("@this"); //IMPORTANT SINCE WILDFLY 14 - Unrecognized Content Type?!
mi.setIcon("id-icon-param");
if (m.isExecutecommand()) {
  mi.setCommand(m.getCommandinstruction());
} else if (m.isLoadasdialog()) {
  mi.setUrl(m.getViewId());
} 
mi.setUpdate("@form");
submenu.addElement(mi);

Hope it helps!

Inovarium

0

it's enough to removed the contentType attribute:

<f:view>
Tadas B.
  • 176
  • 8