Skip to content

WebSocket supports for Netty and Grizzly Provider #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Dec 16, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,31 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>7.1.4.v20100610</version>
<version>8.1.0.RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>7.1.4.v20100610</version>
<version>8.1.0.RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>8.1.0.RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>7.1.4.v20100610</version>
<version>8.1.0.RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>7.1.4.v20100610</version>
<version>8.1.0.RC1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -443,7 +449,7 @@
<dependencies>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http</artifactId>
<artifactId>grizzly-websockets</artifactId>
<version>2.2-SNAPSHOT</version>
<optional>true</optional>
</dependency>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/ning/http/client/AsyncHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public static enum STATE {
/**
* Continue the processing
*/
CONTINUE
CONTINUE,
/**
* Upgrade the protocol. When specified, the AsyncHttpProvider will try to invoke the {@link UpgradeHandler#onReady}
*/
UPGRADE
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/ning/http/client/RequestBuilderBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ private String toUrl(boolean encode) {
url = "http://localhost";
}

String uri;
try {
uri = URI.create(url).toURL().toString();
} catch (Throwable e) {
throw new IllegalArgumentException("Illegal URL: " + url, e);
String uri = url;
if (!uri.startsWith("ws")) {
try {
uri = URI.create(url).toURL().toString();
} catch (Throwable e) {
throw new IllegalArgumentException("Illegal URL: " + url, e);
}
}

if (queryParams != null && !queryParams.isEmpty()) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/ning/http/client/UpgradeHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.ning.http.client;

/**
* Invoked when an {@link AsyncHandler.STATE#UPGRADE} is returned. Currently the library only support {@link WebSocket}
* as type.
*
* @param <T>
*/
public interface UpgradeHandler<T> {

/**
* If the HTTP Upgrade succeed (response's status code equals 101), the {@link AsyncHttpProvider} will invoke that
* method
*
* @param t an Upgradable entity
*/
void onSuccess(T t);

/**
* If the upgrade fail.
* @param t a {@link Throwable}
*/
void onFailure(Throwable t);

}
Loading