MCPcopy Index your code
hub / github.com/ccxt/ccxt / createConnection

Method createConnection

java/lib/src/main/java/io/github/ccxt/ws/WsClient.java:263–377  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

261 }
262
263 private void createConnection() {
264 try {
265 URI uri = new URI(this.url);
266 String scheme = uri.getScheme();
267 String host = uri.getHost();
268 int port = uri.getPort();
269 if (port == -1) {
270 port = "wss".equalsIgnoreCase(scheme) ? 443 : 80;
271 }
272 boolean ssl = "wss".equalsIgnoreCase(scheme);
273
274 final SslContext sslCtx;
275 if (ssl) {
276 var sslBuilder = SslContextBuilder.forClient();
277 if (!this.validateServerSsl) {
278 sslBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
279 }
280 sslCtx = sslBuilder.build();
281 } else {
282 sslCtx = null;
283 }
284
285 // Netty doesn't auto-attach User-Agent/Origin like browser/node WebSocket
286 // libraries do, so we set them ourselves — caller-supplied values win.
287 DefaultHttpHeaders requestHeaders = new DefaultHttpHeaders();
288 boolean hasUserAgent = false;
289 boolean hasOrigin = false;
290 if (this.handshakeHeaders != null) {
291 for (java.util.Map.Entry<String, String> e : this.handshakeHeaders.entrySet()) {
292 if (e.getKey() == null || e.getValue() == null) continue;
293 requestHeaders.add(e.getKey(), e.getValue());
294 if ("User-Agent".equalsIgnoreCase(e.getKey())) hasUserAgent = true;
295 if ("Origin".equalsIgnoreCase(e.getKey())) hasOrigin = true;
296 }
297 }
298 if (!hasUserAgent) {
299 requestHeaders.add("User-Agent", "ccxt/java");
300 }
301 if (!hasOrigin) {
302 String origin = ("wss".equalsIgnoreCase(scheme) ? "https://" : "http://") + host;
303 requestHeaders.add("Origin", origin);
304 }
305
306 WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
307 uri, WebSocketVersion.V13, null, true,
308 requestHeaders, 65536 * 100);
309
310 final WsClientHandler handler = new WsClientHandler(handshaker, this);
311 final int finalPort = port;
312
313 Bootstrap bootstrap = new Bootstrap();
314 bootstrap.group(SHARED_EVENT_LOOP)
315 .channel(NioSocketChannel.class)
316 .handler(new ChannelInitializer<SocketChannel>() {
317 @Override
318 protected void initChannel(SocketChannel ch) {
319 ChannelPipeline pipeline = ch.pipeline();
320

Callers

nothing calls this directly

Calls 7

handshakeFutureMethod · 0.95
getFormattedDateMethod · 0.95
onErrorMethod · 0.95
buildMethod · 0.45
getValueMethod · 0.45
addMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected