@Test public void receiveReceipt() throws Exception { final String subscriptionId = "subscriptionId"; final String pushResourceId = "pushResourceId"; final String receiptsToken = "receiptsToken"; final String receiptToken = "receiptToken"; final ByteBuf payload = copiedBuffer("Testing", UTF_8); final Subscription subscription = new DefaultSubscription(subscriptionId, pushResourceId); final ChannelHandlerContext ctx = mockChannelHandlerContext(subscriptionId); final Http2ConnectionEncoder encoder = mockEncoder(w -> w.thenReturn(pushPath(pushResourceId)) .thenReturn(pushPath(pushResourceId)), receiptToken, Resource.RECEIPT, Resource.PUSH); final WebPushFrameListener frameListener = new WebPushFrameListener(MockWebPushServerBuilder .withSubscription(subscription) .subscriptionMaxAge(10000L) .receiptsToken(receiptsToken) .receiptToken(receiptToken, new DefaultPushMessage("123", subscriptionId, Optional.of(receiptToken), "test", Optional.empty())) .pushResourceToken(pushResourceId) .build(), encoder); try { final Http2Headers subscribeHeaders = UserAgent.subscribe(frameListener, ctx, encoder); final CharSequence receiptsUri = getLinkUri(WebLink.RECEIPTS, subscribeHeaders.getAll(LINK_HEADER)); final Http2Headers receiptsHeaders = AppServer.receiptsSubcsribe(receiptsUri, frameListener, ctx, encoder); AppServer.receiveReceipts(frameListener, ctx, receiptsHeaders.get(LOCATION)); final Http2Headers sendHeaders = AppServer.sendPush(frameListener, ctx, encoder, subscribeHeaders, payload); final CharSequence pushMessageUri = sendHeaders.get(LOCATION); assertThat(sendHeaders.status(), equalTo(CREATED.codeAsText())); assertThat(pushMessageUri, equalTo(asciiString(messagePath(receiptToken)))); final Http2Headers ackHeaders = UserAgent.acknowledgePushMessage(frameListener, ctx, encoder, pushMessageUri); assertThat(ackHeaders.status(), equalTo(GONE.codeAsText())); } finally { frameListener.shutdown(); } }
void shutdown() { monitoredStreams.values().stream().forEach(client -> client.ctx.close()); monitoredStreams.clear(); acksStreams.values().stream().forEach(client -> client.ctx.close()); acksStreams.clear(); }
WebPushFrameListener extends Http2FrameAdapter { void shutdown() { monitoredStreams.values().stream().forEach(client -> client.ctx.close()); monitoredStreams.clear(); acksStreams.values().stream().forEach(client -> client.ctx.close()); acksStreams.clear(); } }
WebPushFrameListener extends Http2FrameAdapter { void shutdown() { monitoredStreams.values().stream().forEach(client -> client.ctx.close()); monitoredStreams.clear(); acksStreams.values().stream().forEach(client -> client.ctx.close()); acksStreams.clear(); } WebPushFrameListener(final WebPushServer webpushServer, final Http2ConnectionEncoder encoder); }
WebPushFrameListener extends Http2FrameAdapter { void shutdown() { monitoredStreams.values().stream().forEach(client -> client.ctx.close()); monitoredStreams.clear(); acksStreams.values().stream().forEach(client -> client.ctx.close()); acksStreams.clear(); } WebPushFrameListener(final WebPushServer webpushServer, final Http2ConnectionEncoder encoder); @Override void onHeadersRead(final ChannelHandlerContext ctx,
                              final int streamId,
                              final Http2Headers headers,
                              final int streamDependency,
                              final short weight,
                              final boolean exclusive,
                              final int padding,
                              final boolean endStream); @Override int onDataRead(final ChannelHandlerContext ctx,
                          final int streamId,
                          final ByteBuf data,
                          final int padding,
                          final boolean endOfStream); }
WebPushFrameListener extends Http2FrameAdapter { void shutdown() { monitoredStreams.values().stream().forEach(client -> client.ctx.close()); monitoredStreams.clear(); acksStreams.values().stream().forEach(client -> client.ctx.close()); acksStreams.clear(); } WebPushFrameListener(final WebPushServer webpushServer, final Http2ConnectionEncoder encoder); @Override void onHeadersRead(final ChannelHandlerContext ctx,
                              final int streamId,
                              final Http2Headers headers,
                              final int streamDependency,
                              final short weight,
                              final boolean exclusive,
                              final int padding,
                              final boolean endStream); @Override int onDataRead(final ChannelHandlerContext ctx,
                          final int streamId,
                          final ByteBuf data,
                          final int padding,
                          final boolean endOfStream);  }