From e46f64293f9a3c294c169adf834bf2bd6af660bf Mon Sep 17 00:00:00 2001 From: Patrick Sung Date: Tue, 29 Apr 2025 09:50:53 +0800 Subject: [PATCH 1/3] Allow setting a custom EventListener in ApiClientBuilder --- .../bot/client/base/ApiClientBuilder.java | 20 ++ .../base/http/EventListenerAdapter.java | 185 ++++++++++++++++++ .../bot/client/base/http/HttpCall.java | 35 ++++ .../bot/client/base/http/HttpConnection.java | 31 +++ .../bot/client/base/http/HttpEndpoint.java | 31 +++ .../client/base/http/HttpEventListener.java | 112 +++++++++++ .../bot/client/base/http/HttpProtocol.java | 31 +++ .../bot/client/base/http/TlsHandshake.java | 31 +++ 8 files changed, 476 insertions(+) create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java create mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java index c28ed72ac..9d41228be 100644 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java @@ -30,13 +30,16 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.linecorp.bot.client.base.http.EventListenerAdapter; import com.linecorp.bot.client.base.http.HttpAuthenticator; import com.linecorp.bot.client.base.http.HttpChain; +import com.linecorp.bot.client.base.http.HttpEventListener; import com.linecorp.bot.client.base.http.HttpInterceptor; import com.linecorp.bot.client.base.http.HttpResponse; import com.linecorp.bot.jackson.ModelObjectMapper; import okhttp3.Dispatcher; +import okhttp3.EventListener; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -89,6 +92,13 @@ public ApiClientBuilder(URI apiEndPoint, Class clientClass, ExceptionBuilder */ private List additionalInterceptors = new ArrayList<>(); + /** + * Custom EventListener + * + *

You can add your own EventListener. + */ + private EventListener eventListener; + private Proxy proxy; private HttpAuthenticator proxyAuthenticator; @@ -141,6 +151,11 @@ public ApiClientBuilder addInterceptor(HttpInterceptor interceptor) { return this; } + public ApiClientBuilder setEventListener(HttpEventListener httpEventListener) { + this.eventListener = new EventListenerAdapter(httpEventListener); + return this; + } + /** * The maximum number of requests to execute concurrently. * Default: 64 @@ -230,6 +245,10 @@ public T build() { } }); + if (this.eventListener != null) { + okHttpClientBuilder.eventListener(this.eventListener); + } + if (this.proxy != null) { okHttpClientBuilder.proxy(this.proxy); } @@ -262,6 +281,7 @@ public String toString() { + ", readTimeout=" + readTimeout + ", writeTimeout=" + writeTimeout + ", additionalInterceptors=" + additionalInterceptors + + ", eventListener=" + eventListener + ", maxRequests=" + maxRequests + ", maxRequestsPerHost=" + maxRequestsPerHost + '}'; diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java new file mode 100644 index 000000000..2a26921d6 --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java @@ -0,0 +1,185 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.util.List; + +import okhttp3.Call; +import okhttp3.Connection; +import okhttp3.EventListener; +import okhttp3.Handshake; +import okhttp3.HttpUrl; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.Response; + +public class EventListenerAdapter extends EventListener { + private final HttpEventListener httpEventListener; + + public EventListenerAdapter(HttpEventListener httpEventListener) { + this.httpEventListener = httpEventListener; + } + + @Override + public void callStart(Call call) { + httpEventListener.callStart(new HttpCall(call)); + } + + @Override + public void proxySelectStart(Call call, HttpUrl url) { + httpEventListener.proxySelectStart(new HttpCall(call), new HttpEndpoint(url)); + } + + @Override + public void proxySelectEnd(Call call, HttpUrl url, List proxies) { + httpEventListener.proxySelectEnd(new HttpCall(call), new HttpEndpoint(url), proxies); + } + + @Override + public void dnsStart(Call call, String domainName) { + httpEventListener.dnsStart(new HttpCall(call), domainName); + } + + @Override + public void dnsEnd(Call call, String domainName, List inetAddressList) { + httpEventListener.dnsEnd(new HttpCall(call), domainName, inetAddressList); + } + + @Override + public void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy) { + httpEventListener.connectStart(new HttpCall(call), inetSocketAddress, proxy); + } + + @Override + public void secureConnectStart(Call call) { + httpEventListener.secureConnectStart(new HttpCall(call)); + } + + @Override + public void secureConnectEnd(Call call, Handshake handshake) { + httpEventListener.secureConnectEnd(new HttpCall(call), handshake != null ? new TlsHandshake(handshake) : null); + } + + @Override + public void connectEnd(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol) { + httpEventListener.connectEnd(new HttpCall(call), inetSocketAddress, proxy, protocol != null ? new HttpProtocol(protocol) : null); + } + + @Override + public void connectFailed(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol, IOException ioe) { + httpEventListener.connectFailed(new HttpCall(call), inetSocketAddress, proxy, protocol != null ? new HttpProtocol(protocol) : null, ioe); + } + + @Override + public void connectionAcquired(Call call, Connection connection) { + httpEventListener.connectionAcquired(new HttpCall(call), new HttpConnection(connection)); + } + + @Override + public void connectionReleased(Call call, Connection connection) { + httpEventListener.connectionReleased(new HttpCall(call), new HttpConnection(connection)); + } + + @Override + public void requestHeadersStart(Call call) { + httpEventListener.requestHeadersStart(new HttpCall(call)); + } + + @Override + public void requestHeadersEnd(Call call, Request request) { + httpEventListener.requestHeadersEnd(new HttpCall(call), new HttpRequest(request)); + } + + @Override + public void requestBodyStart(Call call) { + httpEventListener.requestBodyStart(new HttpCall(call)); + } + + @Override + public void requestBodyEnd(Call call, long byteCount) { + httpEventListener.requestBodyEnd(new HttpCall(call), byteCount); + } + + @Override + public void requestFailed(Call call, IOException ioe) { + httpEventListener.requestFailed(new HttpCall(call), ioe); + } + + @Override + public void responseHeadersStart(Call call) { + httpEventListener.responseHeadersStart(new HttpCall(call)); + } + + @Override + public void responseHeadersEnd(Call call, Response response) { + httpEventListener.responseHeadersEnd(new HttpCall(call), new HttpResponse(response)); + } + + @Override + public void responseBodyStart(Call call) { + httpEventListener.responseBodyStart(new HttpCall(call)); + } + + @Override + public void responseBodyEnd(Call call, long byteCount) { + httpEventListener.responseBodyEnd(new HttpCall(call), byteCount); + } + + @Override + public void responseFailed(Call call, IOException ioe) { + httpEventListener.responseFailed(new HttpCall(call), ioe); + } + + @Override + public void callEnd(Call call) { + httpEventListener.callEnd(new HttpCall(call)); + } + + @Override + public void callFailed(Call call, IOException ioe) { + httpEventListener.callFailed(new HttpCall(call), ioe); + } + + @Override + public void canceled(Call call) { + httpEventListener.canceled(new HttpCall(call)); + } + + @Override + public void satisfactionFailure(Call call, Response response) { + httpEventListener.satisfactionFailure(new HttpCall(call), new HttpResponse(response)); + } + + @Override + public void cacheHit(Call call, Response response) { + httpEventListener.cacheHit(new HttpCall(call), new HttpResponse(response)); + } + + @Override + public void cacheMiss(Call call) { + httpEventListener.cacheMiss(new HttpCall(call)); + } + + @Override + public void cacheConditionalHit(Call call, Response cachedResponse) { + httpEventListener.cacheConditionalHit(new HttpCall(call), new HttpResponse(cachedResponse)); + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java new file mode 100644 index 000000000..8d42a6ecd --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java @@ -0,0 +1,35 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import okhttp3.Call; + +public class HttpCall { + private final Call call; + + public HttpCall(Call call) { + this.call = call; + } + + public HttpRequest request() { + return new HttpRequest(call.request()); + } + + public Call toOkHttpCall() { + return call; + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java new file mode 100644 index 000000000..d67923cb5 --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java @@ -0,0 +1,31 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import okhttp3.Connection; + +public class HttpConnection { + private final Connection connection; + + public HttpConnection(Connection connection) { + this.connection = connection; + } + + public Connection toOkHttpConnection() { + return connection; + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java new file mode 100644 index 000000000..9a8bf27fd --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java @@ -0,0 +1,31 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import okhttp3.HttpUrl; + +public class HttpEndpoint { + private final HttpUrl httpUrl; + + public HttpEndpoint(HttpUrl httpUrl) { + this.httpUrl = httpUrl; + } + + public HttpUrl toOkHttpUrl() { + return httpUrl; + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java new file mode 100644 index 000000000..7d03944f1 --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java @@ -0,0 +1,112 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.util.List; + +public abstract class HttpEventListener { + public void callStart(HttpCall httpCall) { + } + + public void proxySelectStart(HttpCall httpCall, HttpEndpoint httpEndpoint) { + } + + public void proxySelectEnd(HttpCall httpCall, HttpEndpoint httpEndpoint, List proxies) { + } + + public void dnsStart(HttpCall httpCall, String domainName) { + } + + public void dnsEnd(HttpCall httpCall, String domainName, List inetAddressList) { + } + + public void connectStart(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy) { + } + + public void secureConnectStart(HttpCall httpCall) { + } + + public void secureConnectEnd(HttpCall httpCall, TlsHandshake tlsHandshake) { + } + + public void connectEnd(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy, HttpProtocol httpProtocol) { + } + + public void connectFailed(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy, HttpProtocol httpProtocol, IOException ioe) { + } + + public void connectionAcquired(HttpCall httpCall, HttpConnection httpConnection) { + } + + public void connectionReleased(HttpCall httpCall, HttpConnection httpConnection) { + } + + public void requestHeadersStart(HttpCall httpCall) { + } + + public void requestHeadersEnd(HttpCall httpCall, HttpRequest httpRequest) { + } + + public void requestBodyStart(HttpCall httpCall) { + } + + public void requestBodyEnd(HttpCall httpCall, long byteCount) { + } + + public void requestFailed(HttpCall httpCall, IOException ioe) { + } + + public void responseHeadersStart(HttpCall httpCall) { + } + + public void responseHeadersEnd(HttpCall httpCall, HttpResponse httpResponse) { + } + + public void responseBodyStart(HttpCall httpCall) { + } + + public void responseBodyEnd(HttpCall httpCall, long byteCount) { + } + + public void responseFailed(HttpCall httpCall, IOException ioe) { + } + + public void callEnd(HttpCall httpCall) { + } + + public void callFailed(HttpCall httpCall, IOException ioe) { + } + + public void canceled(HttpCall httpCall) { + } + + public void satisfactionFailure(HttpCall httpCall, HttpResponse httpResponse) { + } + + public void cacheHit(HttpCall httpCall, HttpResponse httpResponse) { + } + + public void cacheMiss(HttpCall httpCall) { + } + + public void cacheConditionalHit(HttpCall call, HttpResponse cachedResponse) { + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java new file mode 100644 index 000000000..a609b869b --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java @@ -0,0 +1,31 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import okhttp3.Protocol; + +public class HttpProtocol { + private final Protocol protocol; + + public HttpProtocol(Protocol protocol) { + this.protocol = protocol; + } + + public Protocol toOkHttpProtocol() { + return protocol; + } +} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java new file mode 100644 index 000000000..789e4a808 --- /dev/null +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java @@ -0,0 +1,31 @@ +/* + * Copyright 2025 LINE Corporation + * + * LINE Corporation 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 com.linecorp.bot.client.base.http; + +import okhttp3.Handshake; + +public class TlsHandshake { + private final Handshake handshake; + + public TlsHandshake(Handshake handshake) { + this.handshake = handshake; + } + + public Handshake toOkHttpHandshake() { + return handshake; + } +} From 196053ddc3f90cd0811dbd3968f013a7d12a3d81 Mon Sep 17 00:00:00 2001 From: Patrick Sung Date: Thu, 5 Jun 2025 14:38:26 +0800 Subject: [PATCH 2/3] Directly expose okhttp's EventListener class --- .../bot/client/base/ApiClientBuilder.java | 6 +- .../base/http/EventListenerAdapter.java | 185 ------------------ .../bot/client/base/http/HttpCall.java | 35 ---- .../bot/client/base/http/HttpConnection.java | 31 --- .../bot/client/base/http/HttpEndpoint.java | 31 --- .../client/base/http/HttpEventListener.java | 112 ----------- .../bot/client/base/http/HttpProtocol.java | 31 --- .../bot/client/base/http/TlsHandshake.java | 31 --- 8 files changed, 2 insertions(+), 460 deletions(-) delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java delete mode 100644 clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java index 9d41228be..f47a052ac 100644 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java +++ b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java @@ -30,10 +30,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.linecorp.bot.client.base.http.EventListenerAdapter; import com.linecorp.bot.client.base.http.HttpAuthenticator; import com.linecorp.bot.client.base.http.HttpChain; -import com.linecorp.bot.client.base.http.HttpEventListener; import com.linecorp.bot.client.base.http.HttpInterceptor; import com.linecorp.bot.client.base.http.HttpResponse; import com.linecorp.bot.jackson.ModelObjectMapper; @@ -151,8 +149,8 @@ public ApiClientBuilder addInterceptor(HttpInterceptor interceptor) { return this; } - public ApiClientBuilder setEventListener(HttpEventListener httpEventListener) { - this.eventListener = new EventListenerAdapter(httpEventListener); + public ApiClientBuilder setEventListener(EventListener eventListener) { + this.eventListener = eventListener; return this; } diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java deleted file mode 100644 index 2a26921d6..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/EventListenerAdapter.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.util.List; - -import okhttp3.Call; -import okhttp3.Connection; -import okhttp3.EventListener; -import okhttp3.Handshake; -import okhttp3.HttpUrl; -import okhttp3.Protocol; -import okhttp3.Request; -import okhttp3.Response; - -public class EventListenerAdapter extends EventListener { - private final HttpEventListener httpEventListener; - - public EventListenerAdapter(HttpEventListener httpEventListener) { - this.httpEventListener = httpEventListener; - } - - @Override - public void callStart(Call call) { - httpEventListener.callStart(new HttpCall(call)); - } - - @Override - public void proxySelectStart(Call call, HttpUrl url) { - httpEventListener.proxySelectStart(new HttpCall(call), new HttpEndpoint(url)); - } - - @Override - public void proxySelectEnd(Call call, HttpUrl url, List proxies) { - httpEventListener.proxySelectEnd(new HttpCall(call), new HttpEndpoint(url), proxies); - } - - @Override - public void dnsStart(Call call, String domainName) { - httpEventListener.dnsStart(new HttpCall(call), domainName); - } - - @Override - public void dnsEnd(Call call, String domainName, List inetAddressList) { - httpEventListener.dnsEnd(new HttpCall(call), domainName, inetAddressList); - } - - @Override - public void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy) { - httpEventListener.connectStart(new HttpCall(call), inetSocketAddress, proxy); - } - - @Override - public void secureConnectStart(Call call) { - httpEventListener.secureConnectStart(new HttpCall(call)); - } - - @Override - public void secureConnectEnd(Call call, Handshake handshake) { - httpEventListener.secureConnectEnd(new HttpCall(call), handshake != null ? new TlsHandshake(handshake) : null); - } - - @Override - public void connectEnd(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol) { - httpEventListener.connectEnd(new HttpCall(call), inetSocketAddress, proxy, protocol != null ? new HttpProtocol(protocol) : null); - } - - @Override - public void connectFailed(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol, IOException ioe) { - httpEventListener.connectFailed(new HttpCall(call), inetSocketAddress, proxy, protocol != null ? new HttpProtocol(protocol) : null, ioe); - } - - @Override - public void connectionAcquired(Call call, Connection connection) { - httpEventListener.connectionAcquired(new HttpCall(call), new HttpConnection(connection)); - } - - @Override - public void connectionReleased(Call call, Connection connection) { - httpEventListener.connectionReleased(new HttpCall(call), new HttpConnection(connection)); - } - - @Override - public void requestHeadersStart(Call call) { - httpEventListener.requestHeadersStart(new HttpCall(call)); - } - - @Override - public void requestHeadersEnd(Call call, Request request) { - httpEventListener.requestHeadersEnd(new HttpCall(call), new HttpRequest(request)); - } - - @Override - public void requestBodyStart(Call call) { - httpEventListener.requestBodyStart(new HttpCall(call)); - } - - @Override - public void requestBodyEnd(Call call, long byteCount) { - httpEventListener.requestBodyEnd(new HttpCall(call), byteCount); - } - - @Override - public void requestFailed(Call call, IOException ioe) { - httpEventListener.requestFailed(new HttpCall(call), ioe); - } - - @Override - public void responseHeadersStart(Call call) { - httpEventListener.responseHeadersStart(new HttpCall(call)); - } - - @Override - public void responseHeadersEnd(Call call, Response response) { - httpEventListener.responseHeadersEnd(new HttpCall(call), new HttpResponse(response)); - } - - @Override - public void responseBodyStart(Call call) { - httpEventListener.responseBodyStart(new HttpCall(call)); - } - - @Override - public void responseBodyEnd(Call call, long byteCount) { - httpEventListener.responseBodyEnd(new HttpCall(call), byteCount); - } - - @Override - public void responseFailed(Call call, IOException ioe) { - httpEventListener.responseFailed(new HttpCall(call), ioe); - } - - @Override - public void callEnd(Call call) { - httpEventListener.callEnd(new HttpCall(call)); - } - - @Override - public void callFailed(Call call, IOException ioe) { - httpEventListener.callFailed(new HttpCall(call), ioe); - } - - @Override - public void canceled(Call call) { - httpEventListener.canceled(new HttpCall(call)); - } - - @Override - public void satisfactionFailure(Call call, Response response) { - httpEventListener.satisfactionFailure(new HttpCall(call), new HttpResponse(response)); - } - - @Override - public void cacheHit(Call call, Response response) { - httpEventListener.cacheHit(new HttpCall(call), new HttpResponse(response)); - } - - @Override - public void cacheMiss(Call call) { - httpEventListener.cacheMiss(new HttpCall(call)); - } - - @Override - public void cacheConditionalHit(Call call, Response cachedResponse) { - httpEventListener.cacheConditionalHit(new HttpCall(call), new HttpResponse(cachedResponse)); - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java deleted file mode 100644 index 8d42a6ecd..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpCall.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import okhttp3.Call; - -public class HttpCall { - private final Call call; - - public HttpCall(Call call) { - this.call = call; - } - - public HttpRequest request() { - return new HttpRequest(call.request()); - } - - public Call toOkHttpCall() { - return call; - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java deleted file mode 100644 index d67923cb5..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpConnection.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import okhttp3.Connection; - -public class HttpConnection { - private final Connection connection; - - public HttpConnection(Connection connection) { - this.connection = connection; - } - - public Connection toOkHttpConnection() { - return connection; - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java deleted file mode 100644 index 9a8bf27fd..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEndpoint.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import okhttp3.HttpUrl; - -public class HttpEndpoint { - private final HttpUrl httpUrl; - - public HttpEndpoint(HttpUrl httpUrl) { - this.httpUrl = httpUrl; - } - - public HttpUrl toOkHttpUrl() { - return httpUrl; - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java deleted file mode 100644 index 7d03944f1..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpEventListener.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.util.List; - -public abstract class HttpEventListener { - public void callStart(HttpCall httpCall) { - } - - public void proxySelectStart(HttpCall httpCall, HttpEndpoint httpEndpoint) { - } - - public void proxySelectEnd(HttpCall httpCall, HttpEndpoint httpEndpoint, List proxies) { - } - - public void dnsStart(HttpCall httpCall, String domainName) { - } - - public void dnsEnd(HttpCall httpCall, String domainName, List inetAddressList) { - } - - public void connectStart(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy) { - } - - public void secureConnectStart(HttpCall httpCall) { - } - - public void secureConnectEnd(HttpCall httpCall, TlsHandshake tlsHandshake) { - } - - public void connectEnd(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy, HttpProtocol httpProtocol) { - } - - public void connectFailed(HttpCall httpCall, InetSocketAddress inetSocketAddress, Proxy proxy, HttpProtocol httpProtocol, IOException ioe) { - } - - public void connectionAcquired(HttpCall httpCall, HttpConnection httpConnection) { - } - - public void connectionReleased(HttpCall httpCall, HttpConnection httpConnection) { - } - - public void requestHeadersStart(HttpCall httpCall) { - } - - public void requestHeadersEnd(HttpCall httpCall, HttpRequest httpRequest) { - } - - public void requestBodyStart(HttpCall httpCall) { - } - - public void requestBodyEnd(HttpCall httpCall, long byteCount) { - } - - public void requestFailed(HttpCall httpCall, IOException ioe) { - } - - public void responseHeadersStart(HttpCall httpCall) { - } - - public void responseHeadersEnd(HttpCall httpCall, HttpResponse httpResponse) { - } - - public void responseBodyStart(HttpCall httpCall) { - } - - public void responseBodyEnd(HttpCall httpCall, long byteCount) { - } - - public void responseFailed(HttpCall httpCall, IOException ioe) { - } - - public void callEnd(HttpCall httpCall) { - } - - public void callFailed(HttpCall httpCall, IOException ioe) { - } - - public void canceled(HttpCall httpCall) { - } - - public void satisfactionFailure(HttpCall httpCall, HttpResponse httpResponse) { - } - - public void cacheHit(HttpCall httpCall, HttpResponse httpResponse) { - } - - public void cacheMiss(HttpCall httpCall) { - } - - public void cacheConditionalHit(HttpCall call, HttpResponse cachedResponse) { - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java deleted file mode 100644 index a609b869b..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/HttpProtocol.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import okhttp3.Protocol; - -public class HttpProtocol { - private final Protocol protocol; - - public HttpProtocol(Protocol protocol) { - this.protocol = protocol; - } - - public Protocol toOkHttpProtocol() { - return protocol; - } -} diff --git a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java b/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java deleted file mode 100644 index 789e4a808..000000000 --- a/clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/http/TlsHandshake.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2025 LINE Corporation - * - * LINE Corporation 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 com.linecorp.bot.client.base.http; - -import okhttp3.Handshake; - -public class TlsHandshake { - private final Handshake handshake; - - public TlsHandshake(Handshake handshake) { - this.handshake = handshake; - } - - public Handshake toOkHttpHandshake() { - return handshake; - } -} From 08a4917be7db98d5d9bb1b20180719d8abfa561a Mon Sep 17 00:00:00 2001 From: Patrick Sung Date: Thu, 5 Jun 2025 14:40:34 +0800 Subject: [PATCH 3/3] Update line-openapi submodule --- line-openapi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/line-openapi b/line-openapi index 69c7f21a2..92f9320b8 160000 --- a/line-openapi +++ b/line-openapi @@ -1 +1 @@ -Subproject commit 69c7f21a2a0a7bfc4870346a565d75105e432128 +Subproject commit 92f9320b891ee6a071c93220ce4a3e34e1f4d38b