11/*******************************************************************************
2- * Copyright (c) 2023, 2025 IBM Corporation and others.
2+ * Copyright (c) 2023, 2026 IBM Corporation and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License 2.0
55 * which accompanies this distribution, and is available at
1111
1212import java .io .EOFException ;
1313import java .io .IOException ;
14+ import java .net .InetAddress ;
15+ import java .net .InetSocketAddress ;
1416import java .net .Socket ;
17+ import java .net .SocketAddress ;
1518import java .net .SocketTimeoutException ;
1619import java .nio .ByteBuffer ;
1720import java .util .Objects ;
3437import com .ibm .wsspi .tcpchannel .TCPReadRequestContext ;
3538
3639import io .netty .channel .Channel ;
40+ import io .netty .channel .socket .SocketChannel ;
41+ import io .netty .channel .socket .nio .NioSocketChannel ;
42+ import io .openliberty .http .netty .channel .ReadOnlySocket ;
3743
3844/**
3945 *
@@ -61,6 +67,8 @@ public class NettyTCPReadRequestContext implements TCPReadRequestContext {
6167
6268 private VirtualConnection vc = null ;
6369
70+ private volatile Socket cachedSocket ;
71+
6472 public NettyTCPReadRequestContext (NettyTCPConnectionContext connectionContext , Channel nettyChannel ) {
6573
6674 this .connectionContext = connectionContext ;
@@ -85,7 +93,10 @@ public TCPConnectionContext getInterface() {
8593
8694 @ Override
8795 public Socket getSocket () {
88- throw new UnsupportedOperationException ("Can not get the socket from a Netty connection!" );
96+ if (cachedSocket == null ){
97+ cachedSocket = new ReadOnlySocket (nettyChannel );
98+ }
99+ return cachedSocket ;
89100 }
90101
91102 /**
@@ -412,5 +423,4 @@ public void setBuffer(WsByteBuffer buf) {
412423 public void setVC (VirtualConnection vc ) {
413424 this .vc = vc ;
414425 }
415-
416426}
0 commit comments