Apache Camel - 16 - Jetty组件

Apache Camel Jetty组件使用场景,貌似就是发布Http服务...

Jetty Component

参考资料:

http://camel.apache.org/jetty.html

 

Apache Camel相关代码已经上传GitHub,需要的自取:GitHub - Apache Camel 完整Demo

如果觉得还行,麻烦点个Star

 

The producer is deprecated - do not use. We only recommend using jetty as consumer (eg from jetty)

生产者被弃用 - 不要使用。 我们只推荐使用jetty作为消费者(例如 from jetty)

这个是啥意思呢?我的理解是:

不要将jetty端点作为客户端(生产者)使用...

推荐jetty作为服务端(消费者)使用....

 

The jetty component provides HTTP-based endpoints for consuming and producing HTTP requests. 

That is, the Jetty component behaves as a simple Web server. 

Jetty can also be used as an HTTP client which mean you can also use it with Camel as a producer.

jetty组件提供基于HTTP的端点来消费和生成HTTP请求。 

也就是说,Jetty组件的行为如同一个简单的Web服务器。

Jetty也可以用作HTTP客户端,这意味着您也可以将其与Camel一起用作生产者。

 

Stream

The assert call appears in this example, because the code is part of an unit test. 

Jetty is stream based, which means the input it receives is submitted to Camel as a stream. 

That means you will only be able to read the content of the stream once.

在这个例子中出现断言调用,因为代码是单元测试的一部分。 

Jetty是基于流的,这意味着它接收到的输入被作为一个流提交给Camel。

这意味着您将只能读取一次流的内容。

 

If you find a situation where the message body appears to be empty or you need to access the Exchange.HTTP_RESPONSE_CODE data multiple times, e.g., doing multi-casting, or re-delivery error handling, you should use Stream caching or convert the message body to a String which is safe to be re-read multiple times.

如果您发现邮件正文显示为空的情况,或者您需要多次访问Exchange.HTTP_RESPONSE_CODE数据(例如,进行多播或重传错误处理),则应使用流缓存或转换邮件正文 到一个可以多次重读的安全字符串。

 

URI Format

jetty:http://hostname[:port][/resourceUri][?options]

Query options should be appended to the URI using the following format: ?option=value&option=value&...

查询选项应使用以下格式附加到URI:?option=value&option = value&...

 

Options

Option

Default Value

Description

bridgeEndpoint

false

Camel 2.1: If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back.

如果选项是真的,HttpProducer将忽略Exchange.HTTP_URI头,并使用端点的URI的请求。

您也可以将throwExceptionOnFailure设置为false,让HttpProducer将所有错误响应发送回去。

 

Camel 2.3: If the option is true, HttpProducer and CamelServletwill skip the gzip processing if the Content-Encoding is gzip.

如果选项为true,如果Content-Encoding是gzip,则HttpProducer和CamelServlet将跳过gzip处理。

 

Consider setting disableStreamCache=true to optimize when bridging.

考虑设置disableStreamCache = true来优化桥接。

chunked

true

Camel 2.2: If this option is false Jetty Servlet will disable the HTTP streaming and set the Content-Length header on the response

如果这个选项是false的,Jetty Servlet将禁用HTTP流,并在响应中设置Content-Length头

continuationTimeout

null

Camel 2.6: Allows to set a timeout in milliseconds when using Jetty as consumer (server). By default Jetty uses 30000. You can use a value of <= 0 to never expire. If a timeout occurs then the request will be expired and Jetty will return back an HTTP error 503 to the client.

当使用Jetty作为使用者(服务器)时,允许设置以毫秒为单位的超时。 默认情况下,Jetty使用30000.您可以使用<= 0的值永不过期。 如果发生超时,则请求将过期,Jetty将向客户端返回HTTP错误503。

 

This option is only in use when using Jetty with the Asynchronous Routing Engine.

此选项仅在与异步路由引擎一起使用Jetty时使用。

cookieHandler

null

Camel 2.19: Producer only Configure a cookie handler to maintain a HTTP session.

disableStreamCache

false

Camel 2.3: Determines whether or not the raw input stream from Jetty is cached or not (Camel will read the stream into a in memory/overflow to file, Stream caching) cache. By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However, you can set this option to true when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store. 

