當前位置: 首頁>>代碼示例>>Java>>正文


Java UnifiedMessage類代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:eduyayo,項目名稱:gamesboard,代碼行數:20,代碼來源:MessageServiceImpl.java

示例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;
}
 
開發者ID:eduyayo,項目名稱:gamesboard,代碼行數:36,代碼來源:MessageServiceImpl.java

示例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<>());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:11,代碼來源:DefaultPushSender.java

示例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());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:38,代碼來源:DefaultPushSenderTest.java

示例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());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:39,代碼來源:DefaultPushSenderTest.java

示例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.
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:40,代碼來源:DefaultPushSenderTest.java

示例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");
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:41,代碼來源:DefaultPushSenderTest.java

示例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());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:38,代碼來源:DefaultPushSenderTest.java

示例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);
        }
    });
}
 
開發者ID:liveoak-io,項目名稱:liveoak,代碼行數:51,代碼來源:UPS.java

示例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());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:42,代碼來源:DefaultPushSenderTest.java

示例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());
}
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:43,代碼來源:DefaultPushSenderTest.java

示例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);
 
開發者ID:aerogear,項目名稱:aerogear-unifiedpush-java-client,代碼行數:9,代碼來源:PushSender.java


注:本文中的org.jboss.aerogear.unifiedpush.message.UnifiedMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。