Search in sources :

Example 1 with Response

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);
    }
}
Also used : Response(io.kamax.mxisd.proxy.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonElement(com.google.gson.JsonElement) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InternalServerError(io.kamax.mxisd.exception.InternalServerError)

Example 2 with Response

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);
}
Also used : Response(io.kamax.mxisd.proxy.Response) HttpGet(org.apache.http.client.methods.HttpGet) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID) URI(java.net.URI)

Aggregations

Response (io.kamax.mxisd.proxy.Response)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)1 io.kamax.matrix._ThreePid (io.kamax.matrix._ThreePid)1 InternalServerError (io.kamax.mxisd.exception.InternalServerError)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1