Search in sources :

Example 6 with Request

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

the class AbstractAnnotationHandler method isCompatible.

@Override
public boolean isCompatible(Object source) {
    String contentType = null;
    Map<String, String> params = null;
    Request req = HttpManager.request();
    if (req != null) {
        contentType = req.getContentTypeHeader();
        params = req.getParams();
    }
    ControllerMethod m = getBestMethod(source.getClass(), contentType, params, null);
    return m != null;
}
Also used : Request(io.milton.http.Request)

Example 7 with Request

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

the class JsonResourceFactory method getResource.

@Override
public Resource getResource(String host, String sPath) throws NotAuthorizedException, BadRequestException {
    LogUtils.trace(log, "getResource", host, sPath);
    Path path = Path.path(sPath);
    Path parent = path.getParent();
    Request request = HttpManager.request();
    String encodedPath = request.getAbsolutePath();
    if (isMatchingPath(parent)) {
        log.trace("getResource: is matching path");
        Path resourcePath = parent.getParent();
        if (resourcePath != null) {
            String method = path.getName();
            Resource wrappedResource = wrapped.getResource(host, resourcePath.toString());
            if (wrappedResource != null) {
                Resource r = wrapResource(host, wrappedResource, method, encodedPath);
                LogUtils.trace(log, "returning a", r.getClass());
                return r;
            }
        }
    } else if (isAjaxLoginPath(sPath)) {
        Resource h = wrapped.getResource(host, "/");
        if (h == null) {
            log.info("Found a login path, but couldnt get a root resource to delegate login to");
            return null;
        } else {
            return new AjaxLoginResource(sPath, h);
        }
    } else {
        log.trace("getResource: not matching path");
        return wrapped.getResource(host, sPath);
    }
    return null;
}
Also used : Path(io.milton.common.Path) Request(io.milton.http.Request)

Example 8 with Request

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

the class PropFindJsonResource method getMaxAgeSeconds.

/**
 * Overridden to allow clients to specifiy the max age as a request parameter
 *
 * This is to allow efficient browser caching of results in cases that need it,
 * while also permitting non-cached access
 *
 * @param auth
 * @return
 */
@Override
public Long getMaxAgeSeconds(Auth auth) {
    Request req = HttpManager.request();
    if (req != null) {
        String sMaxAge = req.getParams().get("maxAgeSecs");
        if (sMaxAge != null && sMaxAge.length() > 0) {
            try {
                log.trace("using max age from parameter");
                Long maxAge = Long.parseLong(sMaxAge);
                return maxAge;
            } catch (NumberFormatException e) {
                log.debug("Couldnt parse max age parameter: " + sMaxAge);
            }
        }
    }
    return super.getMaxAgeSeconds(auth);
}
Also used : Request(io.milton.http.Request)

Example 9 with Request

use of io.milton.http.Request 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 10 with Request

use of io.milton.http.Request 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)12 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 JsonResult (io.milton.common.JsonResult)1 Path (io.milton.common.Path)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 ContentManager (org.polymap.service.fs.ContentManager)1 IContentNode (org.polymap.service.fs.spi.IContentNode)1