Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

java - Empty request while using webServiceTemplate.marshalSendAndReceive()

I am using spring webServiceTemplate to make a SOAP request to another web service.

First of all I generated Java classes from wsdl using cxf maven plugin.

Some interesting part of wsdl and xsd are below:

<wsdl:portType name="FooPort">
    <wsdl:operation name="foo">
        <wsdl:input message="FooRequest"/>
        <wsdl:output message="FooResponse"/>
    </wsdl:operation>
</wsdl:portType>

<wsdl:message name="FooRequest">
    <wsdl:documentation>
        Doc here
    </wsdl:documentation>
    <wsdl:part element="foo" name="request"/>
</wsdl:message>

<xsd:element name="foo">
    <xsd:annotation>
        <xsd:documentation> Doc here </xsd:documentation>
    </xsd:annotation>
</xsd:element>

No class named Foo was generated because the <xsd:element> is empty.

I observed that there was generated another class ObjectFactory which has method like this:

@XmlElementDecl(namespace = "namespace", name = "foo")
public JAXBElement<Object> createFoo(Object value) {
    return new JAXBElement<Object>(_Foo_QNAME, Object.class, null, value);
}

The problem here is that function createFoo takes Object as an argument and I don't know what I should pass to it.

Then to call web service I want to use spring webServiceTemplate

ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<Object> request = objectFactory.createFoo(new Object());
getWebServiceTemplate().marshalSendAndReceive(request);

When I try to run this application, some error happens:

class java.lang.Object cannot be cast to class org.w3c.dom.Element (java.lang.Object is in module java.base of loader 'bootstrap'; org.w3c.dom.Element is in module java.xml of loader 'bootstrap')

I undestand that I cannot pass new Object() to the factory method but what else I can pass there?

I expect final request to look like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header />
   <SOAP-ENV:Body>
      <ns3:foo xmlns:ns3="namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
question from:https://stackoverflow.com/questions/65945984/empty-request-while-using-webservicetemplate-marshalsendandreceive

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...