12.3.2. 使用配置

命名空间

用于配置 HTTP 供应商端点的元素在命名空间 http://cxf.apache.org/transports/http/configuration 中定义。通常会使用前缀 http-conf 来引用。要使用 HTTP 配置元素,您必须将 例 12.9 “HTTP Provider Configuration Namespace” 中显示的行添加到端点配置文件的 Bean 元素中。另外,您必须将配置元素的命名空间添加到 xsi:schemaLocation 属性。

例 12.9. HTTP Provider Configuration Namespace

<beans ...
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       ...
       xsi:schemaLocation="...
                           http://cxf.apache.org/transports/http/configuration
                              http://cxf.apache.org/schemas/configuration/http-conf.xsd
                          ...">

Undertow 运行时或 Netty 运行时

您可以使用 http-conf 命名空间中的元素配置 Undertow 运行时或 Netty 运行时。

destination 元素

您可以使用 http-conf:destination 元素及其子项配置 HTTP 服务供应商端点。http-conf:destination 元素采用单个属性 name,用于指定与端点对应的 WSDL 端口 元素。name 属性的值采用以下形式的 portQName'.http-destination'。例 12.10 “HTTP-conf:destination Element” 显示 http-conf:destination 元素,用于为端点添加由 WSDL 片段 < port binding="widgetSOAPBinding" name="widgetSOAPPort > 指定的端点配置 http://widgets.widgetvendor.net。

例 12.10. HTTP-conf:destination Element

...
  <http-conf:destination name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-destination">
    ...
  </http-conf:destination>
...

http-conf:destination 元素有多个指定配置信息的子元素。表 12.4 “用于配置 HTTP 服务提供商端点的元素” 中描述的它们。

表 12.4. 用于配置 HTTP 服务提供商端点的元素

元素描述

http-conf:server

指定 HTTP 连接属性。请参阅 “server 元素”一节

http-conf:contextMatchStrategy

指定配置用于处理 HTTP 请求的上下文匹配策略的参数。

http-conf:fixedParameterOrder

指定此目的地处理的 HTTP 请求的参数顺序是否已解决。

server 元素

http-conf:server 元素用于配置服务提供商端点 HTTP 连接的属性。其属性(如 表 12.5 “HTTP 服务提供商配置属性” 所述)指定连接的属性。

表 12.5. HTTP 服务提供商配置属性

属性描述

ReceiveTimeout

设定连接超时前服务提供程序尝试接收请求的时间长度,以毫秒为单位。默认值为 30000

0 指定供应商不会超时。

SuppressClientSendErrors

指定在收到请求时是否抛出异常。默认为 false ;遇到错误时会抛出异常。

SuppressClientReceiveErrors

指定在向消费者发送响应时是否遇到错误时是否抛出异常。默认为 false ;遇到错误时会抛出异常。

HonorKeepAlive

指定在发送响应后,服务提供商是否遵循连接是否保持打开状态。默认为 false ;忽略 keep-alive 请求。

RedirectURL

如果客户端请求的 URL 不再适合所请求的资源,则指定客户端请求应重定向到的 URL。在本例中,如果服务器响应的第一行中没有自动设置状态代码,则状态代码设置为 302,状态描述设置为 Object Moved。该值用作 HTTP RedirectURL 属性的值。

CacheControl

指定由涉及的链中必须遵循的行为的指令,由来自服务提供商的响应增加至消费者。请参阅 第 12.3.4 节 “服务提供商缓存控制指令”

ContentLocation

设置在响应中发送资源所在的 URL。

ContentType

指定在响应中发送的信息的介质类型。使用多用途互联网邮件扩展(MIME)类型来指定介质类型。该值用作 HTTP ContentType 位置的值。

ContentEncoding

指定应用于由服务提供商发送的信息应用的任何额外内容编码。内容编码标签由互联网编号授权机构(IANA)监管。可能的内容编码值包括 zip、gzip、压缩、deflate 和 identity。这个值被用作 HTTP ContentEncoding 属性的值。

内容编码的主要用途是允许使用一些编码机制(如 zip 或 gzip)压缩文档。Apache CXF 对内容编码没有验证。用户负责确保应用程序级别支持指定的内容编码。

ServerType

指定发送响应的服务器类型。使用 form program-name/version 的值,如 Apache/1.2.5

示例

例 12.11 “HTTP 服务提供商端点配置” 显示 HTTP 服务提供商端点的配置,该端点遵循保留请求并阻止所有通信错误。

例 12.11. HTTP 服务提供商端点配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration
                             http://cxf.apache.org/schemas/configuration/http-conf.xsd
                           http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans.xsd">

  <http-conf:destination name="{http://apache.org/hello_world_soap_http}SoapPort.http-destination">
    <http-conf:server SuppressClientSendErrors="true"
                      SuppressClientReceiveErrors="true"
                      HonorKeepAlive="true" />
  </http-conf:destination>
</beans>