spring-bootwsdlcxfspring-wswsdl2java

@Endpoint with primitive data types - No adapter for endpoint


I am trying to generate CXF-Java-Classes from a WSDL with gradle (WSDL2Java), so that i can use it in my SpringBoot-Application.

The Application provides a SOAP-Endpoint. My Response which I want consists of just a simple boolean:

Request:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header/>
   <soap:Body>
      <ns:isActiveRequest xmlns:ns=\"http://problem.com\"><id>1234</id></ns:isActiveRequest>
   </soap:Body>
</soap:Envelope>

Response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header/>
   <soap:Body>
      <ns:isActiveResponse xmlns:ns="http://problem.com">true</ns3:isActiveResponse>
   </soap:Body>
</soap:Envelope>

I was not able to define this response in my WSDL, so that it works after the CXF-generation with the @Endpoint-Annotation in my SpringBoot-Application. I always get the error: "No adapter for endpoint ... Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?"

Usually i have no problems with CXF and Endpoint with complex response types, because it generates an @XmlRootElement. But it wont do that with a primitive type in the response and is not able to recognize my method under the @Endpoint-Annotation.

[...]
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class SoapEndpoint implements Problem {
private static final String TARGET_NAMESPACE = "http://problem.com";

@PayloadRoot(namespace = TARGET_NAMESPACE, localPart = "isActiveRequest")
@ResponsePayload
@Secured(Roles.PERMISSION)
public boolean isActive(@RequestPayload IsActiveRequest request) {
    return true;
}

The WSDL i used for the generation looks as follow:

<wsdl:types>
    <xs:schema attributeFormDefault="unqualified"
               elementFormDefault="unqualified" targetNamespace="http://problem.com"
               xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <xs:element name="isActiveRequest">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="id" maxOccurs="1" minOccurs="1"
                                nillable="false" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="isActiveResponse" type="xs:boolean"/>

    </xs:schema>
</wsdl:types>

<wsdl:message name="isActiveRequest">
    <wsdl:part name="parameters" element="tns:isActiveRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="isActiveResponse">
    <wsdl:part name="parameters" element="tns:isActiveResponse"></wsdl:part>
</wsdl:message>

<wsdl:portType name="problem">
    <wsdl:operation name="isActive">
        <wsdl:input message="tns:isActiveRequest" name="isActiveRequest"/>
        <wsdl:output message="tns:isActiveResponse" name="isActiveResponse"/>
        <wsdl:fault message="tns:myException" name="fault"/>
    </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="problem_SOAPBinding" type="tns:problem">
    <soap:binding style="document"
                  transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation name="isActive">
        <soap:operation soapAction="isActive"/>
        <wsdl:input name="isActiveRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="isActiveResponse">
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="fault">
            <soap:fault use="literal" name="fault"/>
        </wsdl:fault>
    </wsdl:operation>
</wsdl:binding>

In my build.gradle i am using CXF 3.2.1

task wsdl2java(type: JavaExec) {
    ext {
        outputDir = file(cxfOutputDir)
        wsdlFiles = new FileNameByRegexFinder().getFileNames("${wsdlDir}", /.*\.wsdl/)
    }

    wsdlFiles.each { String wsdlFile ->
        outputs.upToDateWhen { false }
        outputs.dir outputDir
        main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
        classpath = configurations.cxfTool
        args '-d', outputDir
        args '-wsdlLocation', "/wsdl/" + new File(wsdlFile).name
        args '-verbose'
        args '-validate'
        args wsdlFile
    }
}

compile group: 'org.apache.cxf', name: 'cxf-core', version: "3.2.1"
compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version: "3.2.1"
compile "org.apache.cxf:cxf-spring-boot-starter-jaxws:3.2.1"
cxfTool "org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:3.2.1"
cxfTool "org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:3.2.1"
cxfTool "org.apache.cxf:cxf-tools-common:3.2.1"
cxfTool "org.apache.cxf:cxf-tools-wsdlto-core:3.2.1"

Solution

  • I have solved the Problem with the JAXBElement<>

    public JAXBElement<Boolean> isActive(@RequestPayload IsActiveRequest request) {
       ...
       ObjectFactory factory = new ObjectFactory();
       return factory.createIsActiveResponse(myBoolean);
    }