Search in sources :

Example 1 with SlingServletRequestAdapter

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

the class RequestData method toSlingHttpServletRequest.

/**
     * @param request
     * @throws IllegalArgumentException if <code>request</code> is not a
     *             <code>HttpServletRequest</code> of if <code>request</code>
     *             is not backed by <code>SlingHttpServletRequestImpl</code>.
     */
public static SlingHttpServletRequest toSlingHttpServletRequest(ServletRequest request) {
    // unwrap to SlingHttpServletRequest, may throw if no
    // SlingHttpServletRequest is wrapped in request
    SlingHttpServletRequest cRequest = unwrap(request);
    // ensure the SlingHttpServletRequest is backed by
    // SlingHttpServletRequestImpl
    RequestData.unwrap(cRequest);
    // if the request is not wrapper at all, we are done
    if (cRequest == request) {
        return cRequest;
    }
    // ensure the request is a HTTP request
    if (!(request instanceof HttpServletRequest)) {
        throw new IllegalArgumentException("Request is not an HTTP request");
    }
    // and unwrapped component response
    return new SlingServletRequestAdapter(cRequest, (HttpServletRequest) request);
}
Also used : SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SlingServletRequestAdapter(org.apache.sling.engine.impl.adapter.SlingServletRequestAdapter) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 SlingServletRequestAdapter (org.apache.sling.engine.impl.adapter.SlingServletRequestAdapter)1