Jetty 9:设置处理程序和连接器 [英] Jetty 9: Setting up handlers and connectors

查看:310
本文介绍了Jetty 9:设置处理程序和连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在架构上查看了Jetty 9的文档( http: //www.eclipse.org/jetty/documentation/current/architecture.html )但我仍然对处理程序和连接器之间的关系感到困惑。

I've looked at the documentation for Jetty 9 on the architecture (http://www.eclipse.org/jetty/documentation/current/architecture.html) but I am still confused about the relationship between handlers and connectors.


  1. 你能否将处理程序链接到特定的连接器(如果是这样,怎么样?连接器似乎没有setHandler方法)?

  1. Can you link a handler to a specific connector (if so, how? The connector doesn't seem to have a setHandler method)?

或者一切都去主处理程序,然后你从那里分发东西? (即你找出它来自哪个连接器,然后你将它转发给另一个处理程序或自己处理它)

Or does everything go to a main handler and then you distribute things from there? (i.e. You figure out form what connector it came from so then you forward it to a different handler or handle it yourself)

非常感谢!

推荐答案

连接器是听的组件传入连接。

Connectors are the components that listen for incoming connections.

处理程序是用于处理所有的低级码头机制请求。

Handlers are the low level jetty mechanism used to handle all requests.

Jetty发送所有有效请求(有一类请求只是错误的HTTP使用,可能会导致 400 Bad请求)注册的任何内容> Server.getHandler()

Jetty sends all valid requests (there are a class of requests that are just bad HTTP usage and can result in things like a 400 Bad Request) to whatever is registered at Server.getHandler()

有很多特定于函数的处理程序的类型,选择一个最适合您需求并从中扩展的处理程序,或者围绕一种更通用的方法包装处理程序。

There are many types of function specific handlers, pick one that best suits your needs and extend from it, or wrap your handler around a more generalized approach.

典型的服务器设置为HandlerList或HandlerCollection指示可能的行为列表。

A typical server is setup to have either a HandlerList or HandlerCollection to indicate a list of possible behavior.

每个处理程序是命中(按顺序)并且如果该处理程序决定它想要做某事它可以。

Each handler is hit (in order) and if that handler decides it wants to do something it can.

如果处理程序实际产生了某些东西,那么调用 baseRequest.setHandled(true); 用于告诉Jetty在当前的处理程序之后不再处理任何处理程序。

If a handler actually produced something, then a call to baseRequest.setHandled(true); is used to tell Jetty to not process any more handlers after this current one.

关于如何限制某些连接器的某些处理程序,通过虚拟主机机制完成。

As to how to restrict certain handlers to certain connectors, that's done via the virtualhosts mechanism.

VirtualHosts是一个特定于 ContextHandler 的概念处理程序,因此您需要将自定义处理程序包装在 ContextHandler 中以获得VirtualHosts的好处。

VirtualHosts is a concept baked into the ContextHandler specific handlers, so you'll want to wrap your custom handlers in a ContextHandler to get the benefit of VirtualHosts.

要使用它,您可以使用 Connector.setName(String)命名连接器,然后使用 @ {name} 关于 ContextHandler 的VirtualHosts定义的语法,具体说明只有该命名连接器可用于提供特定的 ContextHandler

To use this, you would name your connector using Connector.setName(String) and then use the @{name} syntax on the VirtualHosts definition of the ContextHandler to specific that only that named connector can be used to serve that specific ContextHandler.

示例:

    ServerConnector httpConnector = new ServerConnector(server);
    httpConnector.setName("unsecured"); // named connector
    httpConnector.setPort(80);

    ContextHandler helloHandler = new ContextHandler();
    helloHandler.setContextPath("/hello");
    helloHandler.setHandler(new HelloHandler("Hello World"));
    helloHandler.setVirtualHosts(new String[]{"@unsecured"});

这篇关于Jetty 9:设置处理程序和连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