Skip to content

Commit

Permalink
Merge pull request wso2#166 from riyafa/cancel
Browse files Browse the repository at this point in the history
Get response from server on client handshake
  • Loading branch information
irunika authored May 21, 2018
2 parents 29c9ef1 + ad343fe commit 804048f
Show file tree
Hide file tree
Showing 27 changed files with 485 additions and 336 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.transport.http.netty.contract.websocket;

import org.wso2.transport.http.netty.message.HttpCarbonResponse;

/**
* Future for WebSocket handshake.
*/
public interface ClientHandshakeFuture {

/**
* Set the listener for WebSocket handshake.
*
* @param serverHandshakeListener Listener for WebSocket handshake.
* @return the same handshake future.
*/
ClientHandshakeFuture setClientHandshakeListener(ClientHandshakeListener serverHandshakeListener);

/**
* Notify the success of the WebSocket handshake.
*
* @param webSocketConnection {@link WebSocketConnection} for the successful connection.
* @param response {@link HttpCarbonResponse} received from server.
*/
void notifySuccess(WebSocketConnection webSocketConnection, HttpCarbonResponse response);

/**
* Notify any error occurred during the handshake.
*
* @param throwable error occurred during handshake.
* @param response {@link HttpCarbonResponse} received from server or null if error occurred before response is
* received.
*/
void notifyError(Throwable throwable, HttpCarbonResponse response);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.transport.http.netty.contract.websocket;

import org.wso2.transport.http.netty.message.HttpCarbonResponse;

/**
* Future listener for WebSocket handshake.
*/
public interface ClientHandshakeListener {

/**
* Notify the success of the handshake.
*
* @param webSocketConnection {@link WebSocketConnection} for the successful handshake.
*/
void onSuccess(WebSocketConnection webSocketConnection, HttpCarbonResponse response);

/**
* Notify error on handshake.
* @param t error occurred during handshake.
*/
void onError(Throwable t, HttpCarbonResponse response);

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.transport.http.netty.contract.websocket;

/**
* Future for WebSocket handshake.
*/
public interface ServerHandshakeFuture {

/**
* Set the listener for WebSocket handshake.
*
* @param serverHandshakeListener Listener for WebSocket handshake.
* @return the same handshake future.
*/
ServerHandshakeFuture setHandshakeListener(ServerHandshakeListener serverHandshakeListener);

/**
* Notify the success of the WebSocket handshake.
*
* @param webSocketConnection {@link WebSocketConnection} for the successful connection.
*/
void notifySuccess(WebSocketConnection webSocketConnection);

/**
* Notify any error occurred during the handshake.
*
* @param throwable error occurred during handshake.
*/
void notifyError(Throwable throwable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
/**
* Future listener for WebSocket handshake.
*/
public interface HandshakeListener {
public interface ServerHandshakeListener {

/**
* Notify the success of the handshake.
*
* @param webSocketConnection {@link WebSocketConnection} for the successful handshake.
*/
public void onSuccess(WebSocketConnection webSocketConnection);
void onSuccess(WebSocketConnection webSocketConnection);

/**
* Notify error on handshake.
*
* @param t error occurred during handshake.
*/
public void onError(Throwable t);
void onError(Throwable t);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface WebSocketClientConnector {
* Connect to the remote server.
*
* @param connectorListener {@link WebSocketConnectorListener} to listen incoming messages.
* @return HandshakeFuture for the newly created connection.
* @return ClientHandshakeFuture for the newly created connection.
*/
HandshakeFuture connect(WebSocketConnectorListener connectorListener);
ClientHandshakeFuture connect(WebSocketConnectorListener connectorListener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.netty.channel.ChannelFuture;
import io.netty.handler.codec.http.HttpHeaders;
import org.wso2.transport.http.netty.message.HttpCarbonRequest;

/**
* This Message is used to handle WebSocket handshake.
Expand All @@ -33,65 +34,73 @@ public interface WebSocketInitMessage extends WebSocketMessage {
*
* @return the Server session for the newly created WebSocket connection.
*/
HandshakeFuture handshake();
ServerHandshakeFuture handshake();

/**
* Complete the handshake of a given request. There will not be a idle timeout for the connection if this
* method is used.
*
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param allowExtensions whether the extensions are allowed or not.
* @return the Server session for the newly created WebSocket connection.
*/
HandshakeFuture handshake(String[] subProtocols, boolean allowExtensions);
ServerHandshakeFuture handshake(String[] subProtocols, boolean allowExtensions);

/**
* Complete the handshake of a given request. The connection will be timed out if the connection is idle for
* given time period.
*
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param allowExtensions whether the extensions are allowed or not.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @return the handshake future.
*/
HandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout);
ServerHandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout);

/**
* Complete the handshake of a given request. The connection will be timed out if the connection is idle for given
* time period.
*
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param allowExtensions whether the extensions are allowed or not.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @param responseHeaders Extra headers to add to the handshake response or {@code null} if no extra headers should
* be added
* @return the handshake future.
*/
HandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout,
HttpHeaders responseHeaders);
ServerHandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout,
HttpHeaders responseHeaders);

/**
* Complete the handshake of a given request. The connection will be timed out if the connection is idle for given
* time period.
*
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param allowExtensions whether the extensions are allowed or not.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @param responseHeaders Extra headers to add to the handshake response or {@code null} if no extra headers should
* be added.
* @param subProtocols Sub-Protocols which are allowed by the service.
* @param allowExtensions whether the extensions are allowed or not.
* @param idleTimeout Idle timeout in milli-seconds for WebSocket connection.
* @param responseHeaders Extra headers to add to the handshake response or {@code null} if no extra
* headers should
* be added.
* @param maxFramePayloadLength Maximum allowable frame payload length. Setting this value to your application's
* requirement may reduce denial of service attacks using long data frames.
* requirement may reduce denial of service attacks using long data frames.
* @return the handshake future.
*/
HandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout,
HttpHeaders responseHeaders, int maxFramePayloadLength);
ServerHandshakeFuture handshake(String[] subProtocols, boolean allowExtensions, int idleTimeout,
HttpHeaders responseHeaders, int maxFramePayloadLength);

/**
* Get the HttpCarbonRequest received from the client to perform the handshake.
*
* @return the carbon request received to perform the handshake
*/
HttpCarbonRequest getHttpCarbonRequest();


/**
* Cancel the handshake with HTTP response.
*
* @param closeCode close code for cancelling the handshake.
* @param closeCode close code for cancelling the handshake.
* @param closeReason reason for canceling the handshake.
*
* @return the ChannelPromise created after submitting response
*/
ChannelFuture cancelHandshake(int closeCode, String closeReason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.wso2.transport.http.netty.contract.websocket;

import java.util.Map;

/**
* This is the common interface for all WebSocket messages.
* <b>Note: Use this interface in the application level only and only if the user needs only the channel details
Expand Down Expand Up @@ -71,36 +69,6 @@ public interface WebSocketMessage {
*/
WebSocketConnection getWebSocketConnection();

/**
* Set header for the message.
*
* @param key key of the header.
* @param value value of the header.
*/
void setHeader(String key, String value);

/**
* Set headers for the message.
*
* @param headers map of headers which should be added to the current headers.
*/
void setHeaders(Map<String, String> headers);

/**
* Get the value of a header.
*
* @param key key of the header.
* @return the value of the header.
*/
String getHeader(String key);

/**
* Get a map of all headers.
*
* @return a map of all headers.
*/
Map<String, String> getHeaders();

/**
* Retrieve the session ID.
*
Expand Down
Loading

0 comments on commit 804048f

Please sign in to comment.