use of com.meterware.servletunit.InvocationContext in project teammates by TEAMMATES.
the class GaeSimulation method createWebRequest.
private HttpServletRequest createWebRequest(String uri, String... parameters) {
WebRequest request = new PostMethodWebRequest("http://localhost" + uri);
if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) {
request.setHeaderField("referer", "http://localhost");
String sessionId = sc.getSession(true).getId();
String token = CryptoHelper.computeSessionToken(sessionId);
request.setParameter(Const.ParamsNames.SESSION_TOKEN, token);
}
Map<String, List<String>> paramMultiMap = new HashMap<>();
for (int i = 0; i < parameters.length; i = i + 2) {
String key = parameters[i];
if (paramMultiMap.get(key) == null) {
paramMultiMap.put(key, new ArrayList<String>());
}
paramMultiMap.get(key).add(parameters[i + 1]);
}
paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[0])));
try {
InvocationContext ic = sc.newInvocation(request);
return ic.getRequest();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations