A Java API for sending Push Notifications to the AeroGear UnifiedPush Server. For more information, please visit the Java Sender Tutorial for example usages.
Add the following dependencies to your pom.xml
file:
<dependency>
<groupId>org.jboss.aerogear</groupId>
<artifactId>unifiedpush-java-client</artifactId>
<version>0.4.0</version>
</dependency>
<!-- RestEasy's Jackson Plugin -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.3.2.Final</version>
</dependency>
Create a JavaSender
:
JavaSender defaultJavaSender =
new SenderClient("http://localhost:8080/ag-push");
Construct a UnifiedMessage
using the Builder
:
UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
.pushApplicationId("c7fc6525-5506-4ca9-9cf1-55cc261ddb9c")
.masterSecret("8b2f43a9-23c8-44fe-bee9-d6b0af9e316b")
.aliases(Arrays.asList("john", "maria"))
.alert("Hello from Java Sender API!")
.sound("default")
.build();
Create a callback
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete(int statusCode) {
//do cool stuff
}
@Override
public void onError(Throwable throwable) {
//bring out the bad news
}
};
Send the message
defaultJavaSender.send(unifiedMessage, callback);
You can also omit the callback
defaultJavaSender.send(unifiedMessage);
On Java7 you might see a SSLProtocolException: handshake alert: unrecognized_name
expection when the UnifiedPush server is running on https. There are a few workarounds:
- JBoss'
standalone.xml
configuration file:
<system-properties>
<property name="jsse.enableSNIExtension" value="false"/>
</system-properties>
- in the Java app, that is using the Java Client SDK:
System.setProperty("jsse.enableSNIExtension", "false");
- Or via commandline argument:
-Djsse.enableSNIExtension=false