Search code examples
javaencodingcharacter-encodingjax-wsapache-tomee

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


I have a web-service written on Java and deployed on TomEE plus 1.7.1 and there is an issue concerning requests encoding which is that I have to handle requests that have different encodings, more specifically ISO-8859-1 and UTF-8. That is why I need to recognize which encoding does incoming request have. Now, I am tracing incoming message:

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>

As can be seen from the trace the request has such markers as "Encoding" and "Content-type" from what I can conclude in which encoding the request comes to web-service.

I tried SOAPHandler to detect it:

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
}

The output was:

mimeHeader 1:text/xml

So this way I can not do it.

Q: How can I retrieve content-type charset or encoding of web-service request?


Solution

  • This question is resolved. The solution was found here:

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