membersound
membersound

Reputation: 86915

How to set encoding of SOAP responses in CXF client?

I'm using Apache CXF to create a SOAP client. A web service response contains the following umlaut character: [0xc3][0x9c], which is an Ü.

Of course I could manually convert this field when I read the response like:

String utfString = new String(isoString.getBytes("ISO-8859-1"), "utf-8");

But I'd rather set the client to convert the ISO to UTF8 strings automatically.

Question: how can I configure this in a CXF client globally for any incoming requests?

Upvotes: 5

Views: 7452

Answers (1)

Karthik Prasad
Karthik Prasad

Reputation: 10034

You can set encoding as shown below.

@Bean
    public KPWs kpMath(SpringBus bus) {
        final JAXWSSpringClientProxyFactoryBean client = new JAXWSSpringClientProxyFactoryBean();
        client.setBus(bus);
        client.setAddress("http://localhost:8080/services/ws ?wsdl");
        client.getFeatures().add(new LoggingFeature());
        Map<String, Object> map = new HashMap<>();
        map.put("org.apache.cxf.message.Message.ENCODING", "ISO-8859-1");
        client.setProperties(map);
        return client.create(KPWs.class);

    }

Upvotes: 2

Related Questions