[英]Jetty: How to configure DoSFilter parameters using JMX
I have set up a DoSFilter for my webapp and have deployed it in Jetty. 我已经为我的web应用程序设置了DoSFilter并将其部署在Jetty中。 Things works nicely.
一切正常。 However I occasionally want to change the Filter configuration.
但是我偶尔想更改过滤器配置。 To do that I always have to change the web.xml and redeploy the webapps which is rather inconvenient.
为此,我总是必须更改web.xml并重新部署webapp,这非常不方便。 I would want to do this dynamically instead.
我想动态地做到这一点。
I learned that I can configure QoSFilter and DoSFilter using JMX since they are exposed as MBeans inside Jetty. 我了解到可以使用JMX配置QoSFilter和DoSFilter,因为它们在Jetty中作为MBean公开。 I am having trouble in doing the same.
我在做同样的事情时遇到了麻烦。
So far, I have been able to do the following: 到目前为止,我已经能够执行以下操作:
<filter> <filter-name>DoSFilter</filter-name> <filter-class>org.eclipse.jetty.servlets.DoSFilter</filter-class> <init-param> <param-name>maxRequestsPerSec</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>requestPort</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>maxRequestMs</param-name> <param-value>600000</param-value> </init-param> <init-param> <param-name>excludePatterns</param-name> <param-value>/healthCheck</param-value> </init-param> <init-param> <param-name>managedAttr</param-name> <param-value>true</param-value> </init-param> </filter>
The managedAttr param is set to true so that this filter is added to the ServletContext thereby exposing it as a MBean. ManagedAttr参数设置为true,以便将此过滤器添加到ServletContext中,从而将其公开为MBean。
3 I've also added a context param asking jetty to make DoSFilter as a MBean as follows 3我还添加了一个上下文参数,要求码头将DoSFilter制作为MBean,如下所示
<context-param> <param-name>org.eclipse.jetty.server.context.ManagedAttributes</param-name> <param-value>DoSFilter</param-value> </context-param>
Now this works, but not the way I want it to. 现在这有效,但不是我想要的方式。 When I open Jconsole and go to the MBeans tab I can see the DoSFilter under org.eclipse.jetty.servlets.DoSFilter.
当我打开Jconsole并转到MBeans选项卡时,可以在org.eclipse.jetty.servlets.DoSFilter下看到DoSFilter。
When I move down the tree, however, I can only see metadata information of that MBean. 但是,当我向下移动树时,只能看到该MBean的元数据信息。 There are no attributes or operations attached to that MBean and I can't change anything.
没有任何属性或操作附加到该MBean,并且我无法更改任何内容。
Please advise. 请指教。 Am I doing anything wrong here?
我在这里做错什么吗?
My webapp is a spring application and there is only one servlet defined 我的webapp是一个spring应用程序,仅定义了一个servlet
<servlet> <servlet-name>capture</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Thanks 谢谢
UPDATE: I tried configuring this in Embedded Jetty and things seem to work fine. 更新:我尝试在Embedded Jetty中配置它,但看起来一切正常。 But I still can't get this to work in a standalone deployment.
但是我仍然无法在独立部署中使用它。
Following is how I tested embedded Server 以下是我测试嵌入式服务器的方式
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new ServerConnector(server);
server.addConnector(connector);
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
server.addBean(mbeanContainer);
WebAppContext context = new WebAppContext(server,"/home/neo/ideaprojects/helloworld/src/main/webapp/", "/");
DoSFilter filter = new DoSFilter();
FilterHolder holder = new FilterHolder(filter);
String name = "DosFilter";
holder.setName(name);
holder.setInitParameter("managedAttr", "true");
context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.FORWARD));
// ----------------------------------------
server.start();
server.join();
}
Updated 更新
I see the following debug logs in jetty standalone mode
2014-04-05 20:18:32.834:DBUG:oejj.MBeanContainer:main: beanAdded o.e.j.w.WebAppContext@ace3c1b{/,file:/tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-6506776307143437350.dir/webapp/,STARTING}{/ROOT.war}->org.eclipse.jetty.servlets.DoSFilter@6d4d63ba
2014-04-05 20:18:32.835:DBUG:oejj.ObjectMBean:main: ObjectMbean: mbeanFor org.eclipse.jetty.servlets.DoSFilter@6d4d63ba mClass=class org.eclipse.jetty.jmx.ObjectMBean
2014-04-05 20:18:32.835:DBUG:oejj.ObjectMBean:main: mbeanFor org.eclipse.jetty.servlets.DoSFilter@6d4d63ba is org.eclipse.jetty.jmx.ObjectMBean@34bb5def
2014-04-05 20:18:32.835:DBUG:oejj.ObjectMBean:main: No MBean Influence for DoSFilter
2014-04-05 20:18:32.835:DBUG:oejj.ObjectMBean:main: No MBean Influence for Object
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: No MBean Influence for Filter
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Influence Count: 3
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: No @ManagedObject declared on class org.eclipse.jetty.servlets.DoSFilter
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Influenced by: org.eclipse.jetty.servlets.DoSFilter
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Annotations not found for: org.eclipse.jetty.servlets.DoSFilter
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Influenced by: java.lang.Object
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Annotations not found for: java.lang.Object
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Influenced by: javax.servlet.Filter
2014-04-05 20:18:32.836:DBUG:oejj.ObjectMBean:main: Annotations not found for: javax.servlet.Filter
2014-04-05 20:18:32.836:DBUG:oejj.MBeanContainer:main: Registered org.eclipse.jetty.servlets:context=ROOT,type=dosfilter,id=0
I found the issue. 我发现了问题。 The issue was with the jars I believe.
我相信问题出在罐子里。 I extended the DOSFilter to replace some headers before the check so I had to include the servlets jar in my webapp.
我扩展了DOSFilter以在检查之前替换一些标头,因此我不得不在我的webapp中包含servlet jar。 I had a whole bunch of other jetty-*.jar in my WEB-INF/lib folder as well(for some other debug purporse) which somehow were creating conflicts.
我的WEB-INF / lib文件夹中还有很多其他jetty-*。jar(用于其他调试目的),这在某种程度上造成了冲突。 The webapp was a maven project so I added provided to all jetty based modules in my webapp so that these jars don't get packed into my deployable war.
该webapp是一个maven项目,因此我在我的webapp中添加了对所有基于码头的模块的提供,这样这些jar就不会陷入我的可部署战争中。 This solved the problem.
这样就解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.