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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations