Search code examples
javaweb-servicesapache-axis

How do I return custom HTTP response (400 or 401) from axis 2 web service (REST)?


Is there any way or API to return custom HTTP response from RESTful services using AXIS. All I want is to return custom http response such as 400 or 401 to client.


Solution

  • If still open... Here is the code about how the get the HTTPServletResponse object and set Status

    MessageContext responseMessageContext =  
        MessageContext.getCurrentMessageContext();
    HttpServletResponse resp =
        (HttpServletResponse) responseMessageContext.getProperty(
        org.apache.axis2.transport.http.HTTPConstants.MC_HTTP_SERVLETRESPONSE);
    resp.setStatus(422);
    

    Hope useful