From 93a1d592d61b229d3dafe57d1590d286312cc0bf Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Thu, 18 May 2017 08:06:52 -0700 Subject: [PATCH] Update okhttp3 Reviewed By: bestander Differential Revision: D5078004 fbshipit-source-id: 79c66cedeeb682d8bb4e67798b41115899fd1c81 --- ReactAndroid/build.gradle | 7 +- .../java/com/facebook/react/devsupport/BUCK | 1 - .../InspectorPackagerConnection.java | 41 ++++----- .../devsupport/JSDebuggerWebSocketClient.java | 42 +++------ .../com/facebook/react/modules/websocket/BUCK | 1 - .../modules/websocket/WebSocketModule.java | 88 +++++++------------ .../facebook/react/packagerconnection/BUCK | 1 - .../packagerconnection/JSPackagerClient.java | 26 +++--- .../ReconnectingWebSocket.java | 47 ++++++---- .../src/main/third-party/java/okhttp/BUCK | 20 +---- .../src/main/third-party/java/okio/BUCK | 4 +- .../java/com/facebook/react/devsupport/BUCK | 1 - .../JSDebuggerWebSocketClientTest.java | 17 ++-- .../facebook/react/packagerconnection/BUCK | 1 - .../JSPackagerClientTest.java | 43 ++------- 15 files changed, 124 insertions(+), 216 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 62f2ee43a..45317e665 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -283,10 +283,9 @@ dependencies { compile 'com.facebook.fresco:imagepipeline-okhttp3:1.0.1' compile 'com.facebook.soloader:soloader:0.1.0' compile 'com.google.code.findbugs:jsr305:3.0.0' - compile 'com.squareup.okhttp3:okhttp:3.4.1' - compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1' - compile 'com.squareup.okhttp3:okhttp-ws:3.4.1' - compile 'com.squareup.okio:okio:1.9.0' + compile 'com.squareup.okhttp3:okhttp:3.8.0' + compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0' + compile 'com.squareup.okio:okio:1.13.0' compile 'org.webkit:android-jsc:r174650' testCompile "junit:junit:${JUNIT_VERSION}" diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK index b2bbafe5f..8526eba41 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK @@ -12,7 +12,6 @@ android_library( react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/okhttp:okhttp3"), - react_native_dep("third-party/java/okhttp:okhttp3-ws"), react_native_dep("third-party/java/okio:okio"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorPackagerConnection.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorPackagerConnection.java index c328e2504..04843ae05 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorPackagerConnection.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorPackagerConnection.java @@ -19,13 +19,9 @@ import com.facebook.react.bridge.Inspector; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; -import okhttp3.ws.WebSocketCall; -import okhttp3.ws.WebSocketListener; -import okio.Buffer; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -175,7 +171,7 @@ public class InspectorPackagerConnection { return payload; } - private class Connection implements WebSocketListener { + private class Connection extends WebSocketListener { private static final int RECONNECT_DELAY_MS = 2000; private final String mUrl; @@ -196,9 +192,9 @@ public class InspectorPackagerConnection { } @Override - public void onFailure(IOException e, Response response) { + public void onFailure(WebSocket webSocket, Throwable t, Response response) { if (mWebSocket != null) { - abort("Websocket exception", e); + abort("Websocket exception", t); } if (!mClosed) { reconnect(); @@ -206,22 +202,16 @@ public class InspectorPackagerConnection { } @Override - public void onMessage(ResponseBody message) throws IOException { + public void onMessage(WebSocket webSocket, String text) { try { - handleProxyMessage(new JSONObject(message.string())); - } catch (JSONException e) { - throw new IOException(e); - } finally { - message.close(); + handleProxyMessage(new JSONObject(text)); + } catch (Exception e) { + throw new RuntimeException(e); } } @Override - public void onPong(Buffer payload) { - } - - @Override - public void onClose(int code, String reason) { + public void onClosed(WebSocket webSocket, int code, String reason) { mWebSocket = null; closeAllConnections(); if (!mClosed) { @@ -240,8 +230,7 @@ public class InspectorPackagerConnection { .build(); Request request = new Request.Builder().url(mUrl).build(); - WebSocketCall call = WebSocketCall.create(httpClient, request); - call.enqueue(this); + httpClient.newWebSocket(request, this); } private void reconnect() { @@ -270,7 +259,7 @@ public class InspectorPackagerConnection { if (mWebSocket != null) { try { mWebSocket.close(1000, "End of session"); - } catch (IOException e) { + } catch (Exception e) { // swallow, no need to handle it here } mWebSocket = null; @@ -285,8 +274,8 @@ public class InspectorPackagerConnection { return null; } try { - sockets[0].sendMessage(RequestBody.create(WebSocket.TEXT, object.toString())); - } catch (IOException e) { + sockets[0].send(object.toString()); + } catch (Exception e) { FLog.w(TAG, "Couldn't send event to packager", e); } return null; @@ -304,7 +293,7 @@ public class InspectorPackagerConnection { if (mWebSocket != null) { try { mWebSocket.close(1000, "End of session"); - } catch (IOException e) { + } catch (Exception e) { // swallow, no need to handle it here } mWebSocket = null; diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDebuggerWebSocketClient.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDebuggerWebSocketClient.java index 21ddd0226..3a8124997 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDebuggerWebSocketClient.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDebuggerWebSocketClient.java @@ -18,6 +18,7 @@ import com.facebook.infer.annotation.Assertions; import com.facebook.react.common.JavascriptException; import java.io.IOException; +import java.io.StringReader; import java.io.StringWriter; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; @@ -28,18 +29,14 @@ import javax.annotation.Nullable; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; -import okhttp3.ws.WebSocketCall; -import okhttp3.ws.WebSocketListener; -import okio.Buffer; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; /** * A wrapper around WebSocketClient that recognizes RN debugging message format. */ -public class JSDebuggerWebSocketClient implements WebSocketListener { +public class JSDebuggerWebSocketClient extends WebSocketListener { private static final String TAG = "JSDebuggerWebSocketClient"; @@ -67,8 +64,7 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { .build(); Request request = new Request.Builder().url(url).build(); - WebSocketCall call = WebSocketCall.create(mHttpClient, request); - call.enqueue(this); + mHttpClient.newWebSocket(request, this); } public void prepareJSRuntime(JSDebuggerCallback callback) { @@ -142,7 +138,7 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { if (mWebSocket != null) { try { mWebSocket.close(1000, "End of session"); - } catch (IOException e) { + } catch (Exception e) { // swallow, no need to handle it here } mWebSocket = null; @@ -157,8 +153,8 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { return; } try { - mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, message)); - } catch (IOException e) { + mWebSocket.send(message); + } catch (Exception e) { triggerRequestFailure(requestID, e); } } @@ -180,16 +176,11 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { } @Override - public void onMessage(ResponseBody response) throws IOException { - if (response.contentType() != WebSocket.TEXT) { - FLog.w(TAG, "Websocket received unexpected message with payload of type " + response.contentType()); - return; - } - + public void onMessage(WebSocket webSocket, String text) { Integer replyID = null; try { - JsonReader reader = new JsonReader(response.charStream()); + JsonReader reader = new JsonReader(new StringReader(text)); String result = null; reader.beginObject(); while (reader.hasNext()) { @@ -218,14 +209,12 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { } else { abort("Parsing response message from websocket failed", e); } - } finally { - response.close(); } } @Override - public void onFailure(IOException e, Response response) { - abort("Websocket exception", e); + public void onFailure(WebSocket webSocket, Throwable t, Response response) { + abort("Websocket exception", t); } @Override @@ -236,15 +225,10 @@ public class JSDebuggerWebSocketClient implements WebSocketListener { } @Override - public void onClose(int code, String reason) { + public void onClosed(WebSocket webSocket, int code, String reason) { mWebSocket = null; } - @Override - public void onPong(Buffer payload) { - // ignore - } - private void abort(String message, Throwable cause) { FLog.e(TAG, "Error occurred, shutting down websocket connection: " + message, cause); closeQuietly(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/BUCK index 9a0c96152..6ea83d2e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/BUCK @@ -11,7 +11,6 @@ android_library( react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/okhttp:okhttp3"), - react_native_dep("third-party/java/okhttp:okhttp3-ws"), react_native_dep("third-party/java/okio:okio"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java index a114e63a0..7213bb730 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java @@ -9,11 +9,15 @@ package com.facebook.react.modules.websocket; -import android.util.Base64; +import javax.annotation.Nullable; import java.io.IOException; -import java.lang.IllegalStateException; -import javax.annotation.Nullable; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; import com.facebook.common.logging.FLog; import com.facebook.react.bridge.Arguments; @@ -33,21 +37,9 @@ import com.facebook.react.modules.network.ForwardingCookieHandler; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; -import okhttp3.ws.WebSocketCall; -import okhttp3.ws.WebSocketListener; - -import java.net.URISyntaxException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import okio.Buffer; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; import okio.ByteString; @ReactModule(name = "WebSocketModule", hasConstants = false) @@ -132,7 +124,7 @@ public class WebSocketModule extends ReactContextBaseJavaModule { } } - WebSocketCall.create(client, builder.build()).enqueue(new WebSocketListener() { + client.newWebSocket(builder.build(), new WebSocketListener() { @Override public void onOpen(WebSocket webSocket, Response response) { @@ -143,7 +135,7 @@ public class WebSocketModule extends ReactContextBaseJavaModule { } @Override - public void onClose(int code, String reason) { + public void onClosed(WebSocket webSocket, int code, String reason) { WritableMap params = Arguments.createMap(); params.putInt("id", id); params.putInt("code", code); @@ -152,40 +144,26 @@ public class WebSocketModule extends ReactContextBaseJavaModule { } @Override - public void onFailure(IOException e, Response response) { - notifyWebSocketFailed(id, e.getMessage()); + public void onFailure(WebSocket webSocket, Throwable t, Response response) { + notifyWebSocketFailed(id, t.getMessage()); } @Override - public void onPong(Buffer buffer) { - } - - @Override - public void onMessage(ResponseBody response) throws IOException { - String message; - try { - if (response.contentType() == WebSocket.BINARY) { - message = Base64.encodeToString(response.source().readByteArray(), Base64.NO_WRAP); - } else { - message = response.source().readUtf8(); - } - } catch (IOException e) { - notifyWebSocketFailed(id, e.getMessage()); - return; - } - try { - response.source().close(); - } catch (IOException e) { - FLog.e( - ReactConstants.TAG, - "Could not close BufferedSource for WebSocket id " + id, - e); - } - + public void onMessage(WebSocket webSocket, String text) { WritableMap params = Arguments.createMap(); params.putInt("id", id); - params.putString("data", message); - params.putString("type", response.contentType() == WebSocket.BINARY ? "binary" : "text"); + params.putString("data", text); + params.putString("type", "text"); + sendEvent("websocketMessage", params); + } + + @Override + public void onMessage(WebSocket webSocket, ByteString bytes) { + String text = bytes.utf8(); + WritableMap params = Arguments.createMap(); + params.putInt("id", id); + params.putString("data", text); + params.putString("type", "binary"); sendEvent("websocketMessage", params); } }); @@ -221,8 +199,8 @@ public class WebSocketModule extends ReactContextBaseJavaModule { throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id); } try { - client.sendMessage(RequestBody.create(WebSocket.TEXT, message)); - } catch (IOException | IllegalStateException e) { + client.send(message); + } catch (Exception e) { notifyWebSocketFailed(id, e.getMessage()); } } @@ -235,9 +213,8 @@ public class WebSocketModule extends ReactContextBaseJavaModule { throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id); } try { - client.sendMessage( - RequestBody.create(WebSocket.BINARY, ByteString.decodeBase64(base64String))); - } catch (IOException | IllegalStateException e) { + client.send(ByteString.decodeBase64(base64String)); + } catch (Exception e) { notifyWebSocketFailed(id, e.getMessage()); } } @@ -250,9 +227,8 @@ public class WebSocketModule extends ReactContextBaseJavaModule { throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id); } try { - Buffer buffer = new Buffer(); - client.sendPing(buffer); - } catch (IOException | IllegalStateException e) { + client.send(ByteString.EMPTY); + } catch (Exception e) { notifyWebSocketFailed(id, e.getMessage()); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/BUCK b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/BUCK index 4202a2782..605ae7481 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/BUCK @@ -17,7 +17,6 @@ android_library( react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/okhttp:okhttp3"), - react_native_dep("third-party/java/okhttp:okhttp3-ws"), react_native_dep("third-party/java/okio:okio"), react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo-moduleless"), ] + ([react_native_target("jni/packagerconnection:jni")] if not IS_OSS_BUILD else []), diff --git a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/JSPackagerClient.java b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/JSPackagerClient.java index e22a37ef7..0248973d8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/JSPackagerClient.java +++ b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/JSPackagerClient.java @@ -15,9 +15,7 @@ import android.net.Uri; import com.facebook.common.logging.FLog; import com.facebook.react.modules.systeminfo.AndroidInfoHelpers; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; +import okio.ByteString; import org.json.JSONObject; @@ -42,7 +40,7 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall message.put("version", PROTOCOL_VERSION); message.put("id", mId); message.put("result", result); - mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, message.toString())); + mWebSocket.sendMessage(message.toString()); } catch (Exception e) { FLog.e(TAG, "Responding failed", e); } @@ -54,7 +52,7 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall message.put("version", PROTOCOL_VERSION); message.put("id", mId); message.put("error", error); - mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, message.toString())); + mWebSocket.sendMessage(message.toString()); } catch (Exception e) { FLog.e(TAG, "Responding with error failed", e); } @@ -89,16 +87,9 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall } @Override - public void onMessage(ResponseBody response) { - if (response.contentType() != WebSocket.TEXT) { - FLog.w( - TAG, - "Websocket received message with payload of unexpected type " + response.contentType()); - return; - } - + public void onMessage(String text) { try { - JSONObject message = new JSONObject(response.string()); + JSONObject message = new JSONObject(text); int version = message.optInt("version"); String method = message.optString("method"); @@ -130,11 +121,14 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall } } catch (Exception e) { FLog.e(TAG, "Handling the message failed", e); - } finally { - response.close(); } } + @Override + public void onMessage(ByteString bytes) { + FLog.w(TAG, "Websocket received message with payload of unexpected type binary"); + } + private void abortOnMessage(Object id, String reason) { if (id != null) { (new ResponderImpl(id)).error(reason); diff --git a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/ReconnectingWebSocket.java b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/ReconnectingWebSocket.java index 1782df8b1..cc00f3d8e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/ReconnectingWebSocket.java +++ b/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/ReconnectingWebSocket.java @@ -21,24 +21,22 @@ import com.facebook.common.logging.FLog; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; -import okhttp3.ws.WebSocketCall; -import okhttp3.ws.WebSocketListener; -import okio.Buffer; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; +import okio.ByteString; /** * A wrapper around WebSocketClient that reconnects automatically */ -final public class ReconnectingWebSocket implements WebSocketListener { +final public class ReconnectingWebSocket extends WebSocketListener { private static final String TAG = ReconnectingWebSocket.class.getSimpleName(); private static final int RECONNECT_DELAY_MS = 2000; public interface MessageCallback { - void onMessage(ResponseBody message); + void onMessage(String text); + void onMessage(ByteString bytes); } public interface ConnectionCallback { @@ -77,8 +75,7 @@ final public class ReconnectingWebSocket implements WebSocketListener { .build(); Request request = new Request.Builder().url(mUrl).build(); - WebSocketCall call = WebSocketCall.create(httpClient, request); - call.enqueue(this); + httpClient.newWebSocket(request, this); } private synchronized void delayedReconnect() { @@ -122,7 +119,7 @@ final public class ReconnectingWebSocket implements WebSocketListener { if (mWebSocket != null) { try { mWebSocket.close(1000, "End of session"); - } catch (IOException e) { + } catch (Exception e) { // swallow, no need to handle it here } mWebSocket = null; @@ -145,9 +142,9 @@ final public class ReconnectingWebSocket implements WebSocketListener { } @Override - public synchronized void onFailure(IOException e, Response response) { + public synchronized void onFailure(WebSocket webSocket, Throwable t, Response response) { if (mWebSocket != null) { - abort("Websocket exception", e); + abort("Websocket exception", t); } if (!mClosed) { if (mConnectionCallback != null) { @@ -158,17 +155,21 @@ final public class ReconnectingWebSocket implements WebSocketListener { } @Override - public synchronized void onMessage(ResponseBody message) { + public synchronized void onMessage(WebSocket webSocket, String text) { if (mMessageCallback != null) { - mMessageCallback.onMessage(message); + mMessageCallback.onMessage(text); } } @Override - public synchronized void onPong(Buffer payload) { } + public synchronized void onMessage(WebSocket webSocket, ByteString bytes) { + if (mMessageCallback != null) { + mMessageCallback.onMessage(bytes); + } + } @Override - public synchronized void onClose(int code, String reason) { + public synchronized void onClosed(WebSocket webSocket, int code, String reason) { mWebSocket = null; if (!mClosed) { if (mConnectionCallback != null) { @@ -178,9 +179,17 @@ final public class ReconnectingWebSocket implements WebSocketListener { } } - public synchronized void sendMessage(RequestBody message) throws IOException { + public synchronized void sendMessage(String message) throws IOException { if (mWebSocket != null) { - mWebSocket.sendMessage(message); + mWebSocket.send(message); + } else { + throw new ClosedChannelException(); + } + } + + public synchronized void sendMessage(ByteString message) throws IOException { + if (mWebSocket != null) { + mWebSocket.send(message); } else { throw new ClosedChannelException(); } diff --git a/ReactAndroid/src/main/third-party/java/okhttp/BUCK b/ReactAndroid/src/main/third-party/java/okhttp/BUCK index 4d5048176..84be571ad 100644 --- a/ReactAndroid/src/main/third-party/java/okhttp/BUCK +++ b/ReactAndroid/src/main/third-party/java/okhttp/BUCK @@ -6,8 +6,8 @@ prebuilt_jar( remote_file( name = "okhttp3-binary-jar", - sha1 = "c7c4f9e35c2fd5900da24f9872e3971801f08ce0", - url = "mvn:com.squareup.okhttp3:okhttp:jar:3.4.1", + sha1 = "5a11f020cce2d11eb71ba916700600e18c4547e7", + url = "mvn:com.squareup.okhttp3:okhttp:jar:3.8.0", ) prebuilt_jar( @@ -18,18 +18,6 @@ prebuilt_jar( remote_file( name = "okhttp3-urlconnection-binary-jar", - sha1 = "63994437f62bc861bc20c605d12962f7246116d1", - url = "mvn:com.squareup.okhttp3:okhttp-urlconnection:jar:3.4.1", -) - -prebuilt_jar( - name = "okhttp3-ws", - binary_jar = ":okhttp3-ws-binary-jar", - visibility = ["//ReactAndroid/..."], -) - -remote_file( - name = "okhttp3-ws-binary-jar", - sha1 = "8ace66ef7002d98f633377c9e67daeeb196d8c3b", - url = "mvn:com.squareup.okhttp3:okhttp-ws:jar:3.4.1", + sha1 = "265257b82f20bb0371a926cc8ceb5f7bb17c0df8", + url = "mvn:com.squareup.okhttp3:okhttp-urlconnection:jar:3.8.0", ) diff --git a/ReactAndroid/src/main/third-party/java/okio/BUCK b/ReactAndroid/src/main/third-party/java/okio/BUCK index 096df3ada..45955117a 100644 --- a/ReactAndroid/src/main/third-party/java/okio/BUCK +++ b/ReactAndroid/src/main/third-party/java/okio/BUCK @@ -6,6 +6,6 @@ prebuilt_jar( remote_file( name = "okio-binary-jar", - sha1 = "f824591a0016efbaeddb8300bee54832a1398cfa", - url = "mvn:com.squareup.okio:okio:jar:1.9.0", + sha1 = "a9283170b7305c8d92d25aff02a6ab7e45d06cbe", + url = "mvn:com.squareup.okio:okio:jar:1.13.0", ) diff --git a/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK b/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK index 605c934b5..29fb02c91 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK @@ -15,7 +15,6 @@ rn_robolectric_test( react_native_dep("third-party/java/junit:junit"), react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), - react_native_dep("third-party/java/okhttp:okhttp3-ws"), react_native_dep("third-party/java/okio:okio"), react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java b/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java index 1b94389a4..ec8637c06 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java @@ -22,8 +22,7 @@ import org.robolectric.RobolectricTestRunner; import java.util.HashMap; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; +import okio.ByteString; import static org.mockito.Mockito.*; @@ -78,7 +77,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_WithInvalidContentType_ShouldNotTriggerCallbacks() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.BINARY, "{\"replyID\":0, \"result\":\"OK\"}")); + client.onMessage(null, ByteString.encodeUtf8("{\"replyID\":0, \"result\":\"OK\"}")); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString()); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -87,7 +86,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_WithoutReplyId_ShouldNotTriggerCallbacks() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"result\":\"OK\"}")); + client.onMessage(null, "{\"result\":\"OK\"}"); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString()); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -96,7 +95,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_With_Null_ReplyId_ShouldNotTriggerCallbacks() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":null, \"result\":\"OK\"}")); + client.onMessage(null, "{\"replyID\":null, \"result\":\"OK\"}"); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString()); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -105,7 +104,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_WithResult_ShouldTriggerRequestSuccess() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"result\":\"OK\"}")); + client.onMessage(null, "{\"replyID\":0, \"result\":\"OK\"}"); PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", 0, "OK"); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -114,7 +113,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_With_Null_Result_ShouldTriggerRequestSuccess() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"result\":null}")); + client.onMessage(null, "{\"replyID\":0, \"result\":null}"); PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", 0, null); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -123,7 +122,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_WithError_ShouldCallAbort() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"error\":\"BOOM\"}")); + client.onMessage(null, "{\"replyID\":0, \"error\":\"BOOM\"}"); PowerMockito.verifyPrivate(client).invoke("abort", eq("BOOM"), isA(JavascriptException.class)); } @@ -131,7 +130,7 @@ public class JSDebuggerWebSocketClientTest { public void test_onMessage_With_Null_Error_ShouldTriggerRequestSuccess() throws Exception { JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); - client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"error\":null}")); + client.onMessage(null, "{\"replyID\":0, \"error\":null}"); PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", anyInt(), anyString()); } } diff --git a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK index 4da3f2764..46db01689 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK @@ -15,7 +15,6 @@ rn_robolectric_test( react_native_dep("third-party/java/junit:junit"), react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), - react_native_dep("third-party/java/okhttp:okhttp3-ws"), react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react/packagerconnection:packagerconnection"), ], diff --git a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/JSPackagerClientTest.java b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/JSPackagerClientTest.java index 165ab5e82..41bc84647 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/JSPackagerClientTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/JSPackagerClientTest.java @@ -17,8 +17,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import okhttp3.ResponseBody; -import okhttp3.ws.WebSocket; +import okio.ByteString; import static org.mockito.Mockito.*; import org.robolectric.RobolectricTestRunner; @@ -47,10 +46,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 2, \"method\": \"methodValue\", \"params\": \"paramsValue\"}")); + client.onMessage("{\"version\": 2, \"method\": \"methodValue\", \"params\": \"paramsValue\"}"); verify(handler).onNotification(eq("paramsValue")); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -60,10 +56,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}")); + client.onMessage("{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}"); verify(handler, never()).onNotification(any()); verify(handler).onRequest(eq("paramsValue"), any(Responder.class)); } @@ -73,10 +66,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 2, \"method\": \"methodValue\"}")); + client.onMessage("{\"version\": 2, \"method\": \"methodValue\"}"); verify(handler).onNotification(eq(null)); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -86,10 +76,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.BINARY, - "{\"version\": 2, \"method\": \"methodValue\"}")); + client.onMessage(ByteString.encodeUtf8("{\"version\": 2, \"method\": \"methodValue\"}")); verify(handler, never()).onNotification(any()); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -99,10 +86,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 2}")); + client.onMessage("{\"version\": 2}"); verify(handler, never()).onNotification(any()); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -112,10 +96,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 2, \"method\": null}")); + client.onMessage("{\"version\": 2, \"method\": null}"); verify(handler, never()).onNotification(any()); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -125,10 +106,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.BINARY, - "{\"version\": 2, \"method\": \"methodValue2\"}")); + client.onMessage(ByteString.EMPTY); verify(handler, never()).onNotification(any()); verify(handler, never()).onRequest(any(), any(Responder.class)); } @@ -138,10 +116,7 @@ public class JSPackagerClientTest { RequestHandler handler = mock(RequestHandler.class); final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler)); - client.onMessage( - ResponseBody.create( - WebSocket.TEXT, - "{\"version\": 1, \"method\": \"methodValue\"}")); + client.onMessage("{\"version\": 1, \"method\": \"methodValue\"}"); verify(handler, never()).onNotification(any()); verify(handler, never()).onRequest(any(), any(Responder.class)); }