Announcement Announcement Module
Collapse
No announcement yet.
Changing response from "void" to "Element" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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);

    Comment

    Working...
    X