Search in sources :

Example 1 with Response

use of io.milton.http.Response in project lobcder by skoulouzis.

the class SpringAwareMiltonServlet method service.

@Override
public void service(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    try {
        originalRequest.set(req);
        originalResponse.set(resp);
        Request request = new ServletRequest(req, servletContext);
        Response response = new ServletResponse(resp);
        httpManager.process(request, response);
    } finally {
        originalRequest.remove();
        originalResponse.remove();
        servletResponse.getOutputStream().flush();
        servletResponse.flushBuffer();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(io.milton.http.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Request(io.milton.http.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 2 with Response

use of io.milton.http.Response in project lobcder by skoulouzis.

the class SpringMiltonFilter method doMiltonProcessing.

private void doMiltonProcessing(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {
        MiltonServlet.setThreadlocals(req, resp);
        Request request = new io.milton.servlet.ServletRequest(req, servletContext);
        Response response = new io.milton.servlet.ServletResponse(resp);
        httpManager.process(request, response);
    } finally {
        MiltonServlet.clearThreadlocals();
        resp.getOutputStream().flush();
        resp.flushBuffer();
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Response(io.milton.http.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(io.milton.http.Request)

Example 3 with Response

use of io.milton.http.Response in project polymap4-core by Polymap4.

the class WebDavServer method service.

public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
    Timer timer = new Timer();
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    DefaultSessionContextProvider contextProvider = FsPlugin.getDefault().sessionContextProvider;
    try {
        Request request = new io.milton.servlet.ServletRequest(req, servletRequest.getServletContext());
        Response response = new io.milton.servlet.ServletResponse(resp);
        threadRequest.set(request);
        threadResponse.set(response);
        Auth auth = request.getAuthorization();
        log.debug("Auth: " + auth);
        // map/create session context
        req.getSession(true);
        if (auth != null) {
            contextProvider.mapContext(auth.getUser(), true);
            log.debug("SessionContext: " + SessionContext.current());
        }
        httpManager.process(request, response);
        log.debug("Request: " + Request.Header.ACCEPT_ENCODING.code + ": " + request.getHeaders().get(Request.Header.ACCEPT_ENCODING.code) + " --> Response: " + Response.Header.CONTENT_ENCODING.code + ": " + response.getHeaders().get(Response.Header.CONTENT_ENCODING.code));
        log.debug("Response: " + response.getStatus());
    } finally {
        if (contextProvider.currentContext() != null) {
            contextProvider.unmapContext();
        }
        threadRequest.set(null);
        threadResponse.set(null);
        servletResponse.getOutputStream().flush();
        servletResponse.flushBuffer();
    }
    log.info("WebDAV request: " + timer.elapsedTime() + "ms");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Response(io.milton.http.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Timer(org.polymap.core.runtime.Timer) Auth(io.milton.http.Auth) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(io.milton.http.Request) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultSessionContextProvider(org.polymap.core.runtime.session.DefaultSessionContextProvider)

Example 4 with Response

use of io.milton.http.Response in project lobcder by skoulouzis.

the class AnnotationResourceFactory method findArgValue.

private Object findArgValue(Class type, Request request, Response response, List otherAvailValues) throws Exception {
    if (type == Request.class) {
        return request;
    } else if (type == Response.class) {
        return response;
    } else if (type == byte[].class) {
        InputStream in = (InputStream) findArgValue(InputStream.class, request, response, otherAvailValues);
        return toBytes(in);
    } else {
        for (Object o : otherAvailValues) {
            // System.out.println("is assignable: " + o + " == " + type + " = " + o.getClass().isAssignableFrom(type) );
            if (o != null && type.isAssignableFrom(o.getClass())) {
                // remove it so that we dont use same value for next param of same type
                otherAvailValues.remove(o);
                return o;
            }
        }
    }
    log.error("Unknown parameter type: " + type);
    log.error("Available types are:");
    log.error(" - " + Request.class);
    log.error(" - " + Response.class);
    for (Object o : otherAvailValues) {
        if (o != null) {
            log.error(" - " + o.getClass());
        } else {
            log.error(" - null");
        }
    }
    throw new UnresolvableParameterException("Couldnt find parameter of type: " + type);
}
Also used : Response(io.milton.http.Response) InputStream(java.io.InputStream) Request(io.milton.http.Request)

Example 5 with Response

use of io.milton.http.Response in project lobcder by skoulouzis.

the class AnnotationResourceFactory method buildInvokeArgs.

/**
 * @param source
 * @param m
 * @param otherValues - any other values to be provided which can be mapped
 * onto method arguments
 * @return
 * @throws Exception
 */
public Object[] buildInvokeArgs(AnnoResource sourceRes, java.lang.reflect.Method m, Object... otherValues) throws Exception {
    Request request = HttpManager.request();
    Response response = HttpManager.response();
    Object[] args = new Object[m.getParameterTypes().length];
    List list = new ArrayList();
    // put this resource and all its parents on the stack
    AnnoResource r = sourceRes;
    while (r != null) {
        // First argument MUST be the source object!!!
        list.add(r.getSource());
        list.add(r);
        r = r.getParent();
    }
    for (Object s : otherValues) {
        list.add(s);
    }
    for (int i = 0; i < m.getParameterTypes().length; i++) {
        Class type = m.getParameterTypes()[i];
        Object argValue;
        try {
            argValue = findArgValue(type, request, response, list);
        } catch (UnresolvableParameterException e) {
            // System.out.println("Couldnt find parameter " + type + " for method: " + m);
            argValue = null;
        }
        args[i] = argValue;
    }
    return args;
}
Also used : Response(io.milton.http.Response) Request(io.milton.http.Request) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) AccessControlList(io.milton.annotations.AccessControlList)

Aggregations

Request (io.milton.http.Request)7 Response (io.milton.http.Response)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 AccessControlList (io.milton.annotations.AccessControlList)1 Auth (io.milton.http.Auth)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 javax.servlet (javax.servlet)1 Timer (org.polymap.core.runtime.Timer)1 DefaultSessionContextProvider (org.polymap.core.runtime.session.DefaultSessionContextProvider)1