Search code examples
javasoapspring-ws

No adapter for endpoint. Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?


I am struggling with an Spring-WS project.

In my Endpoint class, if I don't specify I'm receiving/returning a JAXBElement, I get the following error: No adapter for endpoint; Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

For instance, this method will work OK:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "pingRequest")
@ResponsePayload
public JAXBElement<PingResponse> pingRequest(@RequestPayload JAXBElement<PingRequest> request) {
    PingResponse response = service.ping();
    return new JAXBElement<PingResponse>(request.getName(), PingResponse.class, response);
}

But this one will cause the error mentioned above:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "pingRequest")
@ResponsePayload
public PingResponse pingRequest(@RequestPayload PingRequest request) {
    return service.ping();
}

Is there any way for me to simply return the element I want instead of wrapping it up in a JAXBElement?

I have a few methods declared like that, and I noticed I only need to wrap them as JAXBElements when I'm using elements imported from another XSD.

For instance, if I have my XSD defined like this:

<xs:element name="pingRequest">
    <xs:complexType>
        <xs:sequence>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="pingResponse">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="return" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

It will work without specifying JAXBElement in the signature. But if I want to export that and use it in another XSD like this:

service.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://example.com/service"
    elementFormDefault="qualified"
    targetNamespace="http://example.com/service"
    xmlns:customlib="http://example.com/customlib">

    <xs:import namespace="http://example.com/customlib"
    schemaLocation="../customlib.xsd" />

    <xs:element name="pingRequest" type="customlib:pingRequest" />

    <xs:element name="pingResponse" type="customlib:pingResponse" />

customlib.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://example.com/customlib" 
    elementFormDefault="unqualified"
    targetNamespace="http://example.com/customlib">

    <xs:complexType name="pingRequest">
    </xs:complexType>

    <xs:complexType name="pingResponse">
        <xs:sequence>
            <xs:element name="return" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>

Then it won't work. I'm not sure what to google for to get the desired effect.


Solution

  • JAXBElement is here because you have custom type. If you point nillable=true you get the same. As you already understood you need to do your request and response simple elements, so JAXBElement wrapper won't be needed.

    ANd it's good practice to put real data model in one xsd and its wrappers like request and response element in another. In that case you can change the representation of your data model with different wrappers without changing data model itself.