我最近将我的数据和文件存储移植到了我开始真正喜欢的 Mongodb。我现在有一个看起来很奇怪的问题。
当我的应用程序尝试从 GridFS 为用户写入图像时,Tomohawk 中的文件扩展过滤器似乎正在拦截。我只希望过滤器支持我的文件上传 - 当系统将图像推送给用户时它不应该处于活动状态。关于如何阻止它拦截这些文件的任何想法都会非常有帮助。
更多细节:
我使用 Tomohawk 文件上传,并在我的 web.xml 中启用了扩展过滤器,以便使用它。我在 RichFaces MediaOutput 控件中显示图像,该控件提供了一个输出流,您可以将媒体字节流写入该输出流。当我将图像存储为文件或在 MySql 中时,一切正常。
现在我正在使用 GridFSDBFile writeTo: OutputStream 方法将我的图像写入 RichFaces MediaOutput 控件。当我尝试显示我的图像时,文件扩展过滤器似乎拦截了它,然后 Tomcat 抛出了 TokenMgrException。
我只希望过滤器支持我的文件上传 - 当系统将图像推送给用户时它不应该处于活动状态。关于如何阻止它拦截这些文件的任何想法都会非常有帮助。
这是错误:
Oct 16, 2012 2:17:29 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/ilearn] threw exception [Servlet execution threw an exception] with root cause
org.apache.tomcat.util.http.parser.TokenMgrError: Lexical error at line 1, column 1. Encountered: "{" (123), after : ""
at org.apache.tomcat.util.http.parser.HttpParserTokenManager.getNextToken(HttpParserTokenManager.java:434)
at org.apache.tomcat.util.http.parser.HttpParser.jj_consume_token(HttpParser.java:267)
at org.apache.tomcat.util.http.parser.HttpParser.Type(HttpParser.java:64)
at org.apache.tomcat.util.http.parser.HttpParser.MediaType(HttpParser.java:16)
at org.apache.catalina.connector.Response.setContentType(Response.java:806)
at org.apache.catalina.connector.Response.checkSpecialHeader(Response.java:1140)
at org.apache.catalina.connector.Response.setHeader(Response.java:1460)
at org.apache.catalina.connector.ResponseFacade.setHeader(ResponseFacade.java:535)
at com.sun.faces.context.ExternalContextImpl.setResponseHeader(ExternalContextImpl.java:777)
at javax.faces.context.ExternalContextWrapper.setResponseHeader(ExternalContextWrapper.java:717)
at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:211)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)
at org.apache.myfaces.custom.captcha.CAPTCHAResourceHandlerWrapper.handleResourceRequest(CAPTCHAResourceHandlerWrapper.java:208)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
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:662)
这是我的 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>iLearn</display-name>
<welcome-file-list>
<welcome-file>index.jsf</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>*.jsf</url-pattern>
</servlet-mapping>
<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>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>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/beans.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>ruby</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<filter-name>AccessFilter</filter-name>
<filter-class>com.iLearn.security.AccessFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AccessFilter</filter-name>
<url-pattern>/restricted/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Extensions Filter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<description>
Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<description>
Set the threshold size - files below this limit are stored
in memory, files above this limit are stored on disk.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
<init-param>
<description>
Set the path where the intermediary files will be stored.
</description>
<param-name>uploadRepositoryPath</param-name>
<param-value>/iLearnData/temp/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Extensions Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>