我有来自soap服务的日志文件,其中存在xml请求/响应。如何在不进行任何编组/映射和手动解析的情况下将其转换为java对象?只创建绑定类,将其放入wsld并调用read()方法。
我的系统使用cfx和Aegis绑定。这是我的代码,但它不能解析对象,因为它不知道如何映射对象。关于如何将wsdl绑定到我的目标的确切问题。
AegisDatabindingFactoryBean factoryBean = new AegisDatabindingFactoryBean();
factoryBean.setWriteXsiTypes(true);
factoryBean.setOverrideTypes(overridedClassList);
factoryBean.setSupportVariations(true);
AegisDatabinding dataBinding = factoryBean.createAegisDatabinding();
DataReader<XMLStreamReader> dataReader = dataBinding.createReader(XMLStreamReader.class);
String tempData = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>...";
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = factory.createXMLStreamReader(new StringReader(tempData));
Object result = dataReader.read(streamReader);
答案 0 :(得分:0)
我找到了解决方案:要使用Aegis将soap-xml转换为java对象,您需要创建AegisDatabind(它可以与您的重写相比),而不是使用ClientFactoryBean创建cxf客户端,现在您的绑定是使用wsdl的init。但是对于所有这些工作,你应该拥有或使用wsdl服务器或将wsdl放在文件系统中:
AegisDatabinding dataBinding = ... {your dataBinding};
ClientFactoryBean clientProxyFactoryBean = new ClientFactoryBean();
clientProxyFactoryBean.setDataBinding(dataBinding);
// Path to wsdl
clientProxyFactoryBean.setAddress("http://servername/app?wsdl");
// implemented service
clientProxyFactoryBean.setServiceClass(com.exigen.aaa.rating.home.ca.RatingService.class);
Client client = clientProxyFactoryBean.create();
DataReader<XMLStreamReader> dataReader = dataBinding.createReader(XMLStreamReader.class);
String tempData = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>...";
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = factory.createXMLStreamReader(new StringReader(tempData));
// miss all soap messages
while (true) {
if (streamReader.isStartElement()) {
System.out.println(streamReader.getName());
if ("{http://your.object.value/}arg1".equals(streamReader.getName().toString())) {
break;
}
}
streamReader.next();
}
Object result = dataReader.read(streamReader);