Add support for cookies and headers
Refs: #8039
Showing
1 changed file
with
24 additions
and
0 deletions
... | @@ -439,6 +439,14 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -439,6 +439,14 @@ public class DirectControlServlet extends HttpServlet { |
439 | context.put("httpProtocol", request.getProtocol()); | 439 | context.put("httpProtocol", request.getProtocol()); |
440 | context.put("httpScheme", request.getScheme()); | 440 | context.put("httpScheme", request.getScheme()); |
441 | 441 | ||
442 | Enumeration headerNames = request.getHeaderNames(); | ||
443 | Map<String, List> headerMap = new HashMap<String, List>(); | ||
444 | while(headerNames.hasMoreElements()) { | ||
445 | String headerName = (String) headerNames.nextElement(); | ||
446 | headerMap.put(headerName, Collections.list(request.getHeaders(headerName))); | ||
447 | } | ||
448 | context.put("httpHeaders", headerMap); | ||
449 | |||
442 | DispatchContext dctx = dispatcher.getDispatchContext(); | 450 | DispatchContext dctx = dispatcher.getDispatchContext(); |
443 | ModelService model = dctx.getModelService(serviceName); | 451 | ModelService model = dctx.getModelService(serviceName); |
444 | 452 | ||
... | @@ -452,6 +460,22 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -452,6 +460,22 @@ public class DirectControlServlet extends HttpServlet { |
452 | 460 | ||
453 | Map<String, Object> result = dispatcher.runSync(serviceName, context); | 461 | Map<String, Object> result = dispatcher.runSync(serviceName, context); |
454 | 462 | ||
463 | if (result.get("httpHeaders") != null) { | ||
464 | Map<String, List<String>> headers = (Map<String,List<String>>) result.get("httpHeaders"); | ||
465 | for (String headerName : (Set<String>) headers.keySet()) { | ||
466 | for (String value : headers.get(headerName)) { | ||
467 | response.addHeader(headerName, value); | ||
468 | } | ||
469 | } | ||
470 | } | ||
471 | |||
472 | if (result.get("httpCookies") != null) { | ||
473 | List<Cookie> cookies = (List<Cookie>) result.get("httpCookies"); | ||
474 | for (Cookie cookie : cookies) { | ||
475 | response.addCookie(cookie); | ||
476 | } | ||
477 | } | ||
478 | |||
455 | result.remove("responseMessage"); | 479 | result.remove("responseMessage"); |
456 | Integer httpStatusCode = (Integer) result.remove("httpStatusCode"); | 480 | Integer httpStatusCode = (Integer) result.remove("httpStatusCode"); |
457 | int statusCode = httpStatusCode == null ? 200 : httpStatusCode.intValue(); | 481 | int statusCode = httpStatusCode == null ? 200 : httpStatusCode.intValue(); | ... | ... |
-
Please register or sign in to post a comment