Package org.exoplatform.push.service.fcm
Class FCMMessagePublisher
- java.lang.Object
-
- org.exoplatform.push.service.fcm.FCMMessagePublisher
-
- All Implemented Interfaces:
MessagePublisher
public class FCMMessagePublisher extends Object implements MessagePublisher
Message publisher using the HTTP API v1 of Firebase Cloud Messaging
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOG_OPERATION_NAMEstatic StringLOG_SERVICE_NAME
-
Constructor Summary
Constructors Constructor Description FCMMessagePublisher(org.exoplatform.container.xml.InitParams initParams, org.exoplatform.services.resources.ResourceBundleService resourceBundleService, org.exoplatform.commons.api.notification.service.WebNotificationService webNotificationService)FCMMessagePublisher(org.exoplatform.container.xml.InitParams initParams, org.exoplatform.services.resources.ResourceBundleService resourceBundleService, org.exoplatform.commons.api.notification.service.WebNotificationService webNotificationService, org.apache.http.impl.client.CloseableHttpClient httpClient)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringconvertHtml(String html)Conserve line breaks of br and p elements in a html documentprotected StringgetAccessToken()Retrieve the access tokenprotected com.google.api.client.googleapis.auth.oauth2.GoogleCredentialgetCredentialsFromStream(FCMServiceAccountConfiguration configuration)Build GoogleCredential object from configurationprotected PrivateKeygetPrivateKeyFromPkcs8(String privateKeyPem)Build a PrivateKey from its string valueprotected FCMServiceAccountConfigurationloadConfiguration(String fcmServiceAccountFilePath)Load Firebase Cloud Messaging configuration from fileprotected StringprocessBody(Message message)Process the notification message body: * replace images by a text "inline image" * escape double quotesvoidsend(Message message)
-
-
-
Field Detail
-
LOG_SERVICE_NAME
public static final String LOG_SERVICE_NAME
- See Also:
- Constant Field Values
-
LOG_OPERATION_NAME
public static final String LOG_OPERATION_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FCMMessagePublisher
public FCMMessagePublisher(org.exoplatform.container.xml.InitParams initParams, org.exoplatform.services.resources.ResourceBundleService resourceBundleService, org.exoplatform.commons.api.notification.service.WebNotificationService webNotificationService)
-
FCMMessagePublisher
public FCMMessagePublisher(org.exoplatform.container.xml.InitParams initParams, org.exoplatform.services.resources.ResourceBundleService resourceBundleService, org.exoplatform.commons.api.notification.service.WebNotificationService webNotificationService, org.apache.http.impl.client.CloseableHttpClient httpClient)
-
-
Method Detail
-
send
public void send(Message message) throws Exception
- Specified by:
sendin interfaceMessagePublisher- Throws:
Exception
-
convertHtml
protected String convertHtml(String html)
Conserve line breaks of br and p elements in a html document
-
processBody
protected String processBody(Message message)
Process the notification message body: * replace images by a text "inline image" * escape double quotes- Parameters:
message- The raw message body- Returns:
- The transformed message body
-
loadConfiguration
protected FCMServiceAccountConfiguration loadConfiguration(String fcmServiceAccountFilePath) throws IOException
Load Firebase Cloud Messaging configuration from file- Parameters:
fcmServiceAccountFilePath-- Returns:
- Throws:
IOException
-
getCredentialsFromStream
protected com.google.api.client.googleapis.auth.oauth2.GoogleCredential getCredentialsFromStream(FCMServiceAccountConfiguration configuration) throws Exception
Build GoogleCredential object from configuration- Parameters:
configuration- Firebase Cloud Messaging configuration- Returns:
- GoogleCredential
- Throws:
IOExceptionGeneralSecurityExceptionException
-
getPrivateKeyFromPkcs8
protected PrivateKey getPrivateKeyFromPkcs8(String privateKeyPem) throws IOException
Build a PrivateKey from its string value- Parameters:
privateKeyPem- Private key value- Returns:
- PrivateKey
- Throws:
IOException
-
getAccessToken
protected String getAccessToken() throws IOException
Retrieve the access token- Returns:
- The access token
- Throws:
IOException
-
-