Browse Source
WebSocketHandler implementations: - methods must deal with exceptions locally - uncaught runtime exceptions are handled by ending the session - transport errors (websocket engine) are passed into handleError WebSocketSession methods may raise IOException SockJS implementation of WebSocketHandler: - delegate SockJS transport errors into handleError - stop runtime exceptions from user WebSocketHandler and end session SockJsServce and TransportHandlers: - raise IOException or TransportErrorException HandshakeHandler: - raise IOExceptionpull/292/head
32 changed files with 558 additions and 318 deletions
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* Copyright 2002-2013 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.sockjs.server; |
||||
|
||||
import org.springframework.core.NestedRuntimeException; |
||||
import org.springframework.websocket.WebSocketHandler; |
||||
|
||||
|
||||
/** |
||||
* Raised when a TransportHandler fails during request processing. |
||||
* |
||||
* <p>If the underlying exception occurs while sending messages to the client, |
||||
* the session will have been closed and the {@link WebSocketHandler} notified. |
||||
* |
||||
* <p>If the underlying exception occurs while processing an incoming HTTP request |
||||
* including posted messages, the session will remain open. Only the incoming |
||||
* request is rejected. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 4.0 |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class TransportErrorException extends NestedRuntimeException { |
||||
|
||||
private final String sockJsSessionId; |
||||
|
||||
public TransportErrorException(String msg, Throwable cause, String sockJsSessionId) { |
||||
super(msg, cause); |
||||
this.sockJsSessionId = sockJsSessionId; |
||||
} |
||||
|
||||
public String getSockJsSessionId() { |
||||
return sockJsSessionId; |
||||
} |
||||
|
||||
@Override |
||||
public String getMessage() { |
||||
return "Transport error for SockJS session id=" + this.sockJsSessionId + ", " + super.getMessage(); |
||||
} |
||||
|
||||
} |
||||
@ -1,62 +0,0 @@
@@ -1,62 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2013 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.sockjs.server.transport; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.springframework.http.server.ServerHttpRequest; |
||||
import org.springframework.http.server.ServerHttpResponse; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.websocket.HandlerProvider; |
||||
import org.springframework.websocket.WebSocketHandler; |
||||
|
||||
|
||||
/** |
||||
* TODO |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 4.0 |
||||
*/ |
||||
public abstract class AbstractStreamingTransportHandler extends AbstractHttpSendingTransportHandler { |
||||
|
||||
|
||||
@Override |
||||
public StreamingServerSockJsSession createSession(String sessionId, HandlerProvider<WebSocketHandler> handler) { |
||||
Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); |
||||
return new StreamingServerSockJsSession(sessionId, getSockJsConfig(), handler); |
||||
} |
||||
|
||||
@Override |
||||
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, |
||||
AbstractHttpServerSockJsSession session) throws Exception { |
||||
|
||||
writePrelude(request, response); |
||||
super.handleRequestInternal(request, response, session); |
||||
} |
||||
|
||||
protected abstract void writePrelude(ServerHttpRequest request, ServerHttpResponse response) |
||||
throws IOException; |
||||
|
||||
@Override |
||||
protected void handleNewSession(ServerHttpRequest request, ServerHttpResponse response, |
||||
AbstractHttpServerSockJsSession session) throws IOException, Exception { |
||||
|
||||
super.handleNewSession(request, response, session); |
||||
|
||||
session.setCurrentRequest(request, response, getFrameFormat(request)); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue