Use this client to send emails, text messages and letters using the GOV.UK Notify API.
Useful links:
Java client for the GOV.UK Notify API
Home Page: https://central.sonatype.com/artifact/uk.gov.service.notify/notifications-java-client
License: MIT License
Use this client to send emails, text messages and letters using the GOV.UK Notify API.
Useful links:
Currently, as far as I know, we can only update an email template using the User Interface within a web browser. So when we deploy new code to production that requires an email update, we need to remind ourselves to update the email template on Gov Notify. Exposing an endpoint to do that email update, would allow to script that change and to trigger the change as the new code goes live.
We experienced a lot of failures from the notification client while sending notifications. The sms/notification gets sent but unable to retrieve the notification id from the response object.
See jira
https://payments-platform.atlassian.net/browse/PP-2168
see stack trace below
pay-adminusers[13856]: Caused by: java.lang.RuntimeException: error sending user notification
pay-adminusers[13856]: #011at uk.gov.pay.adminusers.service.AdminUsersExceptions.userNotificationError(AdminUsersExceptions.java:96)
pay-adminusers[13856]: #011at uk.gov.pay.adminusers.service.NotificationService.lambda$sendSecondFactorPasscodeSms$0(NotificationService.java:58)
pay-adminusers[13856]: #011at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
pay-adminusers[13856]: #011... 3 common frames omitted
pay-adminusers[13856]: Caused by: org.json.JSONException: JSONObject["id"] not a string.
pay-adminusers[13856]: #011at org.json.JSONObject.getString(JSONObject.java:721)
pay-adminusers[13856]: #011at uk.gov.service.notify.SendSmsResponse.<init>(SendSmsResponse.java:20)
pay-adminusers[13856]: #011at uk.gov.service.notify.NotificationClient.sendSms(NotificationClient.java:162)
pay-adminusers[13856]: #011at uk.gov.pay.adminusers.service.NotificationService.lambda$sendSecondFactorPasscodeSms$0(NotificationService.java:54)
We occasionally hit a NPE when using the Java Gov Notify client.
It happens on conn.getErrorStream()
when the HTTP response code is not as expected. We don't know the underlying cause of why the stream is not available, perhaps a socket error.
It would helpful to have a little more protection around lines 322-329 of uk.gov.service.notify.NotificationClient
.
Here is the stack trace:
java.lang.NullPointerException: null
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:113)
at uk.gov.service.notify.NotificationClient.performPostRequest(NotificationClient.java:327)
at uk.gov.service.notify.NotificationClient.sendSms(NotificationClient.java:192)
at uk.gov.service.notify.NotificationClient.sendSms(NotificationClient.java:171)
at uk.nhs.nhsbsa.covid19.faster.testing.service.GovNotifyService.sendSms(GovNotifyService.java:110)
at uk.nhs.nhsbsa.covid19.faster.testing.service.GovNotifyService.send(GovNotifyService.java:62)
at uk.nhs.nhsbsa.covid19.faster.testing.listener.FasterTestingQueueListener.lambda$listen$0(FasterTestingQueueListener.java:47)
at java.util.Optional.map(Optional.java:215)
at uk.nhs.nhsbsa.covid19.faster.testing.listener.FasterTestingQueueListener.listen(FasterTestingQueueListener.java:47)
at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:565)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:520)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:454)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:227)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:417)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
The Java client is already packed up for Java 8, so would you consider supporting the Java 8 Datetime API instead of or in addition to Joda Time?
Is that implementation thread-safe ?
Can this be deployed to maven central?
What's the reasoning behind not using the standard repository?
in their development environment, pay want to be able to stub out notify - the easiest way is to have a mock notify service. but they can't give a http
URL - because we set up a default ssl context, it won't work or something. They'd have to set up their stub service with https which is a bit extreme. If someone passes in an HTTP url, we shouldn't set up the ssl context I guess. I'm not too sure how java works.
Can another jar be created which has the source code in it?
It would be good for IDE integration.
This can be done with the maven-source-plugin
Currently the API for email only allow to specify one recipient:
SendEmailResponse response = client.sendEmail(templateId, emailAddress, personalisation, "yourReferenceString", emailReplyToId);
Could we add / extend this method to support several recipients:
List<String> emailAddresses = ...
SendEmailResponse response = client.sendEmail(templateId, emailAddresses, personalisation, "yourReferenceString", emailReplyToId);
Where emailAddresses
is a list of strings.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.