Examples of iOSVariant


Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

        // no need to send empty list
        if (tokens.isEmpty()) {
            return;
        }

        final iOSVariant iOSVariant = (iOSVariant) variant;

        PayloadBuilder builder = APNS.newPayload()
                // adding recognized key values
                .alertBody(pushMessage.getAlert()) // alert dialog, in iOS
                .badge(pushMessage.getBadge()) // little badge icon update;
                .sound(pushMessage.getSound()) // sound to be played by app
                .category(pushMessage.getActionCategory()); // iOS8: User Action category

                // apply the 'content-available:1' value:
                if (pushMessage.isContentAvailable()) {
                    // content-available is for 'silent' notifications and Newsstand
                    builder = builder.instantDeliveryOrSilentNotification();
                }

                builder = builder.customFields(pushMessage.getData()); // adding other (submitted) fields

        // we are done with adding values here, before building let's check if the msg is too long
        if (builder.isTooLong()) {
            logger.log(Level.WARNING, "Nothing sent to APNs since the payload is too large");
            // invoke the error callback and return, as it is pointless to send something out
            callback.onError("message too long for APNs");

            return;
        }

        // all good, let's build the JSON payload for APNs
        final String apnsMessage  =  builder.build();

        ApnsService service = buildApnsService(iOSVariant, callback);

        if (service != null) {
            try {
                logger.log(Level.FINE, "Sending transformed APNs payload: " + apnsMessage);
                // send:
                service.start();

                Date expireDate = createFutureDateBasedOnTTL(pushMessage.getTimeToLive());
                service.push(tokens, apnsMessage, expireDate);
                logger.log(Level.INFO, "Message to APNs has been submitted");

                // after sending, let's ask for the inactive tokens:
                final Set<String> inactiveTokens = service.getInactiveDevices().keySet();
                // transform the tokens to be all lower-case:
                final Set<String> transformedTokens = lowerCaseAllTokens(inactiveTokens);

                // trigger asynchronous deletion:
                if (! transformedTokens.isEmpty()) {
                    logger.log(Level.INFO, "Deleting '" + inactiveTokens.size() + "' invalid iOS installations");
                    clientInstallationService.removeInstallationsForVariantByDeviceTokens(iOSVariant.getVariantID(), transformedTokens);
                }
            } catch (Exception e) {
                callback.onError("Error sending payload to APNs server: " + e.getMessage());
            } finally {
                // tear down and release resources:
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

        entityManager.flush();
        // clear the cache otherwise finding the entity will not perform a select but get the entity from cache
        entityManager.clear();


        iOSVariant iOS = new iOSVariant();
        iOS.setCertificate("test".getBytes());
        iOS.setPassphrase("secret");
        final String iOSid = iOS.getVariantID();

        variantDao.create(iOS);
        // flush to be sure that it's in the database
        entityManager.flush();
        // clear the cache otherwise finding the entity will not perform a select but get the entity from cache
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

    @Test
    public void callbackOnError() throws Exception {
        final APNsPushNotificationSender sender = new APNsPushNotificationSender();
        final NotificationSenderCallback callback = mock(NotificationSenderCallback.class);
       
        final iOSVariant iosVariant = mock(iOSVariant.class);
        when(iosVariant.getCertificate()).thenReturn(readCertificate());
        when(iosVariant.getPassphrase()).thenReturn("123456");
       
        sender.sendPushMessage(iosVariant, Arrays.asList("token"), mock(UnifiedPushMessage.class), callback);
       
        verify(callback).onError("Error sending payload to APNs server: Invalid hex character: t");
    }
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

            // nope, keep 400 response empty to not leak details about cert/passphrase
            return Response.status(Status.BAD_REQUEST).build();
        }

        // extract form values:
        iOSVariant iOSVariant = new iOSVariant();
        iOSVariant.setName(form.getName());
        iOSVariant.setDescription(form.getDescription());
        iOSVariant.setPassphrase(form.getPassphrase());
        iOSVariant.setCertificate(form.getCertificate());
        iOSVariant.setProduction(form.getProduction());

        // store the "developer:
        iOSVariant.setDeveloper(extractUsername(request));

        // some model validation on the entity:
        try {
            validateModelClass(iOSVariant);
        } catch (ConstraintViolationException cve) {

            // Build and return the 400 (Bad Request) response
            ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations());

            return builder.build();
        }

        // store the iOS variant:
        variantService.addVariant(iOSVariant);

        // add iOS variant, and merge:
        pushAppService.addVariant(pushApp, iOSVariant);

        return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build();
    }
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

            @Context HttpServletRequest request,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID,
            iOSVariant updatediOSVariant) {

        iOSVariant iOSVariant = (iOSVariant) variantService.findByVariantIDForDeveloper(iOSID, extractUsername(request));

        if (iOSVariant != null) {

            // apply update:
            iOSVariant.setName(updatediOSVariant.getName());
            iOSVariant.setDescription(updatediOSVariant.getDescription());

            variantService.updateVariant(iOSVariant);
            return Response.noContent().build();
        }
        return Response.status(Status.NOT_FOUND).entity("Could not find requested Variant").build();
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

            @MultipartForm iOSApplicationUploadForm updatedForm,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID,
            @Context HttpServletRequest request) {

        iOSVariant iOSVariant = (iOSVariant) variantService.findByVariantIDForDeveloper(iOSID, extractUsername(request));
        if (iOSVariant != null) {

            // uploaded certificate/passphrase pair OK (do they match)?
            if (!validateCertificateAndPassphrase(updatedForm)) {
                // nope, keep 400 response empty to not leak details about cert/passphrase
                return Response.status(Status.BAD_REQUEST).build();
            }

            // apply update:
            iOSVariant.setName(updatedForm.getName());
            iOSVariant.setDescription(updatedForm.getDescription());
            iOSVariant.setPassphrase(updatedForm.getPassphrase());
            iOSVariant.setCertificate(updatedForm.getCertificate());
            iOSVariant.setProduction(updatedForm.getProduction());

            // some model validation on the entity:
            try {
                validateModelClass(iOSVariant);
            } catch (ConstraintViolationException cve) {
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

        AndroidVariant av = new AndroidVariant();
        av.setName("Android Variant");
        av.setGoogleKey("KEY...");
        variantDao.create(av);

        iOSVariant ios = new iOSVariant();
        ios.setName("spelling is hard");
        ios.setPassphrase("123");
        ios.setCertificate("12".getBytes());
        variantDao.create(ios);

        Installation androidInstallation1 = new Installation();
        androidInstallation1.setDeviceToken("CSPA91bGDWDdlxW3EmSs2bH7Qlo5AOfbCJtmyOukYxVHq8KKUqpPLBLUjettGYoN2nahBbAe3GgmxKPcZnqEIFFxHw3brKOSmeXjZQuEVehSJTUdJuXUCmR3XweZ2MM455fYMcvkUse1DIp1wjxnik2uHYSNl87wrJzLddoC7tPpgch3eJAf");
        installationDao.create(androidInstallation1);

        Installation androidInstallation2 = new Installation();
        androidInstallation2.setDeviceToken("ASPA91bGDWDdlxW3EmSs2bH7Qlo5AOfbCJtmyOukYxVHq8KKUqpPLBLUjettGYoN2nahBbAe3GgmxKPcZnqEIFFxHw3brKOSmeXjZQuEVehSJTUdJuXUCmR3XweZ2MM455fYMcvkUse1DIp1wjxnik2uHYSNl87wrJzLddoC7tPpgch3eJAf");
        installationDao.create(androidInstallation2);

        Installation iosInstallation1 = new Installation();
        iosInstallation1.setDeviceToken("33ee51dad49a77ca7b45924074bcc4f19aea20308f5feda202fbba3baed7073d7");
        installationDao.create(iosInstallation1);

        androidInstallation1.setVariant(av);
        androidInstallation2.setVariant(av);
        iosInstallation1.setVariant(ios);
        variantDao.update(av);
        variantDao.update(ios);

        pa.getVariants().add(av);
        pa.getVariants().add(ios);
        pushApplicationDao.update(pa);

        // flush to be sure that it's in the database
        entityManager.flush();
        // clear the cache otherwise finding the entity will not perform a select but get the entity from cache
        entityManager.clear();

        final Map<String, Long> result = pushApplicationDao.countInstallationsByType(pushApplication1.getPushApplicationID());

        System.out.println("result = " + result);
        assertThat(result).isNotEmpty();
        assertThat(result.get(av.getVariantID())).isEqualTo(2L);
        assertThat(result.get(ios.getVariantID())).isEqualTo(1L);
    }
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

        AndroidVariant ignored = new AndroidVariant();
        ignored.setName("ignored");
        ignored.setGoogleKey("123");
        variantDao.create(ignored);

        iOSVariant iOSVariant = new iOSVariant();
        iOSVariant.setName("ignored");
        iOSVariant.setCertificate(new byte[1]);
        iOSVariant.setPassphrase("123");
        variantDao.create(iOSVariant);

        pa.getVariants().add(av);
        pa.getVariants().add(ignored);
        pa.getVariants().add(iOSVariant);
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

        entityManager.flush();
        // clear the cache otherwise finding the entity will not perform a select but get the entity from cache
        entityManager.clear();


        iOSVariant iOS = new iOSVariant();
        iOS.setCertificate("test".getBytes());
        iOS.setPassphrase("secret");
        final String iOSid = iOS.getVariantID();

        variantDao.create(iOS);
        // flush to be sure that it's in the database
        entityManager.flush();
        // clear the cache otherwise finding the entity will not perform a select but get the entity from cache
View Full Code Here

Examples of org.jboss.aerogear.unifiedpush.api.iOSVariant

            // nope, keep 400 response empty to not leak details about cert/passphrase
            return Response.status(Status.BAD_REQUEST).build();
        }

        // extract form values:
        iOSVariant iOSVariant = new iOSVariant();
        iOSVariant.setName(form.getName());
        iOSVariant.setDescription(form.getDescription());
        iOSVariant.setPassphrase(form.getPassphrase());
        iOSVariant.setCertificate(form.getCertificate());
        iOSVariant.setProduction(form.getProduction());

        // store the "developer:
        iOSVariant.setDeveloper(extractUsername(request));

        // some model validation on the entity:
        try {
            validateModelClass(iOSVariant);
        } catch (ConstraintViolationException cve) {

            // Build and return the 400 (Bad Request) response
            ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations());

            return builder.build();
        }

        // store the iOS variant:
        variantService.addVariant(iOSVariant);

        // add iOS variant, and merge:
        pushAppService.addiOSVariant(pushApp, iOSVariant);

        return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.