确定来自Jetty的原始输入流是否被缓存(Camel将读取流内存/溢出到文件,流缓存)缓存。 默认情况下,Camel会缓存Jetty输入流以支持多次读取,以确保Camel可以从流中检索所有数据。 但是,例如,当您需要访问原始流时,可以将此选项设置为true,例如将其直接流式传输到文件或其他持久性存储。

 

DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is falseto support reading the stream multiple times. If you use Jetty to bridge/proxy an endpoint then consider enabling this option to improve performance, in case you do not need to read the message payload multiple times.

DefaultHttpBinding会将请求输入流复制到流缓存中,并将其放入消息体中,如果该选项为false,则支持多次读取流。 如果您使用Jetty桥接/代理端点,则考虑启用此选项以提高性能,以防万一您不需要多次读取消息负载。

enableCORS

false

Camel 2.15: if the option is true, Jetty server will setup the CrossOriginFilter which supports the CORS out of box.

如果选项为true,则Jetty服务器将设置支持CORS的CrossOriginFilter.

enableJmx

false

Camel 2.3: If this option is true, Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.

如果这个选项是真的,Jetty JMX支持将被启用这个端点。 请参阅Jetty JMX支持以获取更多详细信息。

enablemulti-partFilter

true

Camel 2.5: Whether Jetty org.eclipse.jetty.servlets.multi-partFilter is enabled or not.

Set this option to false when bridging endpoints, to ensure multi-part requests is proxied/bridged as well.

是否启用Jetty org.eclipse.jetty.servlets.multi-partFilter。

在桥接端点时将此选项设置为false,以确保多部分请求也被代理/桥接。

filterInit.xxx

null

Camel 2.17: Configuration for the InitParameters of filter.

For example, setting filterInit.parameter=value the parameter could be used when calling the filter init() method.

过滤器InitParameters的配置。

例如,设置filterInit.parameter = value时,可以在调用过滤器init()方法时使用该参数。

filtersRef

null

Camel 2.9: Allows using a custom filters which is putted into a list and can be find in the Registry

允许使用一个自定义的过滤器放入列表中,并可以在注册表中找到

handlers

null

Specifies a comma-delimited set of org.mortbay.jetty.Handlerinstances in your Registry (such as your Spring ApplicationContext). These handlers are added to the Jetty Servlet context (for example, to add security).

在您的注册表中指定一个以逗号分隔的org.mortbay.jetty.Handlerinstances集合(例如您的Spring ApplicationContext)。 这些处理程序被添加到Jetty Servlet上下文中(例如,添加安全性)。

Note: you can not use different handlers with different Jetty endpoints using the same port number. The handlers is associated to the port number. If you need different handlers, then use different port numbers.

注意:不能使用具有不同Jetty端点的不同处理程序使用相同的端口号。 处理程序与端口号关联。 如果您需要不同的处理程序,则使用不同的端口号。

headerFilterStrategy

null

Camel 2.11: Reference to a instance of org.apache.camel.spi.HeaderFilterStrategy in the Registry. It will be used to apply the custom headerFilterStrategy on the new create HttpJettyEndpoint.

引用注册表中的org.apache.camel.spi.HeaderFilterStrategy实例。 它将用于在新创建的HttpJettyEndpoint上应用自定义headerFilterStrategy。

httpBindingRef

null

Reference to an org.apache.camel.component.http.HttpBinding in the Registry. HttpBinding can be used to customize how a response should be written for the consumer.

引用注册表中的org.apache.camel.component.http.HttpBinding。 HttpBinding可以用来定制如何为消费者写一个响应。

httpClient.xxx

null

Configuration of Jetty's HttpClient. For example, setting httpClient.idleTimeout=30000 sets the idle timeout to 30 seconds. And httpClient.timeout=30000 sets the request timeout to 30seconds, in case you want to timeout sooner if you have long running request/response calls.

Jetty的HttpClient的配置。 例如,设置httpClient.idleTimeout = 30000可将空闲超时设置为30秒。 而且httpClient.timeout = 30000会将请求超时设置为30秒,以防万一长时间运行请求/响应调用时您希望超时。

httpClient

null

To use a shared org.eclipse.jetty.client.HttpClient for all producers created by this endpoint. This option should only be used in special circumstances.

对由此端点创建的所有生产者使用共享的org.eclipse.jetty.client.HttpClient。 这个选项只能在特殊情况下使用。

httpClientMinThreads

null

Camel 2.11: Producer only: To set a value for minimum number of threads in HttpClient thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. If not set it default to min 8 threads used in Jetty's thread pool.

