@Test public void handleNotification() throws ChannelNotFoundException { final String channelId = UUID.randomUUID().toString(); final String uaid = UUIDUtil.newUAID(); final RegisterResponse registerResponse = server.handleRegister(new RegisterMessageImpl(channelId), uaid); final String endpointToken = extractEndpointToken(registerResponse.getPushEndpoint()); Notification notification = server.handleNotification(endpointToken, "version=1"); assertThat(notification.ack(), equalTo((Ack)new AckImpl(channelId, 1L))); assertThat(server.getChannel(channelId).getVersion(), is(1L)); server.handleNotification(endpointToken, "version=2"); assertThat(server.getChannel(channelId).getVersion(), is(2L)); }
@Override public Notification handleNotification(final String endpointToken, final String body) throws ChannelNotFoundException { final Long version = Long.valueOf(VersionExtractor.extractVersion(body)); final String channelId = store.updateVersion(endpointToken, version); if (channelId == null) { throw new ChannelNotFoundException("Could not find channel for endpoint [" + endpointToken + "]", null); } final Ack ack = new AckImpl(channelId, version); final String uaid = store.saveUnacknowledged(channelId, ack.getVersion()); return new Notification(uaid, ack); }
DefaultSimplePushServer implements SimplePushServer { @Override public Notification handleNotification(final String endpointToken, final String body) throws ChannelNotFoundException { final Long version = Long.valueOf(VersionExtractor.extractVersion(body)); final String channelId = store.updateVersion(endpointToken, version); if (channelId == null) { throw new ChannelNotFoundException("Could not find channel for endpoint [" + endpointToken + "]", null); } final Ack ack = new AckImpl(channelId, version); final String uaid = store.saveUnacknowledged(channelId, ack.getVersion()); return new Notification(uaid, ack); } }
DefaultSimplePushServer implements SimplePushServer { @Override public Notification handleNotification(final String endpointToken, final String body) throws ChannelNotFoundException { final Long version = Long.valueOf(VersionExtractor.extractVersion(body)); final String channelId = store.updateVersion(endpointToken, version); if (channelId == null) { throw new ChannelNotFoundException("Could not find channel for endpoint [" + endpointToken + "]", null); } final Ack ack = new AckImpl(channelId, version); final String uaid = store.saveUnacknowledged(channelId, ack.getVersion()); return new Notification(uaid, ack); } DefaultSimplePushServer(final DataStore store, final SimplePushServerConfig config, final byte[] privateKey); }
DefaultSimplePushServer implements SimplePushServer { @Override public Notification handleNotification(final String endpointToken, final String body) throws ChannelNotFoundException { final Long version = Long.valueOf(VersionExtractor.extractVersion(body)); final String channelId = store.updateVersion(endpointToken, version); if (channelId == null) { throw new ChannelNotFoundException("Could not find channel for endpoint [" + endpointToken + "]", null); } final Ack ack = new AckImpl(channelId, version); final String uaid = store.saveUnacknowledged(channelId, ack.getVersion()); return new Notification(uaid, ack); } DefaultSimplePushServer(final DataStore store, final SimplePushServerConfig config, final byte[] privateKey); @Override HelloResponse handleHandshake(final HelloMessage handshake); @Override RegisterResponse handleRegister(final RegisterMessage register, final String uaid); @Override Notification handleNotification(final String endpointToken, final String body); @Override UnregisterResponse handleUnregister(final UnregisterMessage unregister, final String uaid); @Override Set<Ack> handleAcknowledgement(final AckMessage ackMessage, final String uaid); @Override Set<Ack> getUnacknowledged(final String uaid); String getUAID(final String channelId); Channel getChannel(final String channelId); boolean hasChannel(final String uaid, final String channelId); boolean removeChannel(final String channnelId, final String uaid); @Override void removeAllChannels(final String uaid); @Override SimplePushServerConfig config(); static byte[] generateAndStorePrivateKey(final DataStore store, final SimplePushServerConfig config); }
DefaultSimplePushServer implements SimplePushServer { @Override public Notification handleNotification(final String endpointToken, final String body) throws ChannelNotFoundException { final Long version = Long.valueOf(VersionExtractor.extractVersion(body)); final String channelId = store.updateVersion(endpointToken, version); if (channelId == null) { throw new ChannelNotFoundException("Could not find channel for endpoint [" + endpointToken + "]", null); } final Ack ack = new AckImpl(channelId, version); final String uaid = store.saveUnacknowledged(channelId, ack.getVersion()); return new Notification(uaid, ack); } DefaultSimplePushServer(final DataStore store, final SimplePushServerConfig config, final byte[] privateKey); @Override HelloResponse handleHandshake(final HelloMessage handshake); @Override RegisterResponse handleRegister(final RegisterMessage register, final String uaid); @Override Notification handleNotification(final String endpointToken, final String body); @Override UnregisterResponse handleUnregister(final UnregisterMessage unregister, final String uaid); @Override Set<Ack> handleAcknowledgement(final AckMessage ackMessage, final String uaid); @Override Set<Ack> getUnacknowledged(final String uaid); String getUAID(final String channelId); Channel getChannel(final String channelId); boolean hasChannel(final String uaid, final String channelId); boolean removeChannel(final String channnelId, final String uaid); @Override void removeAllChannels(final String uaid); @Override SimplePushServerConfig config(); static byte[] generateAndStorePrivateKey(final DataStore store, final SimplePushServerConfig config);  }