1

spring 4.3.6, jsf 2.2.14, primefaces 6.1, jetty 9.4.4.

When I send too big picture from Primefaces' textEditor to the Jetty server, there is [WARNING] in the log received from the Jetty: org.eclipse.jetty.http.BadMessageException: 400: Unable to parse form content. How can I inform client user about the problem?

Following are my 5 attempts, how I tried to solve it:

1) I tried to add validation into view.xhtml:

<p:textEditor id="questionEditor" value="#{manageQuestionsMB.text}" width="950" height="300" style="margin-bottom:10px">
    <f:validateLength maximum="10" />
</p:textEditor>
<p:commandButton value="Save" actionListener="#{manageQuestionsMB.save()}" style="margin-top:10px;" />

The above validation works if textEditor contains characters only, but no picture. (textEditor represents pictures as <img src="data:image/jpeg;base64, ... >).

2) I tried to add validator:

<p:textEditor id="questionEditor" validator="#{manageQuestionsMB.validate()}" value="#{manageQuestionsMB.text}" width="950" height="300" style="margin-bottom:10px">
</p:textEditor>

In case of big picture, no validate(), no save() methods are called. Just the warning from Jetty in log.

3) I tried to add ExceptionHandler to faces-config.xml

<application>
 <el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
</application>
<factory>
 <exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>

With code in view.xhtml

<p:ajaxExceptionHandler type="java.lang.BadMessageException" update="exceptionDialog" onexception="PF('exceptionDialog').show();" />

<p:dialog header="Content" widgetVar="exceptionDialog" >
  <p:outputPanel id="display">
    <h:outputText value="#{pfExceptionHandler.type}" escape="false" />
    <h:outputText value="#{pfExceptionHandler.message}" escape="false" />
    <h:outputText value="#{pfExceptionHandler.formattedStackTrace}" escape="false" />
  </p:outputPanel>
</p:dialog>

No exception caught. Just the warning from Jetty in log.

4) I tried to implement CustomExceptionHandler extends ExceptionHandlerWrapper and to add it into faces-config.xml

<factory>
      <exception-handler-factory>
        online_tests.CustomExceptionHandlerFactory
   </exception-handler-factory>
</factory>

In case of big picture, no handle() method was called. Just the warning from Jetty in log.

5) I tried to implement ErrorHandler as is described here How do I suppress Jetty 8's default ErrorHandler?

In this case I am able to process request attribute and receive

Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception");

I can see, that the cause of the exception was

Caused by: java.lang.IllegalStateException: Form too large: 185992 > 100000
    at org.eclipse.jetty.server.Request.extractFormParameters(Request.java:516) ~[jetty-server-9.4.4.v20170414.jar:9.4.4.v20170414]

but still, I am not sure, how to inform client user about the problem.

Martin
  • 11
  • 2

0 Answers0