使用apache camel apns组件编写一个简单的代码来向iOS设备发送通知?

时间:2014-05-06 10:52:02

标签: apache-camel

我是骆驼和stackoverflow的新手我在java DSL中想出了一个简单的代码来向iOS设备发送通知。 这是我的代码:

public class ApplePush{

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();



    ApnsServiceFactory apnsServiceFactory = new ApnsServiceFactory();
    apnsServiceFactory.setCertificatePath("classpath");    //Specify the certificate path
    apnsServiceFactory.setCertificatePassword("password");            //Specify the password

    ApnsService apnsService = apnsServiceFactory.getApnsService();


    ApnsComponent apnsComponent = new ApnsComponent(apnsService);
    camelContext.addComponent("apns", apnsComponent);

    return camelContext;
}


protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:test")
            .to("apns:notify?tokens=" + ""/*IOS_DEVICE_TOKEN* put device token here*/);
        }
    };
}


public static void main(String args[]) throws Exception{
    ApplePush ob = new ApplePush();
    String message = "Hello World";

    CamelContext component = ob.createCamelContext();
    component.addRoutes(ob.createRouteBuilder());

    ProducerTemplate template = component.createProducerTemplate();

    component.start();
    template.sendBody("direct:test", message);
    Thread.sleep(1000);
    component.stop();
}

}

此代码是否适用于相应的证书和设备令牌,或者我做错了什么?

0 个答案:

没有答案