2

我正在使用 Jetty 9 运行 SolR。它运行良好。

我有以下配置:1 个 Web 服务器(IIS),1 个 solr 服务器(Jetty)。

为了优化带宽使用,我想在这两个服务器之间启用 GZIP 压缩。

我试图将其添加到jetty/etc/webdefault.xml

<filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
    <init-param>
      <param-name>mimeTypes</param-name>
      <param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,application/json,image/svg+xml</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

我收到以下错误:

2013-06-19 11:16:19.534:WARN:oejuc.AbstractLifeCycle:main: FAILED GzipFilter: javax.servlet.UnavailableException: org.eclipse.jetty.servlets.GzipFilter
javax.servlet.UnavailableException: org.eclipse.jetty.servlets.GzipFilter
    at org.eclipse.jetty.servlet.Holder.doStart(Holder.java:108)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:91)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:743)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:279)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1312)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:722)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:490)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:274)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:193)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.updateBeans(ContainerLifeCycle.java:713)
    at org.eclipse.jetty.server.handler.HandlerCollection.setHandlers(HandlerCollection.java:89)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.setHandlers(ContextHandlerCollection.java:165)
    at org.eclipse.jetty.server.handler.HandlerCollection.addHandler(HandlerCollection.java:155)
    at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:41)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:495)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:175)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:600)
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:145)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:557)
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:232)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
    at org.eclipse.jetty.server.Server.start(Server.java:346)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
    at org.eclipse.jetty.server.Server.doStart(Server.java:294)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1233)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:453)
    at org.eclipse.jetty.start.Main.start(Main.java:595)
    at org.eclipse.jetty.start.Main.main(Main.java:96)
2013-06-19 11:16:19.534:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@3dada196{/,file:/E:/Solr/jetty-9/webapps/ROOT/,STARTING}{E:\Solr\jetty-9\webapps\ROOT}
javax.servlet.UnavailableException: org.eclipse.jetty.servlets.GzipFilter
    at org.eclipse.jetty.servlet.Holder.doStart(Holder.java:108)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:91)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:743)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:279)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1312)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:722)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:490)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:274)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:193)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.updateBeans(ContainerLifeCycle.java:713)
    at org.eclipse.jetty.server.handler.HandlerCollection.setHandlers(HandlerCollection.java:89)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.setHandlers(ContextHandlerCollection.java:165)
    at org.eclipse.jetty.server.handler.HandlerCollection.addHandler(HandlerCollection.java:155)
    at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:41)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:495)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:175)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:600)
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:145)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:557)
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:232)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
    at org.eclipse.jetty.server.Server.start(Server.java:346)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
    at org.eclipse.jetty.server.Server.doStart(Server.java:294)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1233)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:453)
    at org.eclipse.jetty.start.Main.start(Main.java:595)
    at org.eclipse.jetty.start.Main.main(Main.java:96)

有人有想法吗?

4

2 回答 2

8

通常,您将 GzipFilter 添加到您的 web 应用程序WEB-INF/web.xml并将其包含jetty-servlets.jar在您的WEB-INF/lib目录中。

但是,可以将其配置在顶级码头服务器级别。

对于初学者,您收到的错误表明您的服务器类路径中不存在 jetty-servlets.jar。

要对此进行测试,请从您的 jetty-distribution 独立运行以下命令。

$ java -jar start.jar --version

Active Options: [Server, annotations, client, ext, jaas, jmx, jndi, jndi.demo, jsp, plus, resources, rewrite, websocket]
Version Information on 36 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the OPTIONS=[option,option,...] command line option will be reflected here.
 0:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-xml-9.0.3.v20130506.jar
 1:  3.0.0.v201112011016 | ${jetty.home}/lib/servlet-api-3.0.jar
 2:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-http-9.0.3.v20130506.jar
 3:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-continuation-9.0.3.v20130506.jar
 4:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-server-9.0.3.v20130506.jar
 5:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-security-9.0.3.v20130506.jar
 6:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-servlet-9.0.3.v20130506.jar
 7:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-webapp-9.0.3.v20130506.jar
 8:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-deploy-9.0.3.v20130506.jar
 9:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-annotations-9.0.3.v20130506.jar
