Search in sources :

Example 1 with NotImplementedException

use of io.kamax.mxisd.exception.NotImplementedException in project mxisd by kamax-io.

the class PhoneSmsTwilioConnector method send.

@Override
public void send(String recipient, String content) {
    if (StringUtils.isBlank(cfg.getAccountSid()) || StringUtils.isBlank(cfg.getAuthToken()) || StringUtils.isBlank(cfg.getNumber())) {
        log.error("Twilio connector in not fully configured and is missing mandatory configuration values.");
        throw new NotImplementedException("Phone numbers cannot be validated at this time. Contact your administrator.");
    }
    recipient = "+" + recipient;
    log.info("Sending SMS notification from {} to {} with {} characters", cfg.getNumber(), recipient, content.length());
    try {
        Message.creator(new PhoneNumber("+" + recipient), new PhoneNumber(cfg.getNumber()), content).create();
    } catch (ApiException e) {
        throw new InternalServerError(e);
    }
}
Also used : NotImplementedException(io.kamax.mxisd.exception.NotImplementedException) PhoneNumber(com.twilio.type.PhoneNumber) InternalServerError(io.kamax.mxisd.exception.InternalServerError) ApiException(com.twilio.exception.ApiException)

Example 2 with NotImplementedException

use of io.kamax.mxisd.exception.NotImplementedException in project mxisd by kamax-io.

the class RegistrationManager method execute.

public RegistrationReply execute(URI target, JsonObject request) {
    HttpPost registerProxyRq = RestClientUtils.post(resolveProxyUrl(target), GsonUtil.get(), request);
    try (CloseableHttpResponse response = client.execute(registerProxyRq)) {
        int status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            // The user managed to register. We check if it had a session
            String sessionId = GsonUtil.findObj(request, "auth").flatMap(auth -> GsonUtil.findString(auth, "session")).orElse("");
            if (StringUtils.isEmpty(sessionId)) {
                // No session ID was provided. This is an edge case we do not support for now as investigation is needed
                // to ensure how and when this happens.
                HttpPost newSessReq = RestClientUtils.post(resolveProxyUrl(target), GsonUtil.get(), new JsonObject());
                try (CloseableHttpResponse newSessRes = client.execute(newSessReq)) {
                    RegistrationReply reply = new RegistrationReply();
                    reply.setStatus(newSessRes.getStatusLine().getStatusCode());
                    reply.setBody(GsonUtil.parseObj(EntityUtils.toString(newSessRes.getEntity())));
                    return reply;
                }
            }
        }
        throw new NotImplementedException("Registration");
    } catch (IOException e) {
        throw new RemoteHomeServerException(e.getMessage());
    }
}
Also used : JsonObject(com.google.gson.JsonObject) HttpPost(org.apache.http.client.methods.HttpPost) GsonUtil(io.kamax.matrix.json.GsonUtil) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Logger(org.slf4j.Logger) URIBuilder(org.apache.http.client.utils.URIBuilder) LoggerFactory(org.slf4j.LoggerFactory) RegisterConfig(io.kamax.mxisd.config.RegisterConfig) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) NotImplementedException(io.kamax.mxisd.exception.NotImplementedException) ThreePid(io.kamax.matrix.ThreePid) EntityUtils(org.apache.http.util.EntityUtils) RestClientUtils(io.kamax.mxisd.util.RestClientUtils) Objects(java.util.Objects) Matcher(java.util.regex.Matcher) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) InvitationManager(io.kamax.mxisd.invitation.InvitationManager) URI(java.net.URI) Pattern(java.util.regex.Pattern) ClientDnsOverwrite(io.kamax.mxisd.dns.ClientDnsOverwrite) RemoteHomeServerException(io.kamax.mxisd.exception.RemoteHomeServerException) HttpPost(org.apache.http.client.methods.HttpPost) RemoteHomeServerException(io.kamax.mxisd.exception.RemoteHomeServerException) NotImplementedException(io.kamax.mxisd.exception.NotImplementedException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

NotImplementedException (io.kamax.mxisd.exception.NotImplementedException)2 JsonObject (com.google.gson.JsonObject)1 ApiException (com.twilio.exception.ApiException)1 PhoneNumber (com.twilio.type.PhoneNumber)1 ThreePid (io.kamax.matrix.ThreePid)1 GsonUtil (io.kamax.matrix.json.GsonUtil)1 RegisterConfig (io.kamax.mxisd.config.RegisterConfig)1 ClientDnsOverwrite (io.kamax.mxisd.dns.ClientDnsOverwrite)1 InternalServerError (io.kamax.mxisd.exception.InternalServerError)1 RemoteHomeServerException (io.kamax.mxisd.exception.RemoteHomeServerException)1 InvitationManager (io.kamax.mxisd.invitation.InvitationManager)1 RestClientUtils (io.kamax.mxisd.util.RestClientUtils)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Objects (java.util.Objects)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1