自定义CharacterEscapeHandler无法在Spring Boot应用程序(Jaxb2Marshaller)中触发

时间:2019-02-27 09:05:04

标签: web-services spring-boot soap jaxb maven-jaxb2-plugin

我正在尝试配置编组器,以使其不会将'<'转换为'&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);

0 个答案:

没有答案