[8.5.5.4 或更高版本]

添加 Web Service 全局处理程序

需要对所有 Web Service 端点注册 Web Service 处理程序的组件必须实现处理程序接口并在服务注册表中注册该实现。

开始之前

全局处理程序服务由 jaxws-2.2jaxrs-1.1Liberty Repository[8.5.5.6 或更高版本]jaxrs-2.0jaxrs-2.0 client 提供,所以您必须在 server.xml 文件中指定以下功能部件或功能部件组合:
  • jaxws-2.2
  • jaxrs-1.1
  • Liberty Repository[8.5.5.6 或更高版本]jaxrs-2.0
  • Liberty Repository[8.5.5.6 或更高版本]jaxrs-2.0 客户机
  • jaxws-2.2jaxrs-1.1
  • Liberty Repository[8.5.5.6 或更高版本]jaxws-2.2jaxrs-2.0
  • Liberty Repository[8.5.5.6 或更高版本]jaxws-2.2jaxrs-2.0 客户机

关于此任务

处理程序 SPI 提供不同属性以指定 ENGINE_TYPE、FLOW_TYPE 以及客户端 (IS_CLIENT_SIDE) 或处理程序生效的服务器端 (IS_SERVER_SIDE)。

必须实现处理程序接口并在服务注册表中注册实现类。

每个 Liberty 概要文件 SPI 的 Java API 文档以独立压缩文件的形式在 ${wlp.install.dir}/dev 目录的某个 Javadoc 子目录中提供。

部署处理程序捆绑软件

可通过使用 WebSphere® Application Server Developer Tools for Eclipse 来部署处理程序捆绑软件。

过程

  1. 单击文件 > 新建 > 其他,然后展开 OSGi
  2. 单击 OSGi 捆绑软件项目,然后单击下一步。“新建 OSGi 捆绑软件项目”窗口将打开。
  3. 输入 MyHandler 作为项目名称。在目标运行时列表中,选择 WebSphere Application Server Liberty 概要文件。如果没有运行时,请单击新建运行时以创建 WebSphere(r) Application Server Liberty 概要文件运行时。
  4. 取消选中将捆绑软件添加至应用程序选项。
  5. 单击下一步两次并转至“OSGi 捆绑软件”页面。
  6. 在“OSGi 捆绑软件”页面上,选中生成激活程序,用于控制捆绑软件生命周期的 Java 类。将激活程序名称保留为 myhandler.Activator 并单击完成
  7. 单击窗口 > 首选项 > 插件开发 > 目标平台,然后选择带 SPI 的 WebSphere Application Server Liberty 概要文件
    注: 确保您已在 3 中添加 WebSphere Application Server Liberty 概要文件运行时。
  8. 单击应用,然后单击确定
  9. 展开 MyHandler > BundleContent > META-INF,然后使用插件清单编辑器打开 MANIFEST.MF 文件。
  10. 创建 MyHander 和 MyActivitor 类:
    ...
    import com.ibm.wsspi.webservices.handler.Handler;
    ...
    
    public class MyHandler implements Handler {
        ...
        public void handleFault(GlobalHandlerMessageContext arg0) {
            ...
        }
        public void handleMessage(GlobalHandlerMessageContext msgctxt) throws Exception {
    
            if (msgctxt.getFlowType().equalsIgnoreCase(HandlerConstants.FLOW_TYPE_OUT)) {
                }
            ...
         }
         ....
    }
    public class MyActivator implements BundleActivator {
        ...
        public void start(BundleContext context) throws Exception {
    
              final Hashtable<String, Object> handlerProps = new Hashtable<String, Object>();
               handlerProps.put(HandlerConstants.ENGINE_TYPE, HandlerConstants.ENGINE_TYPE_JAXWS);
               handlerProps.put(HandlerConstants.FLOW_TYPE, HandlerConstants.FLOW_TYPE_IN);
               handlerProps.put(HandlerConstants.IS_CLIENT_SIDE, true);
               handlerProps.put(HandlerConstants.IS_SERVER_SIDE, true);
               handlerProps.put(org.osgi.framework.Constants.SERVICE_RANKING, 3);
               MyHandler myHandler = new MyHandler();
               context.registerService(Handler.class, myHandler, handlerProps);
               ...
            }
            ...
       }
  11. 单击文件 > 新建 > 其他,然后展开 OSGi
  12. 单击 Liberty 功能部件项目,然后单击下一步。“Liberty 功能部件项目”窗口将打开。
  13. 指定 MyHandlerFeature 作为项目名称。
  14. 在目标运行时列表中,选择 WebSphere Application Server Liberty 概要文件,然后单击下一步。“OSGi 捆绑软件选择页面”将打开。
  15. 在“OSGi 捆绑软件选择页面”上,选择 MyHandler 1.0.0 作为包含的捆绑软件,然后单击完成
  16. 在 MyHandler 项目中修改 Manifest:MyHandler。单击 MANIFEST.MF 选项卡,然后将 com.ibm.wsspi.webservices.handler 添加至 Import-pacakge 元素。
  17. 右键单击 MyHandlerFeature 项目,单击安装功能部件以将该功能部件安装至 Liberty 运行时。
  18. 编辑 server.xml 文件以启用 MyHandlerFeature:
    <featureManager> ......
    <feature>jsp-2.2</feature>
    <feature>jaxws-2.2</feature> // you can also use one of the following feature or feature combinations: jaxrs-1.1, jaxrs-2.0, jaxrsClient-2.0, 
    jaxws-2.2 and jaxrs-1.1, jaxws-2.2 and jaxrs-2.0, jaxws-2.2 and jaxrsClient-2.0
    <feature>usr:MyHandlerFeature</feature> ......
    </featureManager>

用于指示主题类型的图标 任务主题

信息中心的条款和条件 | 反馈


时间戳记图标 最近一次更新时间: Wednesday, 2 September 2015
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_web_services_global_handlers
文件名:twlp_web_services_global_handlers.html