繁体   English   中英

如何以编程方式(在TomEE中)获取SOAP请求的内容类型和编码?

[英]How to obtain content-type and encoding of a SOAP request programmatically (in TomEE)?

我有一个用Java编写并部署在TomEE plus 1.7.1上的Web服务,并且存在与请求编码有关的问题,即我必须处理具有不同编码的请求,尤其是ISO-8859-1UTF-8 这就是为什么我需要识别传入请求具有哪种编码的原因。 现在,我正在跟踪传入的消息:

ID: 1
Address: http://localhost:8006/services/soaprequest
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml;charset=UTF-8
Headers: {accept-encoding=[gzip,deflate], connection=[Keep-Alive], Content-Length=[12915], content-type=[text/xml;charset=UTF-8], host=[localhost:8006], SOAPAction=["http://tempuri.org/soaprequest/soaprequest"], user-agent=[Apache-HttpClient/4.1.1 (java 1.5)]}
Payload: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://tempuri.org/soaprequest">

...XML message goes here...

</soapenv:Envelope>

从跟踪中可以看出,该请求具有诸如“编码”和“内容类型”之类的标记,从我可以得出的结论来看,请求是针对Web服务的哪种编码。

我尝试了SOAPHandler来检测它:

public boolean handleMessage(SOAPMessageContext context) {
    if (!(boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        String[] mimeHeader = context.getMessage().getSOAPPart().getMimeHeader("Content-Type");
        for (int i = 0; i < mimeHeader.length; i++)
            System.out.println("mimeHeader " + (i + 1) + ":" + mimeHeader[i]);
    }
    return true; //indicates to the context to proceed with (normal)message processing
}

输出为:

mimeHeader 1:text/xml

所以这种方式我做不到。

问:如何检索内容类型字符集或Web服务请求的编码?

关于什么

 Object encProp = context.getMessage().getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
 String encoding = encProp != null ? encProp.toString() : null;

但似乎该属性主要用于设置编码。 因此,您需要尝试在收到消息时填充属性。

这个问题解决了。 解决方案在这里找到:

http://middlewaremagic.com/weblogic/?p=351

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM