use of io.kamax.mxisd.http.io.identity.StoreInviteRequest in project mxisd by kamax-io.
the class StoreInviteHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) {
String reqContentType = getContentType(exchange).orElse("application/octet-stream");
JsonObject invJson = new JsonObject();
if (StringUtils.startsWith(reqContentType, "application/json")) {
invJson = parseJsonObject(exchange);
} else // Backward compatibility for pre-r0.1.0 implementations
if (StringUtils.startsWith(reqContentType, "application/x-www-form-urlencoded")) {
String body = getBodyUtf8(exchange);
Map<String, Deque<String>> parms = QueryParameterUtils.parseQueryString(body, StandardCharsets.UTF_8.name());
for (Map.Entry<String, Deque<String>> entry : parms.entrySet()) {
if (entry.getValue().size() == 0) {
return;
}
if (entry.getValue().size() > 1) {
throw new BadRequestException("key " + entry.getKey() + " has more than one value");
}
invJson.addProperty(entry.getKey(), entry.getValue().peekFirst());
}
} else {
throw new BadRequestException("Unsupported Content-Type: " + reqContentType);
}
Type parmType = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> parameters = GsonUtil.get().fromJson(invJson, parmType);
StoreInviteRequest inv = GsonUtil.get().fromJson(invJson, StoreInviteRequest.class);
_MatrixID sender = MatrixID.asAcceptable(inv.getSender());
IThreePidInvite invite = new ThreePidInvite(sender, inv.getMedium(), inv.getAddress(), inv.getRoomId(), parameters);
IThreePidInviteReply reply = invMgr.storeInvite(invite);
// FIXME the key info must be set by the invitation manager in the reply object!
respondJson(exchange, new ThreePidInviteReplyIO(reply, keyMgr.getPublicKeyBase64(keyMgr.getServerSigningKey().getId()), cfg.getPublicUrl()));
}
Aggregations