10:  1.1.0.v201108011116 | ${jetty.home}/lib/annotations/javax.annotation-1.1.0.v201108011116.jar
11:  3.1.0.v200803061910 | ${jetty.home}/lib/annotations/org.objectweb.asm-3.1.0.v200803061910.jar
12:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-client-9.0.3.v20130506.jar
13:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jaas-9.0.3.v20130506.jar
14:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jmx-9.0.3.v20130506.jar
15:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jndi-9.0.3.v20130506.jar
16:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-plus-9.0.3.v20130506.jar
17:  1.1.0.v201105071233 | ${jetty.home}/lib/jndi/javax.activation-1.1.0.v201105071233.jar
18:  1.4.1.v201005082020 | ${jetty.home}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar
19:                1.1.1 | ${jetty.home}/lib/jndi/javax.transaction-1.1.1.v201105210645.jar
20:      9.0.3.v20130506 | ${jetty.home}/lib/jndi.demo/test-mock-resources-9.0.3.v20130506.jar
21:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/com.sun.el-2.2.0.v201303151357.jar
22:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/javax.el-2.2.0.v201303151357.jar
23:  1.2.0.v201105211821 | ${jetty.home}/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
24:  2.2.0.v201112011158 | ${jetty.home}/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar
25:  2.2.2.v201112011158 | ${jetty.home}/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar
26:  1.2.0.v201112081803 | ${jetty.home}/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
27: 3.8.2.v20130121-145325 | ${jetty.home}/lib/jsp/org.eclipse.jdt.core-3.8.2.v20130121.jar
28:                (dir) | ${jetty.home}/resources
29:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-rewrite-9.0.3.v20130506.jar
30:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-api-9.0.3.v20130506.jar
31:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-common-9.0.3.v20130506.jar
32:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-server-9.0.3.v20130506.jar
33:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-servlet-9.0.3.v20130506.jar
34:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-util-9.0.3.v20130506.jar
35:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-io-9.0.3.v20130506.jar

这将向您显示服务器类路径,如您所见,标准发行版jetty-servlets.jar默认情况下不可用。然而,start.config包含在其中的 start.jar有一个预定义OPTIONservlets

注意:要查看OPTIONS可用的列表,请运行

$ java -jar start.jar --list-options

注意:查看start.config正在start.jar使用的。

$ java -jar start.jar --list-config

最后,要使用这些信息,我们可以简单地servlets OPTION通过编辑start.ini.

$ echo "OPTIONS=servlets" >> start.ini 

$ java -jar start.jar --version
Active Options: [Server, annotations, client, ext, jaas, jmx, jndi, jndi.demo, jsp, plus, resources, rewrite, servlets, websocket]
Version Information on 37 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the OPTIONS=[option,option,...] command line option will be reflected here.
 0:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-xml-9.0.3.v20130506.jar
 1:  3.0.0.v201112011016 | ${jetty.home}/lib/servlet-api-3.0.jar
 2:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-http-9.0.3.v20130506.jar
 3:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-continuation-9.0.3.v20130506.jar
 4:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-server-9.0.3.v20130506.jar
 5:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-security-9.0.3.v20130506.jar
 6:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-servlet-9.0.3.v20130506.jar
 7:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-webapp-9.0.3.v20130506.jar
 8:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-deploy-9.0.3.v20130506.jar
 9:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-annotations-9.0.3.v20130506.jar
10:  1.1.0.v201108011116 | ${jetty.home}/lib/annotations/javax.annotation-1.1.0.v201108011116.jar
11:  3.1.0.v200803061910 | ${jetty.home}/lib/annotations/org.objectweb.asm-3.1.0.v200803061910.jar
12:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-client-9.0.3.v20130506.jar
13:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jaas-9.0.3.v20130506.jar
14:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jmx-9.0.3.v20130506.jar
15:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-jndi-9.0.3.v20130506.jar
16:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-plus-9.0.3.v20130506.jar
17:  1.1.0.v201105071233 | ${jetty.home}/lib/jndi/javax.activation-1.1.0.v201105071233.jar
18:  1.4.1.v201005082020 | ${jetty.home}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar
19:                1.1.1 | ${jetty.home}/lib/jndi/javax.transaction-1.1.1.v201105210645.jar
20:      9.0.3.v20130506 | ${jetty.home}/lib/jndi.demo/test-mock-resources-9.0.3.v20130506.jar
21:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/com.sun.el-2.2.0.v201303151357.jar
22:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/javax.el-2.2.0.v201303151357.jar
23:  1.2.0.v201105211821 | ${jetty.home}/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
24:  2.2.0.v201112011158 | ${jetty.home}/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar
25:  2.2.2.v201112011158 | ${jetty.home}/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar
26:  1.2.0.v201112081803 | ${jetty.home}/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
27: 3.8.2.v20130121-145325 | ${jetty.home}/lib/jsp/org.eclipse.jdt.core-3.8.2.v20130121.jar
28:                (dir) | ${jetty.home}/resources
29:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-rewrite-9.0.3.v20130506.jar
30:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-servlets-9.0.3.v20130506.jar
31:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-api-9.0.3.v20130506.jar
32:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-common-9.0.3.v20130506.jar
33:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-server-9.0.3.v20130506.jar
34:      9.0.3.v20130506 | ${jetty.home}/lib/websocket/websocket-servlet-9.0.3.v20130506.jar
35:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-util-9.0.3.v20130506.jar
36:      9.0.3.v20130506 | ${jetty.home}/lib/jetty-io-9.0.3.v20130506.jar

此时您可以看到它jetty-servlets.jar现在在服务器端可用。(上面我的输出中的条目 #30)

于 2013-06-19T18:29:05.747 回答
0

对于任何寻找帖子请求未压缩的答案的人;默认情况下,只有 GET 请求会被过滤器压缩。添加

    <init-param>
        <param-name>methods</param-name>
        <param-value>GET,POST</param-value>
    </init-param>

压缩 POST。

于 2014-09-18T12:11:00.673 回答