title: JAXB + Spring WS : "No adapter for endpoint" while using JAXBElement
body: <p>I have a web service that I am trying to implement using Spring and Jaxb.  I already have a handful of working services using both of  these - but this particular service is giving me a hard time due to the format of the response.  In my XSD, the response is defined like this (notice that it is a single element):</p>
  
  <pre><code>&lt;!-- Response definition --&gt;
  &lt;element name="ServiceResponse" type="Q1:Outcome"/&gt;
  
  
  &lt;!-- Outcome definition --&gt;
  &lt;complexType name="Outcome"&gt;
      &lt;sequence&gt;
          &lt;element name="ErrorCode"&gt;
              &lt;simpleType&gt;
                  &lt;restriction base="string"&gt;
                      &lt;maxLength value="8"/&gt;
                  &lt;/restriction&gt;
              &lt;/simpleType&gt;
          &lt;/element&gt;
          &lt;element name="ErrorText"&gt;
              &lt;simpleType&gt;
                  &lt;restriction base="string"&gt;
                      &lt;maxLength value="1000"/&gt;
                  &lt;/restriction&gt;
              &lt;/simpleType&gt;
          &lt;/element&gt;
          &lt;element name="DocumentId"&gt;
              &lt;simpleType&gt;
                  &lt;restriction base="string"&gt;
                      &lt;maxLength value="30"/&gt;
                  &lt;/restriction&gt;
              &lt;/simpleType&gt;
          &lt;/element&gt;
      &lt;/sequence&gt;
  &lt;/complexType&gt;
  </code></pre>
  
  <p>I have a service method that looks like this:</p>
  
  <pre><code>@PayloadRoot( localPart = SERVICE_REQUEST, namespace = NAMESPACE )
  public Outcome processFileRequest( ServiceRequest requestObject )
  </code></pre>
  
  <p>I end up with an exception that looks like this:</p>
  
  <p><strong>java.lang.IllegalStateException:
  No adapter for endpoint [public dortman.xsd.objects.Outcome dortman.annotated.MyTestEndpoint.processFileRequest(dortman.xsd.objects.ServiceRequest)]: Does your endpoint implement a supported interface like MessageHandler or PayloadEndpoint?</strong></p>
  
  <p>After finding some related posts on the Spring forum and Stackoverflow, it seems that return objects need to either have the XmlRootElement annotation or be wrapped in a JAXBElement.  To try the first, I changed the response in the XSD to:</p>
  
  <pre><code>&lt;!-- Response definition --&gt;
  &lt;element name="ServiceResponse"&gt;
      &lt;complexType&gt;
          &lt;sequence&gt;
              &lt;element name="FileSize" type="long"/&gt;
          &lt;/sequence&gt;
      &lt;/complexType&gt;
  &lt;/element&gt;  
  </code></pre>
  
  <p>That works, as JAXB then generates a ServiceResponse class which has the XmlRootElement annotation.  Unfortuantely, I don't necessarily have the latitude the alter the XSD - which means I need to pursue the other option.  So I tried that.  My new service method looks like this:</p>
  
  <pre><code>@PayloadRoot( localPart = SERVICE_REQUEST, namespace = NAMESPACE )
  public JAXBElement&lt;Outcome&gt; processFileRequest( ServiceRequest requestObject )
  </code></pre>
  
  <p>And I then wrap my return object using the method that was created on ObjectFactory:</p>
  
  <pre><code>/**
   * Create an instance of {@link JAXBElement }{@code &lt;}{@link Outcome }{@code &gt;}}
   * 
   */
  @XmlElementDecl(namespace = "http://www.dortman.com/MyTestService", name = "ServiceResponse")
  public JAXBElement&lt;Outcome&gt; createServiceResponse(Outcome value) {
      return new JAXBElement&lt;Outcome&gt;(_ServiceResponse_QNAME, Outcome.class, null, value);
  }
  </code></pre>
  
  <p>I file up the server expecting this to resolve the problem.  But instead I get:</p>
  
  <p><strong>java.lang.IllegalStateException:
  No adapter for endpoint [public javax.xml.bind.JAXBElement dortman.annotated.MyTestEndpoint.processFileRequest(dortman.xsd.objects.ServiceRequest)]:
  Does your endpoint implement a supported interface like MessageHandler or PayloadEndpoint?
          at org.springframework.ws.server.MessageDispatcher.getEndpointAdapter(MessageDispatcher.java:283)
          at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:226)
          at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:169)
          at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection 
  (WebServiceMessageReceiverObjectSupport.java:89)
          at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle 
  (WebServiceMessageReceiverHandlerAdapter.java:57)
          at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:231)
          at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
          at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
          at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
          at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)</strong></p>
  
  <p>Apparently it was not impressed by my use of JAXBElement.  Has anybody else encountered this problem?</p>
  
  <p>My configuration file (which is already working with ~6 web services, it's just that none of them exhibit this particular XSD variation) contains the following:</p>
  
  <pre><code>&lt;!-- JAXB marshaller to be used by the annotated web services --&gt;
  &lt;bean class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter"&gt;
  &lt;constructor-arg&gt;
  &lt;bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
    &lt;property name="contextPath" value="dortman.xsd.objects" /&gt;
    &lt;property name="mtomEnabled" value="true"/&gt;
  &lt;/bean&gt; 
  &lt;/constructor-arg&gt;
  &lt;/bean&gt; 
  
  &lt;bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"&gt;
  &lt;property name="payloadCaching" value="true"&gt;&lt;/property&gt;
  &lt;property name="attachmentCaching" value="true"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>