Results 1 to 2 of 2

Thread: Changing response from "void" to "Element"

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    18

    Thumbs up Changing response from "void" to "Element"

    I'm trying to expand the example from:
    http://static.springsource.org/sprin.../tutorial.html
    The example assumes no response is returned. I want to return a simple response including a success flag and an additional error string. I've defined the response type element in the xsd file and now I'm trying to modify the code to return a response.

    Code:
    @Endpoint
    public class HolidayEndpoint {
    ......................
    @Autowired
      public HolidayEndpoint(HumanResourceService humanResourceService)
          throws JDOMException {
    .........
        }
    
      @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
      public void handleHolidayRequest(@RequestPayload Element holidayRequest)
          throws Exception {
        
    /*---- pare holidayRequest and invoke the service ----/*
    }
    I modified the handleHolidayRequest changing the return type to "Element" and manually constructing the Element object as the return value.

    Code:
      @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
      public Element handleHolidayRequest(@RequestPayload Element holidayRequest)
          throws Exception {
    
        /*---- pare holidayRequest and invoke the service ----/*
    
        Element responseElement = null;
        responseElement = new Element("HolidayResponse");
        responseElement.setAttribute("value", response.getValue().toString());
        responseElement.setAttribute("responseString", response.getResponseMessage());
        return responseElement;
      }
    The code compiles fine. However, when trying to invoke the web service I get a Soap fault:
    Code:
    <SOAP-ENV:Fault>
             <faultcode>SOAP-ENV:Server</faultcode>
             <faultstring xml:lang="en">
             No adapter for endpoint [public org.jdom.Element 
             com.mycompany.hr.ws.HolidayEndpoint.handleHolidayRequest(org.jdom.Element) throws java.lang.Exception]: 
             Is your endpoint annotated with @Endpoint, or does it implement a supported interface like
             MessageHandler or PayloadEndpoint?</faultstring>
    </SOAP-ENV:Fault>
    Any advice? Please note that I got the original example to work just fine.

  2. #2
    Join Date
    May 2010
    Posts
    18

    Default return object must be annotated with @ResponsePayload when annotations are used

    I just learned that when annotations are used then both the request and response parameters must be annotated with @RequestPyload and @ResponsePayload respectively.

    Also, as a side note I was constructing the response incorrectly, ignoring the namespace. The correct way to create response would be:

    Namespace namespace = Namespace.getNamespace("hr",MY_NAMESPACE_URI);
    responseElement = new Element("HolidayResponse", namespace);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •