use of io.kamax.mxisd.proxy.Response in project mxisd by kamax-io.
the class ProfileManager method enhance.
public Response enhance(_MatrixID userId, HttpRequestBase request) {
try {
request.setURI(dns.transform(request.getURI()).build());
Response res = new Response();
try (CloseableHttpResponse hsResponse = client.execute(request)) {
res.setStatus(hsResponse.getStatusLine().getStatusCode());
JsonElement el = GsonUtil.parse(EntityUtils.toString(hsResponse.getEntity()));
if (el.isJsonObject()) {
JsonObject obj = el.getAsJsonObject();
List<_ThreePid> list = getThreepids(userId);
obj.add("threepids", GsonUtil.get().toJsonTree(list));
}
res.setBody(GsonUtil.get().toJson(el));
return res;
} catch (IOException e) {
throw new RuntimeException(e);
}
} catch (URISyntaxException e) {
log.error("Unable to build target URL for profile proxy enhancement", e);
throw new InternalServerError(e);
}
}
use of io.kamax.mxisd.proxy.Response in project mxisd by kamax-io.
the class ProfileHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) {
String userId = getQueryParameter(exchange, UserID);
_MatrixID mxId = MatrixID.asAcceptable(userId);
URI target = URI.create(exchange.getRequestURL());
Optional<String> accessTokenOpt = findAccessToken(exchange);
HttpGet reqOut = new HttpGet(target);
accessTokenOpt.ifPresent(accessToken -> reqOut.addHeader(headerName, headerValuePrefix + accessToken));
Response res = mgr.enhance(mxId, reqOut);
respond(exchange, res);
}
Aggregations