本文整理汇总了Java中org.jboss.aerogear.unifiedpush.message.UnifiedMessage类的典型用法代码示例。如果您正苦于以下问题:Java UnifiedMessage类的具体用法?Java UnifiedMessage怎么用?Java UnifiedMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnifiedMessage类属于org.jboss.aerogear.unifiedpush.message包,在下文中一共展示了UnifiedMessage类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Override
@Transactional
public void sendMessage(HubMessage newMsg) {
if (newMsg.getTo() == null || newMsg.getTo().size() == 0) {
throw new RuntimeException("Message has an empty TO field.");
}
try {
pushSender.send(new UnifiedMessage.Builder()
.pushApplicationId("51b51d7d-cba0-4af1-a420-d9b4d6dae877")
.masterSecret("af80e72d-e9f0-4e83-b543-80f6662e8f7a")
.aliases(userService.getDeviceTokens(newMsg.getTo()))
.sound("default")
.attribute("payload", new ObjectMapper().writeValueAsString(newMsg))
.build());
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
示例2: sendMessageOrFalse
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Transactional
public boolean sendMessageOrFalse(final HubMessage newMsg) {
boolean ret;
if (newMsg.getTo() == null || newMsg.getTo().size() == 0) {
throw new RuntimeException("Message has an empty TO field.");
}
final CountDownLatch latch = new CountDownLatch(1);
Thread task = new Thread(new Runnable() {
@Override
public void run() {
try {
pushSender.send(
new UnifiedMessage.Builder()
.pushApplicationId("51b51d7d-cba0-4af1-a420-d9b4d6dae877")
.masterSecret("af80e72d-e9f0-4e83-b543-80f6662e8f7a")
.aliases(userService.getDeviceTokens(newMsg.getTo()))
.sound("default")
.attribute("payload", new ObjectMapper().writeValueAsString(newMsg))
.build());
} catch (Throwable t) {
t.printStackTrace();
} finally {
latch.countDown();
}
}
});
task.start();
try {
ret = latch.await(TIMEOUT_SEC, TimeUnit.SECONDS);
} catch (InterruptedException e) {
ret = false;
}
return ret;
}
示例3: send
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Override
public void send(List<UnifiedMessage> unifiedMessages, MessageResponseCallback callback) {
final String jsonString = unifiedMessages.stream()
.map(unifiedMessage -> unifiedMessage.getObject().toJsonString())
.collect(Collectors.toList()).toString();
// fire!
submitPayload(buildUrl()+"batch/", pushConfiguration.getConnectionSettings(), jsonString, pushConfiguration.getPushApplicationId(), pushConfiguration.getMasterSecret(), callback, new ArrayList<>());
}
示例4: sendSendWithCallbackAndException
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallbackAndException() throws Exception {
// throw IOException when posting
PowerMockito.doThrow(new IOException()).when(HttpRequestUtil.class, "post", anyString(), anyString(), anyString(), any(),
any(), any(), any());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean pushSenderExceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
defaultSenderClient.send(unifiedMessage, callback);
} catch (PushSenderException pse) {
pushSenderExceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertFalse(onCompleteCalled.get());
assertTrue(pushSenderExceptionThrown.get());
}
示例5: sendSendWithCallbackAndException_SSL
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallbackAndException_SSL() throws Exception {
// throw IOException when posting
PowerMockito.doThrow(new IOException()).when(HttpRequestUtil.class, "post", anyString(), anyString(), anyString(), any(),
any(), any(), any());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean pushSenderExceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
secureSenderClient.send(unifiedMessage, callback);
} catch (PushSenderException pse) {
pushSenderExceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertFalse(onCompleteCalled.get());
assertTrue(pushSenderExceptionThrown.get());
}
示例6: sendSendWithCallback200
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallback200() throws Exception {
when(((HttpURLConnection) getConnnection()).getResponseCode()).thenReturn(STATUS_OK);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
defaultSenderClient.send(unifiedMessage, callback);
} catch (Exception e) {
exceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertTrue(onCompleteCalled.get());
assertFalse(exceptionThrown.get());
verify(getConnnection(), times(1)).setConnectTimeout(CONNECTION_CONNECT_TIMEOUT); // This was explicitly provided and should be set.
verify(getConnnection(), never()).setReadTimeout(Mockito.anyInt()); // Never configured a read timeout, method should never have been called.
}
示例7: sendSendWithInfiniteRedirect
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithInfiniteRedirect() throws Exception {
when(((HttpURLConnection) getConnnection()).getResponseCode()).thenReturn(STATUS_REDIRECT);
when(getConnnection().getHeaderField("Location")).thenReturn("http://aerogear.example.com/ag-push");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean pushSenderExceptionThrown = new AtomicBoolean(false);
final List<Throwable> throwableList = new ArrayList<Throwable>(1);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
defaultSenderClient.send(unifiedMessage,callback);
} catch (PushSenderException pse) {
pushSenderExceptionThrown.set(true);
throwableList.add(pse);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertFalse(onCompleteCalled.get());
assertTrue(pushSenderExceptionThrown.get());
assertEquals(throwableList.get(0).getMessage(), "The site contains an infinite redirect loop! Duplicate url: http://aerogear.example.com/ag-push");
}
示例8: sendSendWithCallback200_SSL
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallback200_SSL() throws Exception {
when(((HttpURLConnection) getSecureConnection()).getResponseCode()).thenReturn(STATUS_OK);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
secureSenderClient.send(unifiedMessage, callback);
} catch (Exception e) {
exceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertTrue(onCompleteCalled.get());
assertFalse(exceptionThrown.get());
}
示例9: send
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
/**
* Sends a message to the UPS instance to send out push notifications to registered applications
*
* @param URI The URI of the updated resource
* @param eventType The type of event which occurred
* @param subscription The object containing the message and specified recipients
*/
public void send(URI URI, EventType eventType, UPSSubscription subscription) {
SenderClient sender = SenderClient.withRootServerURL(upsRootConfigResource.getUPSServerURL()).build();
// setup the application specifics
UnifiedMessage.Builder builder = new UnifiedMessage.Builder()
.pushApplicationId(upsRootConfigResource.getApplicationId())
.masterSecret(upsRootConfigResource.getMasterSecret());
// setup who is to receive the message
builder.variants(subscription.variants());
builder.aliases(subscription.aliases());
builder.categories(subscription.categories());
builder.deviceType(subscription.deviceTypes());
if (subscription.simplePush() != null) {
builder.simplePush(subscription.simplePush().toString());
//increment the simplePush value, otherwise next time the simple-push server will ignore the notification
subscription.simplePush(subscription.simplePush() + 1);
}
//setup the message itself
builder.attributes(subscription.message());
// specify the liveoak specifics of the message, overwrite if needed.
builder.attribute(LIVEOAK_RESOURCE_URL, URI.toString());
builder.attribute(LIVEOAK_RESOURCE_EVENT, eventType.toString());
sender.send(builder.build(), new MessageResponseCallback() {
@Override
public void onComplete(int i) {
//do nothing for now
}
@Override
public void onError(Throwable throwable) {
//TODO: how to handle when there is an error between LiveOak and UPS?
// should we just log the error, try again after x many seconds and y many retries?
log.error("Error trying to send notification to UPS server", throwable);
}
});
}
示例10: sendSendWithCallback404
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallback404() throws Exception {
when(((HttpURLConnection) getConnnection()).getResponseCode()).thenReturn(STATUS_NOT_FOUND);
final CountDownLatch latch = new CountDownLatch(1);
final List<Integer> returnedStatusList = new ArrayList<Integer>(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean pushSenderHttpExceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
defaultSenderClient.send(unifiedMessage, callback);
} catch (PushSenderHttpException pshe) {
returnedStatusList.add(pshe.getStatusCode());
pushSenderHttpExceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertTrue(pushSenderHttpExceptionThrown.get());
assertFalse(onCompleteCalled.get());
assertNotNull(returnedStatusList);
assertEquals(1, returnedStatusList.size());
assertEquals(STATUS_NOT_FOUND, returnedStatusList.get(0).intValue());
}
示例11: sendSendWithCallback404_SSL
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
@Test
public void sendSendWithCallback404_SSL() throws Exception {
when(((HttpURLConnection) getSecureConnection()).getResponseCode()).thenReturn(STATUS_NOT_FOUND);
final CountDownLatch latch = new CountDownLatch(1);
final List<Integer> returnedStatusList = new ArrayList<Integer>(1);
final AtomicBoolean onCompleteCalled = new AtomicBoolean(false);
final AtomicBoolean pushSenderHttpExceptionThrown = new AtomicBoolean(false);
MessageResponseCallback callback = new MessageResponseCallback() {
@Override
public void onComplete() {
onCompleteCalled.set(true);
latch.countDown();
}
};
UnifiedMessage unifiedMessage = UnifiedMessage.withMessage()
.alert(ALERT_MSG)
.sound(DEFAULT_SOUND)
.criteria().aliases(IDENTIFIERS_LIST)
.build();
try {
secureSenderClient.send(unifiedMessage, callback);
} catch (PushSenderHttpException pshe) {
returnedStatusList.add(pshe.getStatusCode());
pushSenderHttpExceptionThrown.set(true);
latch.countDown();
}
latch.await(1000, TimeUnit.MILLISECONDS);
assertTrue(pushSenderHttpExceptionThrown.get());
assertFalse(onCompleteCalled.get());
assertNotNull(returnedStatusList);
assertEquals(1, returnedStatusList.size());
assertEquals(STATUS_NOT_FOUND, returnedStatusList.get(0).intValue());
}
示例12: send
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage; //导入依赖的package包/类
/**
* Sends the given payload to installations of the referenced PushApplication.
* We also pass a {@link MessageResponseCallback} to handle the message
*
* @param unifiedMessage the {@link UnifiedMessage} to send.
* @param callback the {@link MessageResponseCallback}.
*/
void send(UnifiedMessage unifiedMessage, MessageResponseCallback callback);