0

I am using the JAX-WS RI, with files that have been auto-geenrated by Netbeans via File > Web Service and then entering the WSDL.

The problem I am having is that the JAX-WS RI always attaches this header to the request:

Content-Type: application/soap+xml; charset=utf-8;action="urn:getOrganization"

However our web server does not accept charset=utf-8, it wants charset=UTF-8.

How can I change this using the JAX-WS RI?
If this cannot be done, then are there other options available which ultimately lead to sending charset=UTF-8?

skiwi
  • 66,971
  • 31
  • 131
  • 216
  • May be you should fix your server? – win_wave Jun 23 '14 at 11:08
  • @win_wave I do not have the web server under control, so unfortunately I cannot do anything about it. It also seems that JAX-WS RI does not allow sending any other charset. – skiwi Jun 23 '14 at 11:18
  • In practice it is a bug on server side, and you should not care about that. As workaround may be you can put some apache in between and modify header there. see here: http://stackoverflow.com/questions/154441/set-up-an-http-proxy-to-insert-a-header – win_wave Jun 23 '14 at 11:28

1 Answers1

0

Maybe a Handler may do the trick?

public class EnforceUppercaseUtf8MessageHandler implements SOAPHandler<SOAPMessageContext> {

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outbound.booleanValue()) {
        try {
            context.getMessage().setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
                            "UTF-8");
        }
        catch (SOAPException e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}

And register the handler:

    BindingProvider bindProv = (BindingProvider) service;
    List<Handler> handlerChain = bindProv.getBinding().getHandlerChain();
    handlerChain.add(new EnforceUppercaseUtfMessageHandler ());
JRA_TLL
  • 1,186
  • 12
  • 23