仅生产者:为HttpClient线程池中最小线程数设置一个值。 此设置会覆盖在组件级别配置的任何设置。 请注意,必须配置最小和最大尺寸。 如果没有设置它默认为在Jetty线程池中使用的最小8线程。

httpClientMaxThreads

null

Camel 2.11: Producer only: To set a value for maximum number of threads in HttpClient thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. If not set it default to max 16threads used in Jetty's thread pool.

仅生产者:为HttpClient线程池中的最大线程数设置一个值。 此设置会覆盖在组件级别配置的任何设置。 请注意,必须配置最小和最大尺寸。 如果没有设置它默认为Jetty线程池中使用的最大16线程。

httpMethodRestrict

null

Camel 2.11: Consumer only: Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. From Camel 2.15: multiple methods can be specified separated by comma.

仅用于消费者:用于只允许在HttpMethod匹配时使用,比如GET / POST / PUT等。从Camel2.15:可以用逗号分隔多个方法。

jettyHttpBindingRef

null

Camel 2.6.0+: Reference to an org.apache.camel.component.jetty.JettyHttpBinding in the Registry. JettyHttpBinding can be used to customize how a response should be written for the producer.

引用注册表中的org.apache.camel.component.jetty.JettyHttpBinding。 JettyHttpBinding可以用来定制如何为生产者写一个响应。

matchOnUriPrefix

false

Whether or not the CamelServlet should try to find a target consumer by matching the URI prefix if no exact match is found.

如果找不到完全匹配,则CamelServlet是否应通过匹配URI前缀来尝试查找目标使用者。

See here How do I let Jetty match wildcards.

multi-partFilterRef

null

Camel 2.6: Allows using a custom multi-part filter.

Note: setting multi-partFilterRef forces the value of enablemulti-partFilter to true.

允许使用自定义的多部分过滤器。

注意:设置multi-partFilterRef强制enablemulti-partFilter的值为true。

okStatusCodeRange

200-299

Camel 2.16: Producer only The status codes which is considered a success response. The values are inclusive. The range must be defined as from-to with the dash included.

仅生产者被认为是成功响应的状态码。 价值是包容性的。 范围必须被定义为从 - 到包含短划线。

optionsEnabled

false

Camel 2.17: Specifies whether to enable HTTP OPTIONS for this Jetty consumer. By default OPTIONS is turned off.

指定是否为此Jetty使用者启用HTTP OPTIONS。 默认情况下,OPTIONS被关闭。

proxyHost

null

Camel 2.11: Producer only The HTTP proxy Host URL which will be used by Jetty client.

仅生产者Jetty客户端将使用的HTTP代理主机URL。

proxyPort

null

Camel 2.11: Producer only The HTTP proxy port which will be used by Jetty client.

仅生产者Jetty客户端将使用的HTTP代理端口。

responseBufferSize

null

Camel 2.12: To use a custom buffer size on the javax.servlet.ServletResponse.

在javax.servlet.ServletResponse上使用自定义缓冲区大小。

sendDateHeader

false

Camel 2.14: if the option is true, jetty server will send the date header to the client which sends the request.

Note: ensure that there are no any other camel-jetty endpoints that share the same port, otherwise this option may not work as expected.

如果选项为true,则码头服务器将发送日期标题给发送请求的客户端。

注意:确保没有任何其他骆驼码头共享相同的端口,否则此选项可能无法正常工作。

sendServerVersion

true

Camel 2.13: if the option is true, jetty will send the server header with the jetty version information to the client which sends the request.

Note: ensure that there are no any other camel-jetty endpoints that share the same port, otherwise this option may not work as expected.

如果选项为true,则jetty将发送带有码头版本信息的服务器头到发送请求的客户端。

注意:确保没有任何其他骆驼码头共享相同的端口,否则此选项可能无法正常工作。

sessionSupport

false

Specifies whether to enable the session manager on the server side of Jetty.

指定是否启用Jetty服务器端的会话管理器。

sslContextParameters

null

Camel 2.17: Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry.  This reference overrides any configured SSLContextParameters at the component level.   

引用注册表中的org.apache.camel.util.jsse.SSLContextParameters。 此引用将覆盖组件级别的任何已配置的SSLContextParameters。

See Using the JSSE Configuration Utility.

sslContextParametersRef

null

Camel 2.8: Deprecated Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry.  This reference overrides any configured SSLContextParameters at the component level. 

