如何使 JAXWS 在 SOAP 响应上发送内容长度标头

发布于 2024-12-05 03:39:47 字数 1465 浏览 1 评论 0原文

基本上我使用 JAXWS 制作了一个 Web 服务。它使用 SOAP 并且有效。然而,在某些请求上,某些客户端崩溃/错误,这似乎与 JAXWS Web 服务不发送内容长度标头这一事实有关。有办法添加吗?

使用:openjdk-6 (6b20)

我的课程如下所示:

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;

@WebService
public class SOAP {
public static void main(String[] args) {
    try {
        SOAP server = new SOAP();
        Endpoint endpoint = Endpoint.publish('localhost:1234', server);
    } catch (Exception e) {
                Utils.getLog("SOAP").fatal("General Error", e);
    }
}
}

使用 tcpdump 确认响应中没有内容长度:

0x0000:  4500 00b0 4da5 4000 4006 20d5 5cf3 1021  E...M.@.@...\..!
0x0010:  5cf3 01c7 13b2 bcea a9be 716e 14c3 16a1  \.........qn....
0x0020:  8018 006c cc70 0000 0101 080a 2e1b 3ccc  ...l.p........<.
0x0030:  2e18 23a2 4854 5450 2f31 2e31 2032 3030  ..#.HTTP/1.1.200
0x0040:  204f 4b0d 0a54 7261 6e73 6665 722d 656e  .OK..Transfer-en
0x0050:  636f 6469 6e67 3a20 6368 756e 6b65 640d  coding:.chunked.
0x0060:  0a43 6f6e 7465 6e74 2d74 7970 653a 2074  .Content-type:.t
0x0070:  6578 742f 786d 6c3b 6368 6172 7365 743d  ext/xml;charset=
0x0080:  2275 7466 2d38 220d 0a44 6174 653a 2053  "utf-8"..Date:.S
0x0090:  6174 2c20 3137 2053 6570 2032 3031 3120  at,.17.Sep.2011.
0x00a0:  3134 3a31 393a 3337 2047 4d54 0d0a 0d0a  14:19:37.GMT....

所以我的问题是,有没有办法告诉 Web 服务将内容长度与回复一起发送?或者在发送回复之前附加它的方法?

Basically I made a Webservice using JAXWS. It uses SOAP and works. However on some request some clients crash/error, it seems to be linked to the fact the JAXWS webservice does not send the content-length header. Is there a way to add it?

Using: openjdk-6 (6b20)

My class looks like this:

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;

@WebService
public class SOAP {
public static void main(String[] args) {
    try {
        SOAP server = new SOAP();
        Endpoint endpoint = Endpoint.publish('localhost:1234', server);
    } catch (Exception e) {
                Utils.getLog("SOAP").fatal("General Error", e);
    }
}
}

Using tcpdump confirms there is no content-length in the response:

0x0000:  4500 00b0 4da5 4000 4006 20d5 5cf3 1021  E...M.@.@...\..!
0x0010:  5cf3 01c7 13b2 bcea a9be 716e 14c3 16a1  \.........qn....
0x0020:  8018 006c cc70 0000 0101 080a 2e1b 3ccc  ...l.p........<.
0x0030:  2e18 23a2 4854 5450 2f31 2e31 2032 3030  ..#.HTTP/1.1.200
0x0040:  204f 4b0d 0a54 7261 6e73 6665 722d 656e  .OK..Transfer-en
0x0050:  636f 6469 6e67 3a20 6368 756e 6b65 640d  coding:.chunked.
0x0060:  0a43 6f6e 7465 6e74 2d74 7970 653a 2074  .Content-type:.t
0x0070:  6578 742f 786d 6c3b 6368 6172 7365 743d  ext/xml;charset=
0x0080:  2275 7466 2d38 220d 0a44 6174 653a 2053  "utf-8"..Date:.S
0x0090:  6174 2c20 3137 2053 6570 2032 3031 3120  at,.17.Sep.2011.
0x00a0:  3134 3a31 393a 3337 2047 4d54 0d0a 0d0a  14:19:37.GMT....

So my question is, is there a way to tell the webservice to send the content-length along with the reply? Or a way to append it before the reply is sent?

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

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

发布评论

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

评论(2

变身佩奇 2024-12-12 03:39:47

您可以通过编写处理程序将 HTTP 标头添加到传出响应中。您的处理程序将扩展标准 JAX-WS处理程序 并使用 MessageContext 在handleMessage(C context) 方法修改 HTTP_RESPONSE_HEADER 属性(实际上是映射中的一个键)。例如,您的处理程序将是:

public class MyHandler<SOAPMessageContext> implements Handler {

    public boolean handleMessage(SOAPMessageContext c) {
        if((Boolean)c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
            c.put(SOAPMessageContext.HTTP_RESPONSE_HEADERS,"your header stuff here");
            return true;
        }
    }
 }

您将需要创建一个处理程序链文件并在端点类中添加指向该文件的注释。注解为@HandlerChain(file="...");

完成此操作后,您应该能够修改入站和出站的 HTTP 标头。 HTH。

You can add HTTP headers to the outgoing response by writing a handler. Your handler will extend the standard JAX-WS handler and use the MessageContext in the handleMessage(C context) method to modify the HTTP_RESPONSE_HEADER property (actually a key in the map). So for example your handler will be:

public class MyHandler<SOAPMessageContext> implements Handler {

    public boolean handleMessage(SOAPMessageContext c) {
        if((Boolean)c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
            c.put(SOAPMessageContext.HTTP_RESPONSE_HEADERS,"your header stuff here");
            return true;
        }
    }
 }

You will need to create a handler-chain file and add an annotation pointing to that file in your endpoint class. The annotation is @HandlerChain(file="...");

Once you do this you should be able to modify HTTP headers on in and outbound. HTH.

唱一曲作罢 2024-12-12 03:39:47

我遇到了类似的问题,提供商不会接受分块的消息...它也不会在标头中设置内容长度,并且实际上会分块消息并且网络服务提供商会拒绝我的呼叫...这是使用JAX-WS,使用 Axis2 1.6 作为 JAX-WS 运行时。

我尝试添加 HTTP 标头来手动添加 Content-length,但这会导致其他问题。我最终通过在处理程序中的 SOAPMessageContext 上将 HTTPConstants.CHUNKED 设置为 false 来使其工作。

我在这里写了博客: http://btarlton.blogspot.com/2013/03/jax-ws-with-axis2-how-to-disable.html#!/2013/03/jax-ws-with-axis2- how-to-disable.html

使用 Axis2 作为 JAX-WS 运行时,这是我能找到的唯一修复方法。

I had a similar issue where a provider would not accept a chunked message... it would not set the Content-length in the header either and would actually chunk the message and the web service provider would reject my call... This was using JAX-WS with Axis2 1.6 as the JAX-WS runtime.

I tried add the HTTP headers to manually add Content-length, but this would cause other issues. I eventually got it to work by setting the HTTPConstants.CHUNKED to false on the SOAPMessageContext in a Handler.

I blogged about here: http://btarlton.blogspot.com/2013/03/jax-ws-with-axis2-how-to-disable.html#!/2013/03/jax-ws-with-axis2-how-to-disable.html

With Axis2 as the JAX-WS runtime, this was the only fix I could find.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文