简体   繁体   中英

Convert soap xml to java

I have log file from soap service where present xml request/reponce. How i can convert its to java object without any marshaling/mapping and mannual parsing? Only create binding classes, put in it wsld and call read() method.

My system used cfx and Aegis binding. It is my code, but it can't pars object as don't know how to mapping object. Exactly question about how to put wsdl to bind for my aim.

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

I was found the solution: to convert from soap-xml to java object with Aegis you need create AegisDatabind (it can be standart of your with overriding), than create cxf client using ClientFactoryBean and now your binding is init with wsdl. But to all this work you should have or working server with wsdl or put wsdl in filesystem:

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

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