不推荐参考注册表中的org.apache.camel.util.jsse.SSLContextParameters。 此引用将覆盖组件级别的任何已配置的SSLContextParameters。

See Using the JSSE Configuration Utility.

throwExceptionOnFailure

true

Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. This allows you to get all responses regardless of the HTTP status code.

选项可以禁止在远程服务器响应失败的情况下抛出HttpOperationFailedException。 这使您可以获取所有的响应,而不管HTTP状态码如何。

traceEnabled

false

Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off.

指定是否为此Jetty使用者启用HTTP TRACE。 默认情况下TRACE被关闭。

transferException

false

Camel 2.6: If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type.

On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized.

如果已启用,并且客户端上的Exchange处理失败,并且引发的异常是作为application / x-java-serialized-object内容类型在响应中发回的。

在生产者方面,异常将被反序列化并抛出,而不是HttpOperationFailedException。 引起的异常需要被序列化。

urlRewrite

null

Camel 2.11: Producer only Refers to a custom org.apache.camel.component.http.UrlRewrite which allows you to rewrite URLs when you bridge/proxy endpoints.

仅生产者引用自定义org.apache.camel.component.http.UrlRewrite,它允许您在桥接/代理端点时重写URL

See more details at UrlRewrite and How to use Camel as a HTTP proxy between a client and server.

useContinuation

true

Camel 2.6: Whether or not to use Jetty continuations for the Jetty Server.
是否对Jetty服务器使用Jetty延续。

Message Headers

Camel uses the same message headers as the HTTP component. 

Camel使用与HTTP组件相同的消息头。

From Camel 2.2, it also uses (Exchange.HTTP_CHUNKED, CamelHttpChunked) header to toggle chunked encoding on the camel-jetty consumer. 

从Camel 2.2开始,它还使用(Exchange.HTTP_CHUNKED,CamelHttpChunked)标题在骆驼码头消费者上切换分块编码。

Camel also populates all request.parameter and request.headers. 

Camel也填充所有request.parameter和request.headers。

For example, given a client request with the URL, http://myserver/myserver?orderid=123, the exchange will contain a header named orderid with the value 123.

例如,如果客户端请求的URL是http://myserver/myserver?orderid=123,则交换将包含一个名为orderid的标头,其值为123。

From Camel 2.2.0: you can get the request.parameter from the message header not only from GET HTTP Method, but also other HTTP method.

从Camel 2.2.0开始:您可以从消息头获取request.parameter,不仅可以从GET HTTP方法获取,还可以从其他HTTP方法获取。

 

Component Options

The JettyHttpComponent provides the following options:

JettyHttpComponent提供了以下选项:

Option

Default Value

Description

allowJavaSerializedObject

false

Camel 2.16.1/2.15.5: Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object.

When true, be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.

当请求使用context-type = application / x-java-serialized-object时是否允许java序列化。

如果是true,请注意,Java会将请求中的传入数据反序列化为Java,这可能会带来潜在的安全风险。

enableJmx

false

Camel 2.3: If this option is true, Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.

如果这个选项是真的,Jetty JMX支持将被启用这个端点。 请参阅Jetty JMX支持以获取更多详细信息。

errorHandler

null

Camel 2.15: This option is used to set the ErrorHandler that Jetty server uses.

该选项用于设置Jetty服务器使用的ErrorHandler。

httpClient

null

Deprecated: Producer only: To use a custom HttpClientwith the jetty producer.

Note: from Camel 2.11 this option has been removed. Set the option on the endpoint instead.

httpClientMaxThreads

null

Producer only: To set a value for maximum number of threads in HttpClient thread pool. Notice that both a min and max size must be configured.

仅生产者:为HttpClient线程池中的最大线程数设置一个值。 请注意,必须配置最小和最大尺寸。

httpClientMinThreads

null

Producer only: To set a value for minimum number of threads in HttpClient thread pool. Notice that both a min and max size must be configured.

仅生产者:为HttpClient线程池中的最小线程数设置一个值。 请注意,必须配置最小和最大尺寸。

httpClientThreadPool

null

Deprecated: Producer only: To use a custom thread pool for the client.

Note: this option has been removed from Camel 2.11.

maxThreads

null

Camel 2.5 Consumer only: To set a value for maximum number of threads in server thread pool. Notice that both a min and max size must be configured.

Camel 2.5仅限使用者:为服务器线程池中的最大线程数设置一个值。 请注意,必须配置最小和最大尺寸。

minThreads

null

Camel 2.5 Consumer only: To set a value for minimum number of threads in server thread pool. Notice that both a min and max size must be configured.

Camel 2.5仅限使用者:为服务器线程池中的最小线程数设置一个值。 请注意,必须配置最小和最大尺寸。

proxyHost

null

Camel 2.12.2/2.11.3 To use an HTTP proxy.

proxyPort

null

Camel 2.12.2/2.11.3: To use an HTTP proxy.

socketConnectors

null

Camel 2.5 Consumer only: A map which contains per port number specific HTTP connectors. Uses the same principle as sslSocketConnectors and therefore see section SSL supportfor more details.

Camel 2.5仅限使用者:包含每个端口号码的特定HTTP连接器的映射。 使用与sslSocketConnectors相同的原理,因此请参阅SSL支持以获取更多详细信息。

socketConnectorProperties

null

Camel 2.5 Consumer only. A map which contains general HTTP connector properties. Uses the same principle as sslSocketConnectorProperties and therefore see section SSL support for more details.

Camel2.5只消费者。 包含常规HTTP连接器属性的映射。 使用与sslSocketConnectorProperties相同的原理,因此请参阅SSL支持以获取更多详细信息。

sslContextParameters

null

Camel 2.8: To configure a custom SSL/TLS configuration options at the component level. 

在组件级别配置自定义SSL / TLS配置选项。

See  Using the JSSE Configuration Utility for more details.

sslKeyPassword

null

Consumer only: The password for the keystore when using SSL.

仅限使用者:使用SSL时密钥库的密码。

sslKeystore

null

Consumer only: The path to the keystore.

仅限消费者:密钥库的路径。

sslPassword

null

Consumer only: The password when using SSL.

仅限使用者:使用SSL时的密码。

sslSocketConnectors

null

Camel 2.3 Consumer only: A map which contains per port number specific SSL connectors. See section SSL support for more details.

Camel2.3仅限消费者:包含每个端口号特定SSL连接器的映射。 有关更多详细信息,请参阅SSL支持。

sslSocketConnectorProperties

null

Camel 2.5 Consumer only. A map which contains general SSL connector properties. See section SSL support for more details.

Camel2.5只消费者。 包含常规SSL连接器属性的映射。 有关更多详细信息,请参阅SSL支持。

requestBufferSize

null

Camel 2.11.2: Allows to configure a custom value of the request buffer size on the Jetty connectors.

Camel2.11.2:允许在Jetty连接器上配置请求缓冲区大小的自定义值。

requestHeaderSize

null

Camel 2.11.2: Allows to configure a custom value of the request header size on the Jetty connectors.

允许在Jetty连接器上配置请求标头大小的自定义值。

responseBufferSize

null

Camel 2.11.2: Allows to configure a custom value of the response buffer size on the Jetty connectors.

允许在Jetty连接器上配置响应缓冲区大小的自定义值。

responseHeaderSize

null

Camel 2.11.2: Allows to configure a custom value of the response header size on the Jetty connectors.

允许在Jetty连接器上配置自定义的响应头大小。

threadPool

null

Camel 2.5 Consumer only: To use a custom thread pool for the server. This option should only be used in special circumstances.
仅限使用者:为服务器使用自定义线程池。 这个选项只能在特殊情况下使用。

 

Producer Example

The following is a basic example of how to send an HTTP request to an existing HTTP endpoint.

以下是如何向现有HTTP端点发送HTTP请求的基本示例。

Java DSL : 

from("direct:start").to("jetty://http://www.google.com");

消费者示例

In this sample we define a route that exposes a HTTP service at http://localhost:8080/myapp/myservice

在这个例子中,我们定义了一个公开HTTP服务的路由 http://localhost:8080/myapp/myservice

When you specify localhost in a URL, Camel exposes the endpoint only on the local TCP/IP network interface, so it cannot be accessed from outside the machine it operates on.

在URL中指定localhost时,Camel仅在本地TCP / IP网络接口上公开端点,因此无法从运行的机器外部访问。

If you need to expose a Jetty endpoint on a specific network interface, the numerical IP address of this interface should be used as the host. 

If you need to expose a Jetty endpoint on all network interfaces, the 0.0.0.0 address should be used.

如果您需要在特定网络接口上公开Jetty端点,则应使用此接口的数字IP地址作为主机。

如果您需要在所有网络接口上公开Jetty端点,则应使用0.0.0.0地址。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值