Skip to content

Commit

Permalink
Merge pull request square#2852 from square/jw/web-sockets
Browse files Browse the repository at this point in the history
Move WebSockets from separate artifact to main.
  • Loading branch information
swankjesse authored Sep 14, 2016
2 parents b2b4f4a + 039bcf9 commit 7135628
Show file tree
Hide file tree
Showing 33 changed files with 119 additions and 267 deletions.
5 changes: 0 additions & 5 deletions mockwebserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>okhttp-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import okhttp3.Headers;
import okhttp3.internal.Internal;
import okhttp3.internal.http2.Settings;
import okhttp3.ws.WebSocketListener;
import okhttp3.WebSocketListener;
import okio.Buffer;

/** A scripted response to be replayed by the mock web server. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import okhttp3.internal.platform.Platform;
import okhttp3.internal.ws.RealWebSocket;
import okhttp3.internal.ws.WebSocketProtocol;
import okhttp3.ws.WebSocketListener;
import okhttp3.WebSocketListener;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -ex
wstest -m fuzzingserver -s fuzzingserver-config.json &
sleep 2 # wait for wstest to start

java -jar target/okhttp-ws-tests-*-jar-with-dependencies.jar
java -jar target/okhttp-tests-*-jar-with-dependencies.jar

jq '.[] as $in | $in | keys[] | . + " " + $in[.].behavior' target/fuzzingserver-report/index.json > target/fuzzingserver-actual.txt

Expand Down
22 changes: 22 additions & 0 deletions okhttp-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>okhttp3.AutobahnTester</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Do not deploy this as an artifact to Maven central. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.ws;
package okhttp3;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;
Expand All @@ -22,17 +22,12 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.Version;
import okio.Buffer;
import okio.BufferedSource;

import static okhttp3.ws.WebSocket.BINARY;
import static okhttp3.ws.WebSocket.TEXT;
import static okhttp3.WebSocket.BINARY;
import static okhttp3.WebSocket.TEXT;

/**
* Exercises the web socket implementation against the <a
Expand All @@ -49,7 +44,7 @@ public static void main(String... args) throws IOException {

private WebSocketCall newWebSocket(String path) {
Request request = new Request.Builder().url(HOST + path).build();
return WebSocketCall.create(client, request);
return client.newWebSocketCall(request);
}

public void run() throws IOException {
Expand Down
1 change: 0 additions & 1 deletion okhttp-tests/src/test/java/okhttp3/RecordedResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import okhttp3.ws.WebSocket;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.ws;
package okhttp3;

import java.io.IOException;
import java.net.ProtocolException;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.RecordingHostnameVerifier;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.tls.SslClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand All @@ -36,7 +29,7 @@
import org.junit.Rule;
import org.junit.Test;

import static okhttp3.ws.WebSocket.TEXT;
import static okhttp3.WebSocket.TEXT;
import static org.junit.Assert.assertNotNull;

public final class WebSocketCallTest {
Expand Down Expand Up @@ -231,7 +224,7 @@ private WebSocket awaitWebSocket() {
}

private WebSocket awaitWebSocket(Request request) {
WebSocketCall call = new WebSocketCall(client, request, random);
WebSocketCall call = new RealWebSocketCall(client, request, random);

final AtomicReference<Response> responseRef = new AtomicReference<>();
final AtomicReference<WebSocket> webSocketRef = new AtomicReference<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.ws;
package okhttp3;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;
Expand All @@ -22,11 +22,13 @@
import okhttp3.MediaType;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okhttp3.internal.ws.WebSocketReader;
import okio.Buffer;

import static okhttp3.ws.WebSocket.BINARY;
import static okhttp3.ws.WebSocket.TEXT;
import static okhttp3.WebSocket.BINARY;
import static okhttp3.WebSocket.TEXT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.concurrent.Executor;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ws.WebSocketRecorder;
import okhttp3.WebSocketRecorder;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
Expand All @@ -35,8 +35,8 @@
import org.junit.Before;
import org.junit.Test;

import static okhttp3.ws.WebSocket.BINARY;
import static okhttp3.ws.WebSocket.TEXT;
import static okhttp3.WebSocket.BINARY;
import static okhttp3.WebSocket.TEXT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.regex.Pattern;
import okhttp3.ResponseBody;
import okhttp3.internal.Util;
import okhttp3.ws.WebSocketRecorder;
import okhttp3.ws.WebSocketRecorder.MessageDelegate;
import okhttp3.WebSocketRecorder;
import okhttp3.WebSocketRecorder.MessageDelegate;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
Expand Down
76 changes: 0 additions & 76 deletions okhttp-ws-tests/pom.xml

This file was deleted.

22 changes: 0 additions & 22 deletions okhttp-ws/README.md

This file was deleted.

37 changes: 0 additions & 37 deletions okhttp-ws/pom.xml

This file was deleted.

19 changes: 9 additions & 10 deletions okhttp/src/main/java/okhttp3/OkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
* <p>OkHttp also uses daemon threads for HTTP/2 connections. These will exit automatically if they
* remain idle.
*/
public class OkHttpClient implements Cloneable, Call.Factory {
public class OkHttpClient implements Cloneable, Call.Factory, WebSocketCall.Factory {
private static final List<Protocol> DEFAULT_PROTOCOLS = Util.immutableList(
Protocol.HTTP_2, Protocol.HTTP_1_1);

Expand Down Expand Up @@ -154,10 +154,6 @@ public class OkHttpClient implements Cloneable, Call.Factory {
return connectionPool.routeDatabase;
}

@Override public StreamAllocation callEngineGetStreamAllocation(Call call) {
return ((RealCall) call).streamAllocation();
}

@Override
public void apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, boolean isFallback) {
tlsConfiguration.apply(sslSocket, isFallback);
Expand All @@ -167,10 +163,6 @@ public void apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, boolean
throws MalformedURLException, UnknownHostException {
return HttpUrl.getChecked(url);
}

@Override public void setCallWebSocket(Call call) {
((RealCall) call).setForWebSocket();
}
};
}

Expand Down Expand Up @@ -385,7 +377,14 @@ public List<Interceptor> networkInterceptors() {
* Prepares the {@code request} to be executed at some point in the future.
*/
@Override public Call newCall(Request request) {
return new RealCall(this, request);
return new RealCall(this, request, false /* for web socket */);
}

/**
* Prepares the {@code request} to create a web socket at some point in the future.
*/
@Override public WebSocketCall newWebSocketCall(Request request) {
return new RealWebSocketCall(this, request);
}

public Builder newBuilder() {
Expand Down
Loading

0 comments on commit 7135628

Please sign in to comment.