|
21 | 21 |
|
22 | 22 | import java.io.IOException; |
23 | 23 | import java.net.URI; |
| 24 | +import java.net.URISyntaxException; |
24 | 25 | import java.util.Collection; |
25 | 26 | import java.util.List; |
26 | 27 |
|
|
30 | 31 | import javax.servlet.sip.SipURI; |
31 | 32 |
|
32 | 33 | import org.apache.commons.configuration.Configuration; |
| 34 | +import org.joda.time.DateTime; |
33 | 35 | import org.restcomm.connect.commons.configuration.RestcommConfiguration; |
34 | 36 | import org.restcomm.connect.commons.configuration.sets.RcmlserverConfigurationSet; |
35 | 37 | import org.restcomm.connect.commons.dao.Sid; |
|
38 | 40 | import org.restcomm.connect.dao.AccountsDao; |
39 | 41 | import org.restcomm.connect.dao.ApplicationsDao; |
40 | 42 | import org.restcomm.connect.dao.DaoManager; |
| 43 | +import org.restcomm.connect.dao.NotificationsDao; |
41 | 44 | import org.restcomm.connect.dao.common.OrganizationUtil; |
42 | 45 | import org.restcomm.connect.dao.entities.Application; |
43 | 46 | import org.restcomm.connect.dao.entities.IncomingPhoneNumber; |
| 47 | +import org.restcomm.connect.dao.entities.Notification; |
44 | 48 | import org.restcomm.connect.extension.api.ExtensionResponse; |
45 | 49 | //import org.restcomm.connect.extension.api.ExtensionRequest; |
46 | 50 | //import org.restcomm.connect.extension.api.ExtensionResponse; |
@@ -94,6 +98,9 @@ public class SmppMessageHandler extends RestcommUntypedActor { |
94 | 98 | //List of extensions for SmsService |
95 | 99 | List<RestcommExtensionGeneric> extensions; |
96 | 100 |
|
| 101 | + private static final int ERROR_NOTIFICATION = 0; |
| 102 | + private static final int WARNING_NOTIFICATION = 1; |
| 103 | + |
97 | 104 | public SmppMessageHandler(final ServletContext servletContext) { |
98 | 105 | this.servletContext = servletContext; |
99 | 106 | this.storage = (DaoManager) servletContext.getAttribute(DaoManager.class.getName()); |
@@ -230,11 +237,13 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SmppInboundMes |
230 | 237 | final String errMsg = "Inbound SMS is not Allowed"; |
231 | 238 | logger.debug(errMsg); |
232 | 239 | } |
| 240 | + //TODO: Notifications API and idioms need to be cleaned up across whole RC |
233 | 241 | String errMsg = "Inbound SMS to Number: " + number.getPhoneNumber() |
234 | 242 | + " is not allowed"; |
235 | | - //sendNotification(errMsg, 11001, "warning", true); |
236 | | - //final SipServletResponse resp = request.createResponse(SC_FORBIDDEN, "SMS not allowed"); |
237 | | - //resp.send(); |
| 243 | + final NotificationsDao notifications = storage.getNotificationsDao(); |
| 244 | + final Notification notification = notification(WARNING_NOTIFICATION, 11001, errMsg); |
| 245 | + notifications.addNotification(notification); |
| 246 | + //TODO: implement DLR here |
238 | 247 | ec.executePostOutboundAction(far, extensions); |
239 | 248 | return false; |
240 | 249 | } |
@@ -320,4 +329,52 @@ public void outbound(SmppOutboundMessageEntity request) throws SmppInvalidArgume |
320 | 329 | logger.error("SMPP message cannot be sent : " + e ); |
321 | 330 | } |
322 | 331 | } |
| 332 | + |
| 333 | + //TODO: Notifications API and idioms need to be cleaned up across whole RC |
| 334 | + //FIXME: duplicate of SmsService |
| 335 | + private Notification notification(final int log, final int error, final String message) { |
| 336 | + String version = configuration.subset("runtime-settings").getString("api-version"); |
| 337 | + Sid accountId = new Sid("ACae6e420f425248d6a26948c17a9e2acf"); |
| 338 | + // Sid callSid = new Sid("CA00000000000000000000000000000000"); |
| 339 | + final Notification.Builder builder = Notification.builder(); |
| 340 | + final Sid sid = Sid.generate(Sid.Type.NOTIFICATION); |
| 341 | + builder.setSid(sid); |
| 342 | + // builder.setAccountSid(accountId); |
| 343 | + builder.setAccountSid(accountId); |
| 344 | + // builder.setCallSid(callSid); |
| 345 | + builder.setApiVersion(version); |
| 346 | + builder.setLog(log); |
| 347 | + builder.setErrorCode(error); |
| 348 | + final String base = configuration.subset("runtime-settings").getString("error-dictionary-uri"); |
| 349 | + StringBuilder buffer = new StringBuilder(); |
| 350 | + buffer.append(base); |
| 351 | + if (!base.endsWith("/")) { |
| 352 | + buffer.append("/"); |
| 353 | + } |
| 354 | + buffer.append(error).append(".html"); |
| 355 | + final URI info = URI.create(buffer.toString()); |
| 356 | + builder.setMoreInfo(info); |
| 357 | + builder.setMessageText(message); |
| 358 | + final DateTime now = DateTime.now(); |
| 359 | + builder.setMessageDate(now); |
| 360 | + try { |
| 361 | + builder.setRequestUrl(new URI("")); |
| 362 | + } catch (URISyntaxException e) { |
| 363 | + e.printStackTrace(); |
| 364 | + } |
| 365 | + /** |
| 366 | + * if (response != null) { builder.setRequestUrl(request.getUri()); builder.setRequestMethod(request.getMethod()); |
| 367 | + * builder.setRequestVariables(request.getParametersAsString()); } |
| 368 | + **/ |
| 369 | + |
| 370 | + builder.setRequestMethod(""); |
| 371 | + builder.setRequestVariables(""); |
| 372 | + buffer = new StringBuilder(); |
| 373 | + buffer.append("/").append(version).append("/Accounts/"); |
| 374 | + buffer.append(accountId.toString()).append("/Notifications/"); |
| 375 | + buffer.append(sid.toString()); |
| 376 | + final URI uri = URI.create(buffer.toString()); |
| 377 | + builder.setUri(uri); |
| 378 | + return builder.build(); |
| 379 | + } |
323 | 380 | } |
0 commit comments