Search in sources :

Example 1 with SlingServletResponseAdapter

use of org.apache.sling.engine.impl.adapter.SlingServletResponseAdapter in project sling by apache.

the class RequestData method toSlingHttpServletResponse.

/**
     * @param response
     * @throws IllegalArgumentException if <code>response</code> is not a
     *             <code>HttpServletResponse</code> of if
     *             <code>response</code> is not backed by
     *             <code>SlingHttpServletResponseImpl</code>.
     */
public static SlingHttpServletResponse toSlingHttpServletResponse(ServletResponse response) {
    // unwrap to SlingHttpServletResponse
    SlingHttpServletResponse cResponse = unwrap(response);
    // check type of response, don't care actually for the response itself
    RequestData.unwrap(cResponse);
    // are done
    if (cResponse == response) {
        return cResponse;
    }
    // ensure the response is a HTTP response
    if (!(response instanceof HttpServletResponse)) {
        throw new IllegalArgumentException("Response is not an HTTP response");
    }
    // and unwrapped component response
    return new SlingServletResponseAdapter(cResponse, (HttpServletResponse) response);
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) SlingServletResponseAdapter(org.apache.sling.engine.impl.adapter.SlingServletResponseAdapter)

Aggregations

HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 SlingServletResponseAdapter (org.apache.sling.engine.impl.adapter.SlingServletResponseAdapter)1