Skip to content

Commit

Permalink
RESTCOMM-1785: Add notification when inboundSMS SMPP is blocked. Dupl…
Browse files Browse the repository at this point in the history
…icate notification() from SMSService.
  • Loading branch information
abdulazizali77 committed Feb 27, 2018
1 parent 9d63e11 commit da1ca52
Showing 1 changed file with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;

Expand All @@ -30,6 +31,7 @@
import javax.servlet.sip.SipURI;

import org.apache.commons.configuration.Configuration;
import org.joda.time.DateTime;
import org.restcomm.connect.commons.configuration.RestcommConfiguration;
import org.restcomm.connect.commons.configuration.sets.RcmlserverConfigurationSet;
import org.restcomm.connect.commons.dao.Sid;
Expand All @@ -38,9 +40,11 @@
import org.restcomm.connect.dao.AccountsDao;
import org.restcomm.connect.dao.ApplicationsDao;
import org.restcomm.connect.dao.DaoManager;
import org.restcomm.connect.dao.NotificationsDao;
import org.restcomm.connect.dao.common.OrganizationUtil;
import org.restcomm.connect.dao.entities.Application;
import org.restcomm.connect.dao.entities.IncomingPhoneNumber;
import org.restcomm.connect.dao.entities.Notification;
import org.restcomm.connect.extension.api.ExtensionResponse;
//import org.restcomm.connect.extension.api.ExtensionRequest;
//import org.restcomm.connect.extension.api.ExtensionResponse;
Expand Down Expand Up @@ -94,6 +98,9 @@ public class SmppMessageHandler extends RestcommUntypedActor {
//List of extensions for SmsService
List<RestcommExtensionGeneric> extensions;

private static final int ERROR_NOTIFICATION = 0;
private static final int WARNING_NOTIFICATION = 1;

public SmppMessageHandler(final ServletContext servletContext) {
this.servletContext = servletContext;
this.storage = (DaoManager) servletContext.getAttribute(DaoManager.class.getName());
Expand Down Expand Up @@ -230,11 +237,13 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SmppInboundMes
final String errMsg = "Inbound SMS is not Allowed";
logger.debug(errMsg);
}
//TODO: Notifications API and idioms need to be cleaned up across whole RC
String errMsg = "Inbound SMS to Number: " + number.getPhoneNumber()
+ " is not allowed";
//sendNotification(errMsg, 11001, "warning", true);
//final SipServletResponse resp = request.createResponse(SC_FORBIDDEN, "SMS not allowed");
//resp.send();
final NotificationsDao notifications = storage.getNotificationsDao();
final Notification notification = notification(WARNING_NOTIFICATION, 11001, errMsg);
notifications.addNotification(notification);
//TODO: implement DLR here
ec.executePostOutboundAction(far, extensions);
return false;
}
Expand Down Expand Up @@ -320,4 +329,52 @@ public void outbound(SmppOutboundMessageEntity request) throws SmppInvalidArgume
logger.error("SMPP message cannot be sent : " + e );
}
}

//TODO: Notifications API and idioms need to be cleaned up across whole RC
//FIXME: duplicate of SmsService
private Notification notification(final int log, final int error, final String message) {
String version = configuration.subset("runtime-settings").getString("api-version");
Sid accountId = new Sid("ACae6e420f425248d6a26948c17a9e2acf");
// Sid callSid = new Sid("CA00000000000000000000000000000000");
final Notification.Builder builder = Notification.builder();
final Sid sid = Sid.generate(Sid.Type.NOTIFICATION);
builder.setSid(sid);
// builder.setAccountSid(accountId);
builder.setAccountSid(accountId);
// builder.setCallSid(callSid);
builder.setApiVersion(version);
builder.setLog(log);
builder.setErrorCode(error);
final String base = configuration.subset("runtime-settings").getString("error-dictionary-uri");
StringBuilder buffer = new StringBuilder();
buffer.append(base);
if (!base.endsWith("/")) {
buffer.append("/");
}
buffer.append(error).append(".html");
final URI info = URI.create(buffer.toString());
builder.setMoreInfo(info);
builder.setMessageText(message);
final DateTime now = DateTime.now();
builder.setMessageDate(now);
try {
builder.setRequestUrl(new URI(""));
} catch (URISyntaxException e) {
e.printStackTrace();
}
/**
* if (response != null) { builder.setRequestUrl(request.getUri()); builder.setRequestMethod(request.getMethod());
* builder.setRequestVariables(request.getParametersAsString()); }
**/

builder.setRequestMethod("");
builder.setRequestVariables("");
buffer = new StringBuilder();
buffer.append("/").append(version).append("/Accounts/");
buffer.append(accountId.toString()).append("/Notifications/");
buffer.append(sid.toString());
final URI uri = URI.create(buffer.toString());
builder.setUri(uri);
return builder.build();
}
}

0 comments on commit da1ca52

Please sign in to comment.