a80bfaac by Ean Schuessler

Add support for cookies and headers

Refs: #8039
1 parent 33225dc9
......@@ -439,6 +439,14 @@ public class DirectControlServlet extends HttpServlet {
context.put("httpProtocol", request.getProtocol());
context.put("httpScheme", request.getScheme());
Enumeration headerNames = request.getHeaderNames();
Map<String, List> headerMap = new HashMap<String, List>();
while(headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
headerMap.put(headerName, Collections.list(request.getHeaders(headerName)));
}
context.put("httpHeaders", headerMap);
DispatchContext dctx = dispatcher.getDispatchContext();
ModelService model = dctx.getModelService(serviceName);
......@@ -452,6 +460,22 @@ public class DirectControlServlet extends HttpServlet {
Map<String, Object> result = dispatcher.runSync(serviceName, context);
if (result.get("httpHeaders") != null) {
Map<String, List<String>> headers = (Map<String,List<String>>) result.get("httpHeaders");
for (String headerName : (Set<String>) headers.keySet()) {
for (String value : headers.get(headerName)) {
response.addHeader(headerName, value);
}
}
}
if (result.get("httpCookies") != null) {
List<Cookie> cookies = (List<Cookie>) result.get("httpCookies");
for (Cookie cookie : cookies) {
response.addCookie(cookie);
}
}
result.remove("responseMessage");
Integer httpStatusCode = (Integer) result.remove("httpStatusCode");
int statusCode = httpStatusCode == null ? 200 : httpStatusCode.intValue();
......