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