本文整理汇总了Java中ar.com.fernandospr.wns.model.builders.WnsToastBuilder类的典型用法代码示例。如果您正苦于以下问题:Java WnsToastBuilder类的具体用法?Java WnsToastBuilder怎么用?Java WnsToastBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WnsToastBuilder类属于ar.com.fernandospr.wns.model.builders包,在下文中一共展示了WnsToastBuilder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testXmlSerialization
import ar.com.fernandospr.wns.model.builders.WnsToastBuilder; //导入依赖的package包/类
public void testXmlSerialization() {
WnsToastBuilder builder = new WnsToastBuilder();
builder.bindingTemplateToastText02("a", "b");
WnsToast toast = builder.build();
WnsClient client = new WnsClient("sid", "client secret", true) {
@Override
protected String getAuthenticationUri() {
return "http://localhost:8089/accesstoken.srf";
}
};
WnsResourceBuilder xmlResourceBuilder = new WnsXmlResourceBuilder();
// Stub server response for push
stubFor(post(urlEqualTo("/fakechannel"))
.willReturn(aResponse()
.withStatus(200)
.withBody("OK")));
client.push(xmlResourceBuilder, "http://localhost:8089/fakechannel", toast, 5, null);
// Verify it reached with the correct XML content
verify(postRequestedFor(urlEqualTo("/fakechannel"))
.withRequestBody(equalToXml("<toast><visual><binding template=\"ToastText02\"><text id=\"1\">a</text><text id=\"2\">b</text></binding></visual></toast>")));
}
示例2: createToastMessage
import ar.com.fernandospr.wns.model.builders.WnsToastBuilder; //导入依赖的package包/类
WnsToast createToastMessage(Message message) {
final WnsToastBuilder builder = new WnsToastBuilder();
Windows windows = message.getWindows();
if (windows.getDuration() != null) {
builder.duration(windows.getDuration().toString());
}
builder.audioSrc(message.getSound());
builder.launch(createLaunchParam(message.getWindows().getPage(), message.getAlert(), message.getUserData(), getPushMessageInformationId()));
createMessage(message, windows.getToastType().toString(), builder);
return builder.build();
}
示例3: testConnection
import ar.com.fernandospr.wns.model.builders.WnsToastBuilder; //导入依赖的package包/类
@Override
public void testConnection() throws Exception {
WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01("test").build();
try{
//this fails every time due to jax error which is ok
service.pushToast("s-1-15-2-2411381248-444863693-3819932088-4077691928-1194867744-112853457-373132695", toast);
}catch (ClientHandlerException e){
logger.info("Windows Phone notifier added: " + e.toString());
}
}
示例4: createSimpleToastMessage
import ar.com.fernandospr.wns.model.builders.WnsToastBuilder; //导入依赖的package包/类
WnsToast createSimpleToastMessage(Message message) {
final WnsToastBuilder builder = new WnsToastBuilder().bindingTemplateToastText01(message.getAlert());
final Map<String, Object> data = message.getUserData();
builder.launch(createLaunchParam(message.getWindows().getPage(), message.getAlert(), data, getPushMessageInformationId()));
return builder.build();
}
示例5: sendNotification
import ar.com.fernandospr.wns.model.builders.WnsToastBuilder; //导入依赖的package包/类
@Override
public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker) throws Exception {
try {
List<TranslatedNotification> translatedNotifications = ( List<TranslatedNotification>) payload;
for(TranslatedNotification translatedNotification : translatedNotifications) {
// set the optional TTL value used when pushing notifications
WnsNotificationRequestOptional opt = new WnsNotificationRequestOptional();
if(notification.getExpireTTLSeconds()>0) {
opt.ttl = String.valueOf(notification.getExpireTTLSeconds());
}
switch (translatedNotification.getType()) {
case "toast":
WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01(translatedNotification.getMessage().toString()).build();
service.pushToast(providerId, opt, toast);
break;
case "badge":
WnsBadge badge;
if (translatedNotification.getMessage() instanceof Integer) {
badge = new WnsBadgeBuilder().value((Integer) translatedNotification.getMessage()).build();
} else {
badge = new WnsBadgeBuilder().value(translatedNotification.getMessage().toString()).build();
}
service.pushBadge(providerId, opt, badge);
break;
case "raw":
Object message = translatedNotification.getMessage();
if(message instanceof String) {
WnsRaw raw = new WnsRawBuilder().stream(((String) message).getBytes()).build();
// set additional optional parameter for raw notifications
opt.cachePolicy = "cache";
opt.requestForStatus = "true";
WnsNotificationResponse response = service.pushRaw(providerId, opt, raw);
if (!response.notificationStatus.equals("received")) { // https://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#pncodes_x_wns_notification
throw new Exception(String.format("Notification failed status:%s, devicesStatus:%s, description:%s, debug flag:%s", response.notificationStatus, response.deviceConnectionStatus, response.errorDescription, response.debugTrace));
}
}else{
throw new IllegalArgumentException("You must send a string in the raw body. instead got this: " + message.getClass().getName());
}
break;
default:
throw new IllegalArgumentException(translatedNotification.getType() + " does not match a valid notification type (toast,badge).");
}
}
tracker.completed();
} catch (Exception e) {
tracker.failed(0,e.toString());
logger.error("Failed to send notification",e);
}
}