Java SOAP-WS client horror

∥☆過路亽.° 提交于 2019-12-25 10:25:26

问题


It's looking amazingly difficult to use any of the most used soap services framework (at least those I've tried) and come up with this kind of soap request

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://bencws.foobar.com/doc/2008-01-01/" 
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope/">
    <soap:Header xmlns:foo="http://safe.foobar.com/doc/2007-01-01/" xmlns:oof="http://www.w3.org/2005/08/addressing">
        <foo:AccessKeyId>0PKRFZMV7GRJ11N791R2</foo:AccessKeyId>
        <foo:Timestamp>2008-03-07T23:55:22.693Z</foo:Timestamp>
        <foo:Signature>someencodedstring</foo:Signature>
        <oof:Action>SomeAction</oof:Action>
        <oof:To>http://bencws.foobar.com</oof:To>
        <oof:MessageID>120493412293</oof:MessageID>
        <oof:ReplyTo>
            <oof:Address> http://www.w3.org/2005/08/addressing/anonymous</oof:Address>
        </oof:ReplyTo>
    </soap:Header>
    <soap:Body>
    ...

With cxf I started using cxf-codegen-plugin to create classes stub from wsdl file. But then the "standard" thingie did not allow to change soap:Header namespace or even add stuff inside the tag (unless you bend over backwards twice)

With axis2 I used WSDL2Java and endend up with the same kind of troubles.

I've come up with what would look like formally "correct" soap requests but freaking foobar service won't accept them anyways unless my soap:Envelope and soap:Header don't look exactly like that.

Any help will be much appreciated. Should I try something else? We're now at the point we're thinking to write the xml requests manually which is something I'd avoid.


回答1:


With CXF, getting the namespaces declared onto the soap:Envelope is relatively easy. You can provide a Map of namespace -> prefix to the client via a request property:

((BindingProvider)proxy).getRequestContext().put("soap.env.ns.map", map);

Thus, if you can have the foo and oof namespaces declared there, you could do that. Adding them onto the soap:Header is definitely not an easy thing to do. :-(



来源:https://stackoverflow.com/questions/13027354/java-soap-ws-client-horror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!