public RequestContext(Http.Request request) { final ProtectedData protectedData = GlobalHost.getDependencyResolver().getService(ProtectedData.class); final String connectionToken = request.getQueryString("connectionToken"); final String decryptedToken = protectedData.unprotect(connectionToken, Purposes.ConnectionToken).get(); connectionId = UUID.fromString(decryptedToken.substring(0, decryptedToken.lastIndexOf(':'))); username = decryptedToken.substring(decryptedToken.indexOf(':') + 1); final String connectionData = request.getQueryString("connectionData"); hubName = getHubName(connectionData); queryString = getQueryParams(request.queryString()); messageId = Optional.empty(); }
protected Map<String, String> requestData(Http.Request request) { Map<String, String[]> urlFormEncoded = new HashMap<>(); if (request.body().asFormUrlEncoded() != null) { urlFormEncoded = request.body().asFormUrlEncoded(); } Map<String, String[]> multipartFormData = new HashMap<>(); if (request.body().asMultipartFormData() != null) { multipartFormData = request.body().asMultipartFormData().asFormUrlEncoded(); } Map<String, String> jsonData = new HashMap<>(); if (request.body().asJson() != null) { jsonData = play.libs.Scala.asJava( play.api.data.FormUtils.fromJson( "", play.api.libs.json.Json.parse( play.libs.Json.stringify(request.body().asJson())))); } Map<String, String[]> queryString = request.queryString(); Map<String, String> data = new HashMap<>(); for (String key : urlFormEncoded.keySet()) { String[] values = urlFormEncoded.get(key); if (key.endsWith("[]")) { String k = key.substring(0, key.length() - 2); for (int i = 0; i < values.length; i++) { data.put(k + "[" + i + "]", values[i]); } } else { if (values.length > 0) { data.put(key, values[0]); } } } for (String key : multipartFormData.keySet()) { String[] values = multipartFormData.get(key); if (key.endsWith("[]")) { String k = key.substring(0, key.length() - 2); for (int i = 0; i < values.length; i++) { data.put(k + "[" + i + "]", values[i]); } } else { if (values.length > 0) { data.put(key, values[0]); } } } for (String key : jsonData.keySet()) { data.put(key, jsonData.get(key)); } for (String key : queryString.keySet()) { String[] values = queryString.get(key); if (key.endsWith("[]")) { String k = key.substring(0, key.length() - 2); for (int i = 0; i < values.length; i++) { data.put(k + "[" + i + "]", values[i]); } } else { if (values.length > 0) { data.put(key, values[0]); } } } return data; }