JAX-WS:在代码中定义服务器端处理程序链,而不是在外部 xml 中

发布于 2024-12-28 21:11:39 字数 593 浏览 5 评论 0原文

我想为我的 jax-ws web 服务启用 http 压缩。我发现我必须使用可以修改 http 标头的自定义处理程序链来完成此操作。

我发现的所有教程都引用了注释@HandlerChain,它指向处理程序链配置xml文件,但我的问题是我的web服务必须尽可能轻量级,因此我无法在外部xml文件中定义我的处理程序链。

我尝试了以下方法但没有成功:

        final Endpoint ep = Endpoint.publish("http://localhost:8878/mywebservice",
                new WebserviceImpl() );
        final Binding binding = ep.getBinding();
        final List<Handler> handlerChain = binding.getHandlerChain();
        handlerChain.add(new MySuperbSOAPHandler());
        binding.setHandlerChain(handlerChain);

有人知道该怎么做吗?有可能吗?

i want to enable http compression for my jax-ws webservice. i found out that i have to do it with a custom handlerchain that can modify the http-headers.

all tutorials i found refer to the annotation @HandlerChain that points to a handler chain configuration xml-file but my problem is that my webservice has to be as lightweight as possible therefore i cant define my handler chain in an external xml file.

i tried the following but did not succeed:

        final Endpoint ep = Endpoint.publish("http://localhost:8878/mywebservice",
                new WebserviceImpl() );
        final Binding binding = ep.getBinding();
        final List<Handler> handlerChain = binding.getHandlerChain();
        handlerChain.add(new MySuperbSOAPHandler());
        binding.setHandlerChain(handlerChain);

does anyone know how to do this? is it even possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2025-01-04 21:11:39

当服务已经发布时,您似乎无法更改处理程序链。

如果您的实际用例如上所示,只需创建()然后发布()即可轻松修复。

    final Endpoint ep = Endpoint.create(new WebserviceImpl() );
    final Binding binding = ep.getBinding();
    final List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new MySuperbSOAPHandler());
    binding.setHandlerChain(handlerChain);
    ep.publish("http://localhost:8878/mywebservice");

It doesn't appear that you can change the handler chain when the service has already been published.

If your actual use case is as above, it's easy to fix by simply create()ing and then publish()ing.

    final Endpoint ep = Endpoint.create(new WebserviceImpl() );
    final Binding binding = ep.getBinding();
    final List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new MySuperbSOAPHandler());
    binding.setHandlerChain(handlerChain);
    ep.publish("http://localhost:8878/mywebservice");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文