我使用wsimport创建了一个soap客户端,我需要将消息中字符串字段内的xml数据发送到Web服务器.我知道我不需要在webservice调用中使用cdata,但webservice需要这个字段在cdata标签中.
问题是如何做到这一点.
要从wsdl生成代码,我使用jaxws-maven-plugin.在maven配置中我使用绑定文件
bindingFiles
binding Filebinding.xjb /bindingFile
/bindingFiles
Run Code Online (Sandbox Code Playgroud)
jxb:bindings version="2.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:uniface:applic:services:BRF_IN"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<jxb:globalBindings generateElementProperty="false"/>
<jxb:bindings scd="//element::tns:DATA">
<jxb:javaType
name="String"
parseMethod="de.xyz.CdataConverter.unmarshal"
printMethod="de.xyz.CdataConverter.marshal"
/>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
和marshal/unmarschal看起来像这样:
public class CdataConverter {
private static final Pattern PATTERN = Pattern.compile("((?<=\\<\\!\\[CDATA\\[)[\\S\\s]+(?=\\]\\]\\>))");
private static final String CDATA_START = "<![CDATA[";
private static final String CDATA_END = "]]>";
private final static Logger logger =
Logger.getLogger(LgTestServer.class.getName());
public static String marshal(String input) {
if (input == null) {
return null;
}
PropertyConfigurator.configure(".\\log4j.properties");
logger.info("input --------------------->>>>>>>>\n" + input);
return CDATA_START + input + …Run Code Online (Sandbox Code Playgroud)