Azure / azure-notificationhubs-java-backend

Azure Notification Hubs SDK for Java
https://docs.microsoft.com/en-us/azure/notification-hubs/
Apache License 2.0
35 stars 49 forks source link

Fixing errors when initializing the NotificationHub obj #23

Closed lastbattle closed 7 years ago

lastbattle commented 7 years ago

To reproduce the error, run the following lines of code:


    private static final String SENDERID = "<Enter your senderID>";
    private static final String HUBNAME = "<enter your hub id>";
    private static final String CONNECTION_STRING = "Endpoint=sb://bi<enter your endpoint>";

    private static final NamespaceManager NAMESPACE = new NamespaceManager(CONNECTION_STRING);

    private static PeriodicPushNotification INSTANCE;

    private static NotificationHub hub;
    private static NotificationHubDescription hubDesc;

    public static PeriodicPushNotification getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new PeriodicPushNotification();

            try {
                **hub = new NotificationHub(CONNECTION_STRING, HUBNAME); // Error occurs here.** 
                hubDesc = NAMESPACE.getNotificationHub(HUBNAME);
            } catch (NotificationHubsException exp) {
                exp.printStackTrace();

                throw new RuntimeException("Error initializing notification hub."); // rethrow... cant do much about this crap
            }
        }
        return INSTANCE;
    }
efimovandr commented 7 years ago

Thanks for this fix!