简体   繁体   中英

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?

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);

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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