我正在尝试配置编组器,以使其不会将'<'转换为'&lt;'等。 我已经实现了一个自定义的CharacterEscapeHandler,但发出请求时似乎不会触发。 我发现了一些类似的线程,但是不幸的是没有有效的解决方案。我什至读到这是一个弹簧错误,我希望不是。 我的代码是
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
Map<String, Object> props = new HashMap<>();
props.put("com.sun.xml.bind.marshaller.CharacterEscapeHandler",
new CharacterEscapeHandler() {
@Override
public void escape(char[] ac, int i, int j, boolean flag,
Writer writer) throws IOException {
System.out.println("I AM HERE");
writer.write(ac, i, j);
}
});
marshaller.setMarshallerProperties(props);
marshaller.setContextPaths(path);
return marshaller;
}
@Bean
public SOAPClientConnector soapConnector(Jaxb2Marshaller marshaller) {
SOAPClientConnector client = new SOAPClientConnector();
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
我这样使用它。
getWebServiceTemplate().marshalSendAndReceive(url, request);