From 26a137873bb7067dc355b8a505ffb9530aa14b8c Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Tue, 21 Nov 2023 19:45:54 +0800 Subject: [PATCH 1/6] fix(#proxy) : support http proxy --- app-stream-api/pom.xml | 2 +- .../app/api/OpenDingTalkStreamClient.java | 17 +++++++++----- .../api/OpenDingTalkStreamClientBuilder.java | 18 ++++++++++++++- .../open/app/api/open/HttpOpenApiClient.java | 13 +++++++++-- .../open/app/api/open/OpenApiClient.java | 4 +++- .../app/api/open/OpenApiClientBuilder.java | 4 ++++ app-stream-client/pom.xml | 4 ++-- .../app-stream-network-api/pom.xml | 4 ++-- .../network/api/EndPointConnection.java | 9 +++++++- .../open/app/stream/network/api/NetProxy.java | 23 +++++++++++++++++++ .../app-stream-network-core/pom.xml | 2 +- .../network/core/DefaultSessionPool.java | 5 +++- .../stream/network/core/NetWorkService.java | 15 +++++------- .../app-stream-network-rsocket/pom.xml | 2 +- .../app-stream-network-ws/pom.xml | 6 ++++- .../ws/WebsocketTransportConnector.java | 12 +++++----- app-stream-network/pom.xml | 2 +- app-stream-protocol/pom.xml | 2 +- dingtalk-stream/pom.xml | 4 ++-- pom.xml | 7 +++++- version.sh | 2 +- 21 files changed, 116 insertions(+), 41 deletions(-) create mode 100644 app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java diff --git a/app-stream-api/pom.xml b/app-stream-api/pom.xml index 99fd628..dff984a 100644 --- a/app-stream-api/pom.xml +++ b/app-stream-api/pom.xml @@ -5,7 +5,7 @@ open-app-stream-client com.dingtalk.open - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java index d3690f2..a2a33e9 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java @@ -14,6 +14,7 @@ import com.dingtalk.open.app.stream.network.core.NetWorkService; import com.dingtalk.open.app.stream.network.core.Subscription; +import java.net.Proxy; import java.util.Collections; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -34,22 +35,26 @@ class OpenDingTalkStreamClient implements OpenDingTalkClient { private Set subscriptions; private final AtomicReference status; - public OpenDingTalkStreamClient(DingTalkCredential credential, CommandDispatcher dispatcher, ExecutorService executor, ClientOption option, Set subscriptions) { + private final Proxy proxy; + + public OpenDingTalkStreamClient(DingTalkCredential credential, CommandDispatcher dispatcher, ExecutorService executor, ClientOption option, Set subscriptions, + Proxy proxy) { this.credential = credential; this.dispatcher = dispatcher; this.executor = executor; this.option = option; this.subscriptions = Collections.unmodifiableSet(subscriptions); this.status = new AtomicReference<>(Status.INIT); + this.proxy = proxy; } @Override public synchronized void start() throws OpenDingTalkAppException { if (status.get() == Status.INIT) { this.openApiClient = OpenApiClientBuilder.create().setHost(option.getOpenApiHost()).setTimeout(option.getConnectionTTL()).build(); - final EndPointConnectionFactory factory = () -> openConnection(this.credential, subscriptions); + final EndPointConnectionFactory factory = () -> openConnection(this.credential, subscriptions, proxy); ClientConnectionListener listener = new AppServiceListener(dispatcher, executor); - this.netWorkService = new NetWorkService(factory, listener, option.getMaxConnectionCount(), option.getConnectionTTL(), option.getConnectTimeout(),option.getKeepAliveOption().getKeepAliveIdleMill()); + this.netWorkService = new NetWorkService(factory, listener, option.getMaxConnectionCount(), option.getConnectionTTL(), option.getConnectTimeout(), option.getKeepAliveOption().getKeepAliveIdleMill(), proxy); this.netWorkService.start(); this.status.set(Status.ACTIVE); } else if (status.get() == Status.INACTIVE) { @@ -70,15 +75,15 @@ public synchronized void stop() throws Exception { } } - private EndPointConnection openConnection(DingTalkCredential credential, Set subscriptions) throws Exception { + private EndPointConnection openConnection(DingTalkCredential credential, Set subscriptions, Proxy proxy) throws Exception { OpenConnectionRequest request = new OpenConnectionRequest(); request.setClientId(credential.getClientId()); request.setClientSecret(credential.getClientSecret()); request.setUa(UserAgent.getUserAgent().getUa()); request.setSubscriptions(subscriptions); request.setLocalIp(IpUtils.getLocalIP()); - OpenConnectionResponse response = openApiClient.openConnection(request); - return new EndPointConnection(credential.getClientId(), response.getEndpoint(), response.getTicket()); + OpenConnectionResponse response = openApiClient.openConnection(request, proxy); + return new EndPointConnection(credential.getClientId(), response.getEndpoint(), response.getTicket(), proxy); } diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java index 13ea84f..3f40e12 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java @@ -7,9 +7,12 @@ import com.dingtalk.open.app.api.protocol.CommandExecutor; import com.dingtalk.open.app.api.protocol.EventCommandExecutor; import com.dingtalk.open.app.api.security.DingTalkCredential; +import com.dingtalk.open.app.stream.network.api.NetProxy; import com.dingtalk.open.app.stream.network.core.Subscription; import com.dingtalk.open.app.stream.protocol.CommandType; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.util.*; import java.util.concurrent.ExecutorService; @@ -27,6 +30,8 @@ public class OpenDingTalkStreamClientBuilder { private int connectionTimeToLive = 6 * 60 * 60 * 1000; private long connectTimeout = 3 * 1000L; + private Proxy proxy; + private KeepAliveOption keepAliveOption = new KeepAliveOption(); private String openApiHost = "https://api.dingtalk.com"; @@ -99,6 +104,17 @@ public OpenDingTalkStreamClientBuilder preEnv() { return this.openApiHost("https://pre-api.dingtalk.com"); } + /** + * 设置代理方式 + * + * @param netProxy + * @return + */ + public OpenDingTalkStreamClientBuilder proxy(NetProxy netProxy) { + this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(netProxy.getIp(), netProxy.getPort())); + return this; + } + public OpenDingTalkClient build() { ClientOption option = new ClientOption(); option.setConnectTimeout(connectTimeout); @@ -107,7 +123,7 @@ public OpenDingTalkClient build() { option.setOpenApiHost(openApiHost); option.setKeepAliveOption(keepAliveOption); ExecutorService executor = ThreadUtil.newFixedExecutor(consumeThreads, "DingTalk-Consumer"); - return new OpenDingTalkStreamClient(credential, new CommandDispatcher(commands), executor, option, subscriptions); + return new OpenDingTalkStreamClient(credential, new CommandDispatcher(commands), executor, option, subscriptions, proxy); } private void subscribe(CommandType type, String topic) { diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java index bf51337..f00de57 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java @@ -7,6 +7,8 @@ import com.dingtalk.open.app.api.util.IoUtils; import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.net.URL; /** @@ -25,8 +27,15 @@ public HttpOpenApiClient(String host, int timeout) { } @Override - public OpenConnectionResponse openConnection(OpenConnectionRequest request) throws Exception { - final HttpURLConnection connection = (HttpURLConnection) new URL(host + "/v1.0/gateway/connections/open").openConnection(); + public OpenConnectionResponse openConnection(OpenConnectionRequest request, Proxy proxy) throws Exception { + URL url = new URL(host + "/v1.0/gateway/connections/open"); + + HttpURLConnection connection; + if (proxy != null) { + connection = (HttpURLConnection) url.openConnection(proxy); + } else { + connection = (HttpURLConnection) url.openConnection(); + } connection.setRequestMethod(HttpConstants.METHOD_POST); connection.setReadTimeout(this.timeout); connection.setConnectTimeout(this.timeout); diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClient.java index 74fa42a..e420fdb 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClient.java @@ -1,5 +1,7 @@ package com.dingtalk.open.app.api.open; +import java.net.Proxy; + /** * @author feiyin * @date 2023/2/9 @@ -12,7 +14,7 @@ public interface OpenApiClient { * @return * @throws Exception */ - OpenConnectionResponse openConnection(OpenConnectionRequest request) throws Exception; + OpenConnectionResponse openConnection(OpenConnectionRequest request, Proxy proxy) throws Exception; } diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java index 2075ae9..7d30da3 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java @@ -1,5 +1,8 @@ package com.dingtalk.open.app.api.open; + +import java.net.Proxy; + /** * @author feiyin * @date 2023/3/1 @@ -18,6 +21,7 @@ public static OpenApiClientBuilder create() { private int timeout = 3000; + public OpenApiClientBuilder setHost(String host) { this.host = host; return this; diff --git a/app-stream-client/pom.xml b/app-stream-client/pom.xml index d070c74..99883db 100644 --- a/app-stream-client/pom.xml +++ b/app-stream-client/pom.xml @@ -4,13 +4,13 @@ com.dingtalk.open open-app-stream-client - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml app-stream-client jar - 1.2.0 + 1.2.1-SNAPSHOT app-stream-client diff --git a/app-stream-network/app-stream-network-api/pom.xml b/app-stream-network/app-stream-network-api/pom.xml index ecda205..17a6709 100644 --- a/app-stream-network/app-stream-network-api/pom.xml +++ b/app-stream-network/app-stream-network-api/pom.xml @@ -4,12 +4,12 @@ com.dingtalk.open app-stream-network - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml app-stream-network-api - 1.2.0 + 1.2.1-SNAPSHOT jar app-stream-network-api diff --git a/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/EndPointConnection.java b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/EndPointConnection.java index 39551a1..bcf2f5f 100644 --- a/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/EndPointConnection.java +++ b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/EndPointConnection.java @@ -1,5 +1,6 @@ package com.dingtalk.open.app.stream.network.api; +import java.net.Proxy; import java.net.URI; import java.net.URISyntaxException; @@ -12,7 +13,9 @@ public class EndPointConnection { private final URI endPoint; private final String connectionId; - public EndPointConnection(String clientId, String endPoint, String connectionId) { + private final Proxy proxy; + + public EndPointConnection(String clientId, String endPoint, String connectionId, Proxy proxy) { this.clientId = clientId; try { this.endPoint = new URI(endPoint); @@ -20,6 +23,7 @@ public EndPointConnection(String clientId, String endPoint, String connectionId) throw new RuntimeException(e); } this.connectionId = connectionId; + this.proxy = proxy; } public URI getEndPoint() { @@ -38,4 +42,7 @@ public TransportProtocol getProtocol() { return TransportProtocol.parseScheme(endPoint.getScheme()); } + public Proxy getProxy() { + return proxy; + } } diff --git a/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java new file mode 100644 index 0000000..2d3351d --- /dev/null +++ b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java @@ -0,0 +1,23 @@ +package com.dingtalk.open.app.stream.network.api; + +/** + * @author feiyin + * @date 2023/11/21 + */ +public class NetProxy { + private String host; + private Integer port; + + public NetProxy(String ip, Integer port) { + this.host = ip; + this.port = port; + } + + public String getIp() { + return host; + } + + public Integer getPort() { + return port; + } +} diff --git a/app-stream-network/app-stream-network-core/pom.xml b/app-stream-network/app-stream-network-core/pom.xml index 89fbb0d..8e18642 100644 --- a/app-stream-network/app-stream-network-core/pom.xml +++ b/app-stream-network/app-stream-network-core/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml diff --git a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java index 126d950..9a0bd64 100644 --- a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java +++ b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java @@ -8,6 +8,7 @@ import com.dingtalk.open.app.stream.protocol.system.SystemTopic; import io.netty.util.concurrent.DefaultThreadFactory; +import java.net.Proxy; import java.util.Map; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -33,8 +34,9 @@ public class DefaultSessionPool implements SessionPool { private final EndPointConnectionFactory factory; private final ClientConnectionListener appListener; private final Long keepAliveIdle; + private final Proxy proxy; - public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, long ttl, long connectionTimeout, long keepAliveIdle, ClientConnectionListener appListener) { + public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, long ttl, long connectionTimeout, long keepAliveIdle, ClientConnectionListener appListener, Proxy proxy) { this.sessions = new ConcurrentHashMap<>(); this.status = new AtomicBoolean(true); this.factory = factory; @@ -44,6 +46,7 @@ public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, this.connectionTimeout = connectionTimeout; this.connectionTTL = ttl; this.keepAliveIdle = keepAliveIdle; + this.proxy = proxy; } diff --git a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java index c1175c8..8f34183 100644 --- a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java +++ b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java @@ -1,8 +1,9 @@ package com.dingtalk.open.app.stream.network.core; import com.dingtalk.open.app.stream.network.api.ClientConnectionListener; -import com.dingtalk.open.app.stream.network.api.logger.InternalLogger; -import com.dingtalk.open.app.stream.network.api.logger.InternalLoggerFactory; + +import java.net.Proxy; + /** * @author feiyin @@ -11,14 +12,10 @@ public class NetWorkService { private final DefaultSessionPool sessionPool; - public NetWorkService(EndPointConnectionFactory factory, - ClientConnectionListener listener, - int maxConnection, - long ttl, - long connectTimeout, - long keepAliveIdle) { - this.sessionPool = new DefaultSessionPool(factory, maxConnection, ttl, connectTimeout, keepAliveIdle, listener); + public NetWorkService(EndPointConnectionFactory factory, ClientConnectionListener listener, int maxConnection, long ttl, long connectTimeout, long keepAliveIdle, Proxy proxy) { + this.sessionPool = new DefaultSessionPool(factory, maxConnection, ttl, connectTimeout, keepAliveIdle, listener, proxy); } + /** * 开始 */ diff --git a/app-stream-network/app-stream-network-rsocket/pom.xml b/app-stream-network/app-stream-network-rsocket/pom.xml index 465aa81..5d86846 100644 --- a/app-stream-network/app-stream-network-rsocket/pom.xml +++ b/app-stream-network/app-stream-network-rsocket/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml diff --git a/app-stream-network/app-stream-network-ws/pom.xml b/app-stream-network/app-stream-network-ws/pom.xml index fac5b3d..6b54f58 100644 --- a/app-stream-network/app-stream-network-ws/pom.xml +++ b/app-stream-network/app-stream-network-ws/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml @@ -26,5 +26,9 @@ com.alibaba fastjson + + io.netty + netty-handler-proxy + diff --git a/app-stream-network/app-stream-network-ws/src/main/java/com/dingtalk/open/app/stream/network/ws/WebsocketTransportConnector.java b/app-stream-network/app-stream-network-ws/src/main/java/com/dingtalk/open/app/stream/network/ws/WebsocketTransportConnector.java index 04d969a..cfd6c97 100644 --- a/app-stream-network/app-stream-network-ws/src/main/java/com/dingtalk/open/app/stream/network/ws/WebsocketTransportConnector.java +++ b/app-stream-network/app-stream-network-ws/src/main/java/com/dingtalk/open/app/stream/network/ws/WebsocketTransportConnector.java @@ -12,6 +12,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolConfig; import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; +import io.netty.handler.proxy.HttpProxyHandler; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslHandler; @@ -31,6 +32,7 @@ @Protocol(protocol = {TransportProtocol.WSS}) public class WebsocketTransportConnector implements TransportConnector { private static final InternalLogger LOGGER = InternalLoggerFactory.getLogger(WebsocketTransportConnector.class); + @Override public Session connect(EndPointConnection connection, ClientConnectionListener listener, ConnectOption option) throws Exception { LOGGER.info("[DingTalk] start websocket connection, uri={}", connection.getEndPoint().toString()); @@ -41,12 +43,10 @@ public Session connect(EndPointConnection connection, ClientConnectionListener l bootstrap.handler(new ChannelInitializer() { @Override protected void initChannel(SocketChannel socketChannel) throws Exception { - WebSocketClientProtocolConfig config = WebSocketClientProtocolConfig.newBuilder().dropPongFrames(false) - .webSocketUri(configureWebsocketUri(connection)) - .handshakeTimeoutMillis(option.getTtl()) - .dropPongFrames(false) - .handleCloseFrames(true) - .build(); + if (connection.getProxy() != null) { + socketChannel.pipeline().addLast(new HttpProxyHandler(connection.getProxy().address())); + } + WebSocketClientProtocolConfig config = WebSocketClientProtocolConfig.newBuilder().dropPongFrames(false).webSocketUri(configureWebsocketUri(connection)).handshakeTimeoutMillis(option.getTtl()).dropPongFrames(false).handleCloseFrames(true).build(); SslContext sslContext = SslContextBuilder.forClient().build(); if (connection.getProtocol().isTls()) { final SSLEngine engine = sslContext.newEngine(socketChannel.alloc()); diff --git a/app-stream-network/pom.xml b/app-stream-network/pom.xml index 7f72e23..79c2900 100644 --- a/app-stream-network/pom.xml +++ b/app-stream-network/pom.xml @@ -5,7 +5,7 @@ open-app-stream-client com.dingtalk.open - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml pom diff --git a/app-stream-protocol/pom.xml b/app-stream-protocol/pom.xml index 2b2e3c4..0e6063b 100644 --- a/app-stream-protocol/pom.xml +++ b/app-stream-protocol/pom.xml @@ -6,7 +6,7 @@ com.dingtalk.open open-app-stream-client - 1.2.0 + 1.2.1-SNAPSHOT app-stream-protocol diff --git a/dingtalk-stream/pom.xml b/dingtalk-stream/pom.xml index 1d499ad..888852e 100644 --- a/dingtalk-stream/pom.xml +++ b/dingtalk-stream/pom.xml @@ -4,13 +4,13 @@ com.dingtalk.open open-app-stream-client - 1.2.0 + 1.2.1-SNAPSHOT ../pom.xml dingtalk-stream jar - 1.2.0 + 1.2.1-SNAPSHOT app-stream-client diff --git a/pom.xml b/pom.xml index 1508295..92cd14f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.dingtalk.open open-app-stream-client pom - 1.2.0 + 1.2.1-SNAPSHOT app-stream-client app-stream-api @@ -69,6 +69,11 @@ netty-codec-http 4.1.81.Final + + io.netty + netty-handler-proxy + 4.1.81.Final + io.netty netty-common diff --git a/version.sh b/version.sh index 69b1fca..bce6f68 100755 --- a/version.sh +++ b/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -mvn versions:set -DnewVersion=1.2.0 +mvn versions:set -DnewVersion=1.2.1-SNAPSHOT From 26d4ac2c5cfa32978962afb9d8f355170092ea10 Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Wed, 22 Nov 2023 09:51:38 +0800 Subject: [PATCH 2/6] fix(#proxy) : support http proxy --- .../open/app/api/OpenDingTalkStreamClientBuilder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java index 3f40e12..44c0c1c 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClientBuilder.java @@ -1,19 +1,22 @@ package com.dingtalk.open.app.api; -import com.dingtalk.open.app.api.command.CommandDispatcher; -import com.dingtalk.open.app.api.util.ThreadUtil; import com.dingtalk.open.app.api.callback.CallbackCommandExecutor; import com.dingtalk.open.app.api.callback.OpenDingTalkCallbackListener; +import com.dingtalk.open.app.api.command.CommandDispatcher; import com.dingtalk.open.app.api.protocol.CommandExecutor; import com.dingtalk.open.app.api.protocol.EventCommandExecutor; import com.dingtalk.open.app.api.security.DingTalkCredential; +import com.dingtalk.open.app.api.util.ThreadUtil; import com.dingtalk.open.app.stream.network.api.NetProxy; import com.dingtalk.open.app.stream.network.core.Subscription; import com.dingtalk.open.app.stream.protocol.CommandType; import java.net.InetSocketAddress; import java.net.Proxy; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutorService; /** From 6348523a4f3f0f4b39f19a10f65c745beb4057e6 Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Wed, 22 Nov 2023 11:29:10 +0800 Subject: [PATCH 3/6] fix(#proxy) : support http proxy --- .../com/dingtalk/open/app/stream/network/api/NetProxy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java index 2d3351d..c31d761 100644 --- a/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java +++ b/app-stream-network/app-stream-network-api/src/main/java/com/dingtalk/open/app/stream/network/api/NetProxy.java @@ -8,8 +8,8 @@ public class NetProxy { private String host; private Integer port; - public NetProxy(String ip, Integer port) { - this.host = ip; + public NetProxy(String host, Integer port) { + this.host = host; this.port = port; } From f8ce540b4b620dadb1b8a057666c8e4ac3725d15 Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Thu, 23 Nov 2023 15:13:17 +0800 Subject: [PATCH 4/6] feat(#proxy) : support http tunnel proxy --- .../com/dingtalk/open/app/api/OpenDingTalkStreamClient.java | 3 +-- .../com/dingtalk/open/app/api/open/HttpOpenApiClient.java | 1 - .../com/dingtalk/open/app/api/open/OpenApiClientBuilder.java | 4 ---- .../open/app/stream/network/core/DefaultSessionPool.java | 4 +--- .../dingtalk/open/app/stream/network/core/NetWorkService.java | 4 ++-- version.sh | 2 +- 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java index a2a33e9..8f8ee03 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java @@ -34,7 +34,6 @@ class OpenDingTalkStreamClient implements OpenDingTalkClient { private OpenApiClient openApiClient; private Set subscriptions; private final AtomicReference status; - private final Proxy proxy; public OpenDingTalkStreamClient(DingTalkCredential credential, CommandDispatcher dispatcher, ExecutorService executor, ClientOption option, Set subscriptions, @@ -54,7 +53,7 @@ public synchronized void start() throws OpenDingTalkAppException { this.openApiClient = OpenApiClientBuilder.create().setHost(option.getOpenApiHost()).setTimeout(option.getConnectionTTL()).build(); final EndPointConnectionFactory factory = () -> openConnection(this.credential, subscriptions, proxy); ClientConnectionListener listener = new AppServiceListener(dispatcher, executor); - this.netWorkService = new NetWorkService(factory, listener, option.getMaxConnectionCount(), option.getConnectionTTL(), option.getConnectTimeout(), option.getKeepAliveOption().getKeepAliveIdleMill(), proxy); + this.netWorkService = new NetWorkService(factory, listener, option.getMaxConnectionCount(), option.getConnectionTTL(), option.getConnectTimeout(), option.getKeepAliveOption().getKeepAliveIdleMill()); this.netWorkService.start(); this.status.set(Status.ACTIVE); } else if (status.get() == Status.INACTIVE) { diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java index f00de57..f918773 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/HttpOpenApiClient.java @@ -7,7 +7,6 @@ import com.dingtalk.open.app.api.util.IoUtils; import java.net.HttpURLConnection; -import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java index 7d30da3..2075ae9 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/open/OpenApiClientBuilder.java @@ -1,8 +1,5 @@ package com.dingtalk.open.app.api.open; - -import java.net.Proxy; - /** * @author feiyin * @date 2023/3/1 @@ -21,7 +18,6 @@ public static OpenApiClientBuilder create() { private int timeout = 3000; - public OpenApiClientBuilder setHost(String host) { this.host = host; return this; diff --git a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java index 9a0bd64..2c5e1dd 100644 --- a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java +++ b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/DefaultSessionPool.java @@ -34,9 +34,8 @@ public class DefaultSessionPool implements SessionPool { private final EndPointConnectionFactory factory; private final ClientConnectionListener appListener; private final Long keepAliveIdle; - private final Proxy proxy; - public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, long ttl, long connectionTimeout, long keepAliveIdle, ClientConnectionListener appListener, Proxy proxy) { + public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, long ttl, long connectionTimeout, long keepAliveIdle, ClientConnectionListener appListener) { this.sessions = new ConcurrentHashMap<>(); this.status = new AtomicBoolean(true); this.factory = factory; @@ -46,7 +45,6 @@ public DefaultSessionPool(EndPointConnectionFactory factory, int maxConnections, this.connectionTimeout = connectionTimeout; this.connectionTTL = ttl; this.keepAliveIdle = keepAliveIdle; - this.proxy = proxy; } diff --git a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java index 8f34183..549cac9 100644 --- a/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java +++ b/app-stream-network/app-stream-network-core/src/main/java/com/dingtalk/open/app/stream/network/core/NetWorkService.java @@ -12,8 +12,8 @@ public class NetWorkService { private final DefaultSessionPool sessionPool; - public NetWorkService(EndPointConnectionFactory factory, ClientConnectionListener listener, int maxConnection, long ttl, long connectTimeout, long keepAliveIdle, Proxy proxy) { - this.sessionPool = new DefaultSessionPool(factory, maxConnection, ttl, connectTimeout, keepAliveIdle, listener, proxy); + public NetWorkService(EndPointConnectionFactory factory, ClientConnectionListener listener, int maxConnection, long ttl, long connectTimeout, long keepAliveIdle) { + this.sessionPool = new DefaultSessionPool(factory, maxConnection, ttl, connectTimeout, keepAliveIdle, listener); } /** diff --git a/version.sh b/version.sh index bce6f68..011cf51 100755 --- a/version.sh +++ b/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -mvn versions:set -DnewVersion=1.2.1-SNAPSHOT +mvn versions:set -DnewVersion=1.2.1 From 0f121b4e3c5aadddce8fdf72c2037f9cb06eca4e Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Thu, 23 Nov 2023 15:16:28 +0800 Subject: [PATCH 5/6] feat(#proxy) : 1.2.1 release version --- app-stream-api/pom.xml | 2 +- app-stream-client/pom.xml | 4 ++-- app-stream-network/app-stream-network-api/pom.xml | 4 ++-- app-stream-network/app-stream-network-core/pom.xml | 2 +- app-stream-network/app-stream-network-rsocket/pom.xml | 2 +- app-stream-network/app-stream-network-ws/pom.xml | 2 +- app-stream-network/pom.xml | 2 +- app-stream-protocol/pom.xml | 2 +- dingtalk-stream/pom.xml | 4 ++-- pom.xml | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app-stream-api/pom.xml b/app-stream-api/pom.xml index dff984a..b2afdde 100644 --- a/app-stream-api/pom.xml +++ b/app-stream-api/pom.xml @@ -5,7 +5,7 @@ open-app-stream-client com.dingtalk.open - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml 4.0.0 diff --git a/app-stream-client/pom.xml b/app-stream-client/pom.xml index 99883db..94d79e0 100644 --- a/app-stream-client/pom.xml +++ b/app-stream-client/pom.xml @@ -4,13 +4,13 @@ com.dingtalk.open open-app-stream-client - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml app-stream-client jar - 1.2.1-SNAPSHOT + 1.2.1 app-stream-client diff --git a/app-stream-network/app-stream-network-api/pom.xml b/app-stream-network/app-stream-network-api/pom.xml index 17a6709..3b596dd 100644 --- a/app-stream-network/app-stream-network-api/pom.xml +++ b/app-stream-network/app-stream-network-api/pom.xml @@ -4,12 +4,12 @@ com.dingtalk.open app-stream-network - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml app-stream-network-api - 1.2.1-SNAPSHOT + 1.2.1 jar app-stream-network-api diff --git a/app-stream-network/app-stream-network-core/pom.xml b/app-stream-network/app-stream-network-core/pom.xml index 8e18642..2d3ce02 100644 --- a/app-stream-network/app-stream-network-core/pom.xml +++ b/app-stream-network/app-stream-network-core/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml diff --git a/app-stream-network/app-stream-network-rsocket/pom.xml b/app-stream-network/app-stream-network-rsocket/pom.xml index 5d86846..2dd72bb 100644 --- a/app-stream-network/app-stream-network-rsocket/pom.xml +++ b/app-stream-network/app-stream-network-rsocket/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml diff --git a/app-stream-network/app-stream-network-ws/pom.xml b/app-stream-network/app-stream-network-ws/pom.xml index 6b54f58..1f10097 100644 --- a/app-stream-network/app-stream-network-ws/pom.xml +++ b/app-stream-network/app-stream-network-ws/pom.xml @@ -4,7 +4,7 @@ com.dingtalk.open app-stream-network - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml diff --git a/app-stream-network/pom.xml b/app-stream-network/pom.xml index 79c2900..0361fc6 100644 --- a/app-stream-network/pom.xml +++ b/app-stream-network/pom.xml @@ -5,7 +5,7 @@ open-app-stream-client com.dingtalk.open - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml pom diff --git a/app-stream-protocol/pom.xml b/app-stream-protocol/pom.xml index 0e6063b..1306145 100644 --- a/app-stream-protocol/pom.xml +++ b/app-stream-protocol/pom.xml @@ -6,7 +6,7 @@ com.dingtalk.open open-app-stream-client - 1.2.1-SNAPSHOT + 1.2.1 app-stream-protocol diff --git a/dingtalk-stream/pom.xml b/dingtalk-stream/pom.xml index 888852e..4734336 100644 --- a/dingtalk-stream/pom.xml +++ b/dingtalk-stream/pom.xml @@ -4,13 +4,13 @@ com.dingtalk.open open-app-stream-client - 1.2.1-SNAPSHOT + 1.2.1 ../pom.xml dingtalk-stream jar - 1.2.1-SNAPSHOT + 1.2.1 app-stream-client diff --git a/pom.xml b/pom.xml index 92cd14f..964e735 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.dingtalk.open open-app-stream-client pom - 1.2.1-SNAPSHOT + 1.2.1 app-stream-client app-stream-api From 0dd15ebf6222a33a37e963391b0ff9f59599a0b6 Mon Sep 17 00:00:00 2001 From: "mike.wq" Date: Thu, 23 Nov 2023 15:35:38 +0800 Subject: [PATCH 6/6] feat(#proxy) : 1.2.1 release version --- .../open/app/api/OpenDingTalkStreamClient.java | 2 +- .../dingtalk/open/app/api/open/HttpOpenApiClient.java | 7 +++++-- .../com/dingtalk/open/app/api/open/OpenApiClient.java | 4 +--- .../open/app/api/open/OpenApiClientBuilder.java | 11 ++++++++++- .../open/app/api/protocol/AppServiceListener.java | 2 +- .../open/app/stream/network/core/Connector.java | 2 +- .../app/stream/network/core/DefaultSessionPool.java | 5 ++--- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java index 8f8ee03..4a593d8 100644 --- a/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java +++ b/app-stream-api/src/main/java/com/dingtalk/open/app/api/OpenDingTalkStreamClient.java @@ -81,7 +81,7 @@ private EndPointConnection openConnection(DingTalkCredential credential, Set callable) throws Exception { try { return callable.call(); } catch (Exception e) { - LOGGER.error("[DingTalk] retrievable executor execute failed", e); + LOGGER.error("[DingTalk] retrievable executor execute failed, {}", e); if (count.get() <= 0) { throw e; }