【问题标题】:How to provide a parameter to a JAX-WS web service handler?如何向 JAX-WS Web 服务处理程序提供参数?
【发布时间】:2015-01-29 08:46:50
【问题描述】:

十年前,我使用 Weblogic 8.1 (J2EE 1.4) 和 JAX-RPC 创建了几个应用程序,其中主要包含 Web 服务。多亏了一个 Web 服务处理程序,我可以使用这样的 XML 文件定义这些 Web 服务的每次调用都记录在数据库中:

<?xml version="1.0" encoding="UTF-8"?>
<hc:wlw-handler-config xmlns:hc="http://www.bea.com/2003/03/wlw/handler/config/">
    <hc:handler-chain name="HistHandler">
        <hc:handler handler-name="HistLogger" handler-class="class implementing  the handler">
            <hc:init-param>
                <hc:description>description of the parameter</hc:description>
                <hc:param-name>name of the parameter</hc:param-name>
                <hc:param-value>value of the parameter</hc:param-value>
            </hc:init-param>
        </hc:handler>
    </hc:handler-chain>
</hc:wlw-handler-config>

如您所见,可以为 JaxRpc Handler 提供一个参数,我使用此功能提供 Web 服务所属的应用程序的名称,以便该应用程序名称可以存储在数据库中肥皂请求。

我今天必须实施同样的事情,但技术发生了变化。我现在必须使用 J2EE 1.6 (Tomee++ 1.6.0.1),并且 JAX-WS 已经取代了 JAX-RPC。 我仍然可以使用这样的 XML 文件指定 Web 服务处理程序:

<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">
    <handler-chain>
        <handler>
            <handler-name>Name of the handler</handler-name>
            <handler-class>class implementing the handler</handler-class>
        </handler>
    </handler-chain>
</handler-chains>

如您所见,似乎不再有可能向处理程序提供参数了。

所以我的问题是:这个功能真的消失了吗?难道真的没有办法给handler类提供参数吗?

【问题讨论】:

    标签: java web-services soap jax-ws handler


    【解决方案1】:

    您是对的,&lt;init-param&gt; 已从 JAX-WS 的配置选项中删除。 From the JSR-109 specification:

    部署描述符中的元素init-params 不再是 用于基于 JAX-WS 的容器。如果需要,开发人员应使用 中声明的环境入口元素() 用于此目的的应用程序组件的部署描述符。这些 可以使用 @Resource 注释注入处理程序或 使用 JNDI 查找。

    这对您来说意味着您要将初始化参数定义为普通 JNDI 条目,并将它们作为 @Resources viz 注入到您的处理程序中

    • 在 web.xml 中:

      <env-entry>
          <description>Description</description>
          <env-entry-name>PROPERTY_NAME</env-entry-name>
          <env-entry-type>java.lang.String</env-entry-type>
          <env-entry-value>property_value</env-entry-value>
      </env-entry>
      
    • 在你的处理程序中

      @Resource String PROPERTY_NAME;
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      相关资源
      最近更新 更多