Fix handling of empty payload Pong message on Jetty

Issue: SPR-12727
This commit is contained in:
Rossen Stoyanchev
2015-02-18 11:36:22 -05:00
parent 406171c9c0
commit 1f990c3df6
2 changed files with 80 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.web.socket.adapter.jetty;
import java.nio.ByteBuffer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jetty.websocket.api.Session;
@@ -36,6 +38,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
/**
* Adapts {@link WebSocketHandler} to the Jetty 9 WebSocket API.
*
@@ -45,8 +48,11 @@ import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator
@WebSocket
public class JettyWebSocketHandlerAdapter {
private static final ByteBuffer EMPTY_PAYLOAD = ByteBuffer.wrap(new byte[0]);
private static final Log logger = LogFactory.getLog(JettyWebSocketHandlerAdapter.class);
private final WebSocketHandler webSocketHandler;
private final JettyWebSocketSession wsSession;
@@ -96,7 +102,8 @@ public class JettyWebSocketHandlerAdapter {
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
if (OpCode.PONG == frame.getOpCode()) {
PongMessage message = new PongMessage(frame.getPayload());
ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
PongMessage message = new PongMessage(payload);
try {
this.webSocketHandler.handleMessage(this.wsSession, message);
}