From 8f994580c413f691dd226274938e6d1c4a2e8ac9 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Mon, 5 May 2025 16:53:22 -0400 Subject: [PATCH 1/4] Formatting Signed-off-by: Scott Kurz --- .../internal/TCPBaseRequestContext.java | 33 +++++++++++-------- .../wsspi/tcpchannel/TCPRequestContext.java | 16 ++++----- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java b/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java index 93797b28c198..ec639e594ffc 100644 --- a/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java +++ b/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -61,7 +61,7 @@ public class TCPBaseRequestContext implements TCPRequestContext, FFDCSelfIntrosp protected TCPChannelConfiguration config; protected long timeoutTime; private int timeoutInterval; - private WsByteBuffer[] defaultBuffers = new WsByteBuffer[1]; + private final WsByteBuffer[] defaultBuffers = new WsByteBuffer[1]; private ByteBuffer byteBufferArray[] = null; private ByteBuffer byteBufferArrayDirect[] = null; private boolean missedSet = false; @@ -80,7 +80,7 @@ public class TCPBaseRequestContext implements TCPRequestContext, FFDCSelfIntrosp /** * Constructor. - * + * * @param link */ protected TCPBaseRequestContext(TCPConnLink link) { @@ -100,7 +100,7 @@ protected void abort() { /** * Check whether this context has been aborted previously or not. - * + * * @return boolean */ protected boolean isAborted() { @@ -109,7 +109,7 @@ protected boolean isAborted() { /** * Access the connection link for this context object. - * + * * @return TCPConnLink */ public TCPConnLink getTCPConnLink() { @@ -123,6 +123,7 @@ protected TCPChannelConfiguration getConfig() { /** * @see TCPRequestContext#getInterface() */ + @Override public TCPConnectionContext getInterface() { return this.oTCPConnLink; } @@ -132,11 +133,13 @@ public TCPConnectionContext getInterface() { /* =================================================================== */ /** @see TCPRequestContext#getBuffers() */ + @Override public WsByteBuffer[] getBuffers() { return this.buffers; } /** @see TCPRequestContext#setBuffers(WsByteBuffer[]) */ + @Override public void setBuffers(WsByteBuffer[] bufs) { this.missedSet = false; this.buffers = bufs; @@ -278,6 +281,7 @@ protected void setBuffersToDirect(WsByteBuffer[] bufs) { /** * @return WsByteBuffer */ + @Override public WsByteBuffer getBuffer() { if (this.buffers == null) { return null; @@ -288,6 +292,7 @@ public WsByteBuffer getBuffer() { /** * @param buf */ + @Override public void setBuffer(WsByteBuffer buf) { this.missedSet = false; @@ -333,6 +338,7 @@ public void setBuffer(WsByteBuffer buf) { /** * Clear any buffers that are currently stored. */ + @Override public void clearBuffers() { if (null != this.buffers) { for (int i = 0; i < this.buffers.length; i++) { @@ -392,7 +398,7 @@ protected long getIOCompleteAmount() { * comparable format to System.currentTimeMillis) when this request * will time out. Should only be invoked if the 'hasTimeout' method * returns true for this request. - * + * * @return long Point in time when request will timeout. */ public long getTimeoutTime() { @@ -401,7 +407,7 @@ public long getTimeoutTime() { /** * Sets the timeout value returned by 'getTimeoutTime'. - * + * * @param time */ protected void setTimeoutTime(int time) { @@ -425,7 +431,7 @@ protected void setTimeoutTime(int time) { /** * Returns true if this request has an associated timeout. - * + * * @return boolean */ protected boolean hasTimeout() { @@ -434,7 +440,7 @@ protected boolean hasTimeout() { /** * Returns timoutInterval of this request. - * + * * @return int */ public int getTimeoutInterval() { @@ -443,7 +449,7 @@ public int getTimeoutInterval() { /** * Introspect this object for FFDC output. - * + * * @return List */ public List introspect() { @@ -468,6 +474,7 @@ public List introspect() { /* * @see com.ibm.ws.ffdc.FFDCSelfIntrospectable#introspectSelf() */ + @Override public String[] introspectSelf() { List rc = introspect(); return rc.toArray(new String[rc.size()]); @@ -513,11 +520,11 @@ protected ByteBuffer[] getByteBufferArrayDirect() { /** * Updates the IO byte counters, checks if IO operation is complete - * + * * @param byteCount - * number of IO bytes for latest read/write + * number of IO bytes for latest read/write * @param type - * 0 for read. 1 for write + * 0 for read. 1 for write * @return true if IO operation has read/wrote enough bytes, false if not */ // IMPROVEMENT: this shouldn't be public, but needs to be for now. diff --git a/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java b/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java index 8cbe54e5ede5..150f681908c8 100644 --- a/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java +++ b/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -18,7 +18,7 @@ * A context object encapsulating all of the data related to a TCPChannel * read data request. This context can be obtained via the getReadInterface * method on the TCPConnectionContext. - * + * * @ibm-spi */ @@ -26,7 +26,7 @@ public interface TCPRequestContext { /** * Link back to the TCPConnectionContext from whence this interface came. - * + * * @return TCPConnectionContext - originating context */ TCPConnectionContext getInterface(); @@ -41,16 +41,16 @@ public interface TCPRequestContext { /** * Returns the set of read buffers associated with this * request. - * + * * @return WsByteBuffer[] */ WsByteBuffer[] getBuffers(); /** * Sets the array of read buffers associated with this request. - * + * * @param bufs - * - the array of WsByteBuffers to be set + * - the array of WsByteBuffers to be set */ void setBuffers(WsByteBuffer[] bufs); @@ -58,7 +58,7 @@ public interface TCPRequestContext { * Returns the first read buffer in the buffer array associated with this * request. * This is a convenience method for when only one buffer is needed. - * + * * @return WsByteBuffer */ WsByteBuffer getBuffer(); @@ -67,7 +67,7 @@ public interface TCPRequestContext { * Sets the first read buffer in the buffer array associated with this * request. This is * a convenience method for when only one buffer is needed - * + * * @param buf */ void setBuffer(WsByteBuffer buf); From 4bb73d1414677b90d9e5cfc34b387b0af96406ba Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Mon, 5 May 2025 16:57:53 -0400 Subject: [PATCH 2/4] Add getRequestSocket() SPI method and add impl to impls Signed-off-by: Scott Kurz --- .../channel/ssl/internal/SSLReadServiceContext.java | 11 +++++++++-- .../channel/ssl/internal/SSLWriteServiceContext.java | 11 +++++++++-- .../tcpchannel/internal/TCPBaseRequestContext.java | 9 ++++++++- .../com/ibm/wsspi/tcpchannel/TCPRequestContext.java | 11 ++++++++++- .../ibm/ws/sip/container/was/message/SipMessage.java | 12 +++++++++++- .../channel/h2internal/H2TCPReadRequestContext.java | 10 ++++++++-- .../channel/h2internal/H2TCPWriteRequestContext.java | 10 ++++++++-- .../servlet/request/extended/IRequestExtended.java | 6 +++++- .../ws/webcontainer/osgi/request/IRequestImpl.java | 11 +++++++++++ 9 files changed, 79 insertions(+), 12 deletions(-) diff --git a/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLReadServiceContext.java b/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLReadServiceContext.java index b08e9db6a3c8..7012bbcd7742 100644 --- a/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLReadServiceContext.java +++ b/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLReadServiceContext.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2003, 2020 IBM Corporation and others. + * Copyright (c) 2003, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -13,6 +13,7 @@ package com.ibm.ws.channel.ssl.internal; import java.io.IOException; +import java.net.Socket; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.HandshakeStatus; @@ -1995,4 +1996,10 @@ public void run() { } } } + + @Override + public Socket getSocket() { + // Delegate + return getConnLink().getDeviceReadInterface().getSocket(); + } } diff --git a/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLWriteServiceContext.java b/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLWriteServiceContext.java index 06c3da65a13d..9963cf73e6e6 100644 --- a/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLWriteServiceContext.java +++ b/dev/com.ibm.ws.channel.ssl/src/com/ibm/ws/channel/ssl/internal/SSLWriteServiceContext.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2003, 2020 IBM Corporation and others. + * Copyright (c) 2003, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -13,6 +13,7 @@ package com.ibm.ws.channel.ssl.internal; import java.io.IOException; +import java.net.Socket; import java.nio.ReadOnlyBufferException; import javax.net.ssl.SSLEngine; @@ -1006,4 +1007,10 @@ public void run() { } } } + + @Override + public Socket getSocket() { + // Delegate + return getConnLink().getDeviceWriteInterface().getSocket(); + } } diff --git a/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java b/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java index ec639e594ffc..6dfc5ea7fe01 100644 --- a/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java +++ b/dev/com.ibm.ws.channelfw/src/com/ibm/ws/tcpchannel/internal/TCPBaseRequestContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package com.ibm.ws.tcpchannel.internal; import java.io.IOException; +import java.net.Socket; import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.List; @@ -571,4 +572,10 @@ public boolean updateIOCounts(long byteCount, int type) { return rc; } + @Override + public Socket getSocket() { + TCPConnLink connLink = getTCPConnLink(); + return connLink.getSocketIOChannel().getSocket(); + } + } diff --git a/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java b/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java index 150f681908c8..071f4059fd07 100644 --- a/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java +++ b/dev/com.ibm.ws.channelfw/src/com/ibm/wsspi/tcpchannel/TCPRequestContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package com.ibm.wsspi.tcpchannel; +import java.net.Socket; + import com.ibm.wsspi.bytebuffer.WsByteBuffer; /** @@ -72,6 +74,13 @@ public interface TCPRequestContext { */ void setBuffer(WsByteBuffer buf); + /** + * Returns a java.net.Socket associated with the request + * + * @return Socket + */ + Socket getSocket(); + /** * A special value for the timeout parm used on the request calls. * Specifying this value will cause the TCPChannel to use the default diff --git a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/was/message/SipMessage.java b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/was/message/SipMessage.java index 2668612f3f78..a95e8dbb1b3f 100644 --- a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/was/message/SipMessage.java +++ b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/was/message/SipMessage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003 IBM Corporation and others. + * Copyright (c) 2003, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.Socket; import java.nio.charset.Charset; import java.security.cert.X509Certificate; import java.util.ArrayList; @@ -1681,4 +1682,13 @@ public ServletOutputStream getOutputStream() throws IOException { public HttpInboundConnection getHttpInboundConnection() { return null; } + + /** + * @return null + */ + @Override + public Socket getRequestSocket() { + return null; + } + } diff --git a/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPReadRequestContext.java b/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPReadRequestContext.java index 9acbcac0e13f..e486dec3a06d 100644 --- a/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPReadRequestContext.java +++ b/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPReadRequestContext.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 1997, 2017 IBM Corporation and others. + * Copyright (c) 1997, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -13,6 +13,7 @@ package com.ibm.ws.http.channel.h2internal; import java.io.IOException; +import java.net.Socket; import java.nio.ByteBuffer; import java.util.concurrent.TimeUnit; @@ -276,4 +277,9 @@ public boolean getJITAllocateAction() { return this.jitAllocateAction; } + @Override + public Socket getSocket() { + return muxLink.h2MuxTCPReadContext.getSocket(); + } + } diff --git a/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPWriteRequestContext.java b/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPWriteRequestContext.java index 9df65675950d..5a3aa4c9c6d3 100644 --- a/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPWriteRequestContext.java +++ b/dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/channel/h2internal/H2TCPWriteRequestContext.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 1997, 2017 IBM Corporation and others. + * Copyright (c) 1997, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -13,6 +13,7 @@ package com.ibm.ws.http.channel.h2internal; import java.io.IOException; +import java.net.Socket; import java.nio.ByteBuffer; import com.ibm.websphere.ras.Tr; @@ -242,4 +243,9 @@ public void setBuffer(WsByteBuffer buf) { // // } + @Override + public Socket getSocket() { + return muxLink.h2MuxTCPWriteContext.getSocket(); + } + } diff --git a/dev/com.ibm.ws.webcontainer/src/com/ibm/websphere/servlet/request/extended/IRequestExtended.java b/dev/com.ibm.ws.webcontainer/src/com/ibm/websphere/servlet/request/extended/IRequestExtended.java index eeedd821931c..1fa29fce6d3c 100644 --- a/dev/com.ibm.ws.webcontainer/src/com/ibm/websphere/servlet/request/extended/IRequestExtended.java +++ b/dev/com.ibm.ws.webcontainer/src/com/ibm/websphere/servlet/request/extended/IRequestExtended.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2018 IBM Corporation and others. + * Copyright (c) 2015, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package com.ibm.websphere.servlet.request.extended; +import java.net.Socket; + import com.ibm.websphere.servlet.request.IRequest; import com.ibm.ws.util.ThreadPool; import com.ibm.wsspi.http.HttpInboundConnection; @@ -25,4 +27,6 @@ public interface IRequestExtended extends IRequest { public ThreadPool getThreadPool(); public HttpInboundConnection getHttpInboundConnection(); + + public Socket getRequestSocket(); } diff --git a/dev/com.ibm.ws.webcontainer/src/com/ibm/ws/webcontainer/osgi/request/IRequestImpl.java b/dev/com.ibm.ws.webcontainer/src/com/ibm/ws/webcontainer/osgi/request/IRequestImpl.java index 0ff0633a93ad..b4a2406fe048 100644 --- a/dev/com.ibm.ws.webcontainer/src/com/ibm/ws/webcontainer/osgi/request/IRequestImpl.java +++ b/dev/com.ibm.ws.webcontainer/src/com/ibm/ws/webcontainer/osgi/request/IRequestImpl.java @@ -15,6 +15,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.Socket; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.text.ParseException; @@ -45,6 +46,8 @@ import com.ibm.wsspi.http.channel.values.HttpHeaderKeys; import com.ibm.wsspi.http.channel.values.VersionValues; import com.ibm.wsspi.http.ee7.HttpInboundConnectionExtended; +import com.ibm.wsspi.tcpchannel.TCPConnectionContext; +import com.ibm.wsspi.tcpchannel.TCPReadRequestContext; import com.ibm.wsspi.webcontainer.WCCustomProperties; import io.openliberty.http.ext.HttpRequestExt; @@ -984,4 +987,12 @@ public ThreadPool getThreadPool() public HttpInboundConnection getHttpInboundConnection() { return this.conn; } + + @Override + public Socket getRequestSocket() { + HttpInboundConnectionExtended connExt = (HttpInboundConnectionExtended)conn; + TCPConnectionContext tcpConnCtx = connExt.getTCPConnectionContext(); + TCPReadRequestContext tcpReadReqCtx = tcpConnCtx.getReadInterface(); + return tcpReadReqCtx.getSocket(); + } } From 7aa0c8b8b13de46199cafed33851899c4353adaa Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 22 May 2025 12:46:43 -0400 Subject: [PATCH 3/4] Add request socket test to io.openliberty.transport.http_fat Signed-off-by: Scott Kurz --- dev/io.openliberty.transport.http_fat/bnd.bnd | 2 + .../transport/http_fat/FATSuite.java | 1 + .../transport/http_fat/RequestSocketTest.java | 106 ++++++++++++++++++ .../transport/http_fat/accesslists/Utils.java | 66 ++++++++++- .../features/webcontainerlibertyinternals.mf | 8 ++ .../RequestSocket/bootstrap.properties | 14 +++ .../publish/servers/RequestSocket/server.xml | 21 ++++ .../app1/src/app1/web/RequestSocket.java | 49 ++++++++ 8 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/RequestSocketTest.java create mode 100644 dev/io.openliberty.transport.http_fat/publish/features/webcontainerlibertyinternals.mf create mode 100644 dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/bootstrap.properties create mode 100644 dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/server.xml create mode 100644 dev/io.openliberty.transport.http_fat/test-applications/app1/src/app1/web/RequestSocket.java diff --git a/dev/io.openliberty.transport.http_fat/bnd.bnd b/dev/io.openliberty.transport.http_fat/bnd.bnd index 6fa9d8da7b22..a73942159d9b 100644 --- a/dev/io.openliberty.transport.http_fat/bnd.bnd +++ b/dev/io.openliberty.transport.http_fat/bnd.bnd @@ -28,9 +28,11 @@ tested.features:\ -buildpath:\ io.openliberty.org.apache.commons.logging;version=latest, \ io.openliberty.org.apache.commons.codec;version=latest, \ + com.ibm.websphere.appserver.spi.servlet;version=latest,\ com.ibm.websphere.javaee.servlet.4.0;version=latest, \ com.ibm.ws.transport.http;version=latest, \ com.ibm.ws.channelfw;version=latest, \ + com.ibm.ws.webcontainer;version=latest, \ org.apache.httpcomponents.client5:httpclient5;version=5.0.2, \ org.apache.httpcomponents.core5:httpcore5;version=5.0.2, \ org.apache.httpcomponents.core5:httpcore5-h2;version=5.0.2, \ diff --git a/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/FATSuite.java b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/FATSuite.java index 0d212c806151..9f2275c1794d 100644 --- a/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/FATSuite.java +++ b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/FATSuite.java @@ -25,6 +25,7 @@ AccessListsTests.class, MaxOpenConnectionsTest.class, PortOpenRetriesTests.class, + RequestSocketTest.class, SoLingerTests.class, SoReuseAddrTests.class, TcpOptionsDefaultTests.class diff --git a/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/RequestSocketTest.java b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/RequestSocketTest.java new file mode 100644 index 000000000000..49e68812c3b1 --- /dev/null +++ b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/RequestSocketTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.transport.http_fat; + +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.runner.RunWith; + +import com.ibm.websphere.simplicity.ShrinkHelper; + +import app1.web.RequestSocket; +import componenttest.annotation.Server; +import componenttest.annotation.TestServlet; +import componenttest.custom.junit.runner.FATRunner; +import componenttest.custom.junit.runner.Mode; +import componenttest.custom.junit.runner.Mode.TestMode; +import componenttest.topology.impl.LibertyServer; +import componenttest.topology.utils.FATServletClient; +import io.openliberty.transport.http_fat.accesslists.Utils; + +/** + * Tests exposing Socket from HTTP layers + */ +@RunWith(FATRunner.class) +@Mode(TestMode.FULL) +public class RequestSocketTest extends FATServletClient { + + public static final String APP_NAME = "app1"; + + /* This server is used to get the hostname, address and port that is the test client */ + @Server("RequestSocket") + @TestServlet(servlet = RequestSocket.class, contextRoot = APP_NAME) + public static LibertyServer server; + + /** + * Setup test app, start server and wait for SSL endpoint + * + * @throws Exception + */ + @BeforeClass + public static void setUp() throws Exception { + ShrinkHelper.defaultApp(server, APP_NAME, "app1.web"); + server.installSystemFeature("webcontainerlibertyinternals"); + server.startServer(); + server.resetLogMarks(); + assertNotNull("defaultHttpEndpoint-ssl was not started", + server.waitForStringInLog("CWWKO0219I:(.*)defaultHttpEndpoint-ssl")); + } + + /** + * Stop the server, the FAT scaffolding will check the logs when wrapping up + * + * @throws Exception + */ + @AfterClass + public static void tearDown() throws Exception { + server.stopServer(); + } + + /* Useful for getting hold of the current test */ + @Rule + public TestName test = new TestName(); + + @Override + public String toString() { + return this.getClass().getSimpleName() + "_" + test.getMethodName(); + } + + @Test + public void testRequestSocket() throws Exception { + String expected = "socket LocalPort: " + server.getHttpDefaultPort(); + // Get and validate response + Utils.get(server, "/" + APP_NAME + "/RequestSocket", "", expected, ""); + } + + @Test + public void testRequestSocketSecure() throws Exception { + String expected = "socket LocalPort: " + server.getHttpDefaultSecurePort(); + // Get and validate response + Utils.getSecure(server, "/" + APP_NAME + "/RequestSocket", "", expected, ""); + } + + /** + * Simple logging primarily for unit testing etc. + * + * @param string + */ + protected void debug(String string) { + Utils.debug(string); + } +} \ No newline at end of file diff --git a/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/accesslists/Utils.java b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/accesslists/Utils.java index 3eb3a69dc5f5..90e0f237b8ca 100644 --- a/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/accesslists/Utils.java +++ b/dev/io.openliberty.transport.http_fat/fat/src/io/openliberty/transport/http_fat/accesslists/Utils.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2021 IBM Corporation and others.n + * Copyright (c) 2021, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * Contributors: * IBM Corporation - initial API and implementation @@ -32,8 +32,13 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; +import org.apache.hc.client5.http.ssl.TrustAllStrategy; import org.apache.hc.core5.http.NoHttpResponseException; import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.ssl.SSLContextBuilder; import org.junit.Assert; import com.ibm.websphere.simplicity.RemoteFile; @@ -100,6 +105,63 @@ public static String get(LibertyServer server, return result; } + /** + * Do a simple https get to a server uri with trace + * + * @param server target server + * @param reqURI 'ContextRoot/path' + * @param resExpectedStatusCode + * @param resExpectedText + * @param resNotExpectedText will fail if this is in what is returned + * @return the response text + * @throws Exception + */ + public static String getSecure(LibertyServer server, + String reqURI, String resExpectedStatusCode, String resExpectedText, String resNotExpectedText) throws Exception { + + String url = "https://" + server.getHostname() + ":" + server.getHttpDefaultSecurePort() + reqURI; + debug("Expecting response text [" + resExpectedText + "]"); + debug("Expecting NO response text [" + resNotExpectedText + "]"); + debug("Expecting status code [" + resExpectedStatusCode + "]"); + debug("Sending --> GET" + " [" + url + "]"); + + HttpUriRequestBase method = new HttpGet(url); + + String result = null; + + HttpClientBuilder builder = HttpClients.custom() + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create() + .setSslContext(SSLContextBuilder.create() + .loadTrustMaterial(TrustAllStrategy.INSTANCE) + .build()) + .build()) + .build()) + .disableRedirectHandling(); + + try (final CloseableHttpClient client = builder.build()) { + try (final CloseableHttpResponse response = client.execute(method)) { + String responseText = EntityUtils.toString(response.getEntity()); + String responseCode = String.valueOf(response.getCode()); + + debug("\n" + "##### Response Text ##### \n[" + responseText + "]"); + debug("##### Response Code ###### [" + responseCode + "]"); + + if (resExpectedStatusCode != null && !resExpectedStatusCode.isEmpty()) + assertTrue("The response did not contain the status code " + resExpectedStatusCode, responseCode.equals(resExpectedStatusCode)); + + if (resExpectedText != null && !resExpectedText.isEmpty()) + assertTrue("The response did not contain the following text: " + resExpectedText + " it was " + responseText, responseText.contains(resExpectedText)); + + if (resNotExpectedText != null && !resNotExpectedText.isEmpty()) + assertFalse("The response did not contain the following text: " + resNotExpectedText, responseText.contains(resNotExpectedText)); + result = responseText; + } + } + + return result; + } + /** * Do a simple http get to a server uri with trace and expect it to work * diff --git a/dev/io.openliberty.transport.http_fat/publish/features/webcontainerlibertyinternals.mf b/dev/io.openliberty.transport.http_fat/publish/features/webcontainerlibertyinternals.mf new file mode 100644 index 000000000000..5ca1ad8a5e82 --- /dev/null +++ b/dev/io.openliberty.transport.http_fat/publish/features/webcontainerlibertyinternals.mf @@ -0,0 +1,8 @@ +Subsystem-ManifestVersion: 1 +Subsystem-SymbolicName: webcontainerlibertyinternals-1.0; visibility:=public +Subsystem-Version: 1.0.0 +Subsystem-Type: osgi.subsystem.feature +IBM-API-Package: com.ibm.wsspi.webcontainer.servlet; type="internal", + com.ibm.websphere.servlet.request; type="internal", + com.ibm.websphere.servlet.request.extended; type="internal" +IBM-Feature-Version: 2 diff --git a/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/bootstrap.properties b/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/bootstrap.properties new file mode 100644 index 000000000000..184ced4ad557 --- /dev/null +++ b/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/bootstrap.properties @@ -0,0 +1,14 @@ +############################################################################### +# Copyright (c) 2025 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +bootstrap.include=../testports.properties +com.ibm.ws.logging.trace.specification=*=info diff --git a/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/server.xml b/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/server.xml new file mode 100644 index 000000000000..f83e0d5a6339 --- /dev/null +++ b/dev/io.openliberty.transport.http_fat/publish/servers/RequestSocket/server.xml @@ -0,0 +1,21 @@ + + + + + servlet-3.1 + transportSecurity-1.0 + componenttest-1.0 + webcontainerlibertyinternals-1.0 + + + + + + + + diff --git a/dev/io.openliberty.transport.http_fat/test-applications/app1/src/app1/web/RequestSocket.java b/dev/io.openliberty.transport.http_fat/test-applications/app1/src/app1/web/RequestSocket.java new file mode 100644 index 000000000000..c60873ae0412 --- /dev/null +++ b/dev/io.openliberty.transport.http_fat/test-applications/app1/src/app1/web/RequestSocket.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package app1.web; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.Socket; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.ibm.websphere.servlet.request.IRequest; +import com.ibm.websphere.servlet.request.extended.IRequestExtended; +import com.ibm.wsspi.webcontainer.servlet.IExtendedRequest; + +@SuppressWarnings("serial") +@WebServlet("/RequestSocket") +public class RequestSocket extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + IExtendedRequest extRequest = (IExtendedRequest) request; + IRequest iRequest = extRequest.getIRequest(); + IRequestExtended iRequestExt = (IRequestExtended) iRequest; + Socket socket = iRequestExt.getRequestSocket(); + + PrintWriter writer = response.getWriter(); + writer.println("RequestSocket called from " + + "socket LocalPort: " + socket.getLocalPort() + + ", socket Port: " + socket.getPort()); + writer.flush(); + writer.close(); + } + +} From 569ce5218a73afd580b315516e6d3843d7ccf067 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 22 May 2025 13:09:01 -0400 Subject: [PATCH 4/4] Add request socket test to com.ibm.ws.transport.http2_fat Signed-off-by: Scott Kurz --- dev/com.ibm.ws.transport.http2_fat/bnd.bnd | 2 + .../test/server/transport/http2/FATSuite.java | 5 +- .../http2/Http2RequestSocketTests.java | 105 ++++++++++++++++++ .../features/webcontainerlibertyinternals.mf | 8 ++ .../publish/files/webContainerInternals.xml | 31 ++++++ .../.gitignore | 2 + .../bootstrap.properties | 5 + .../server.xml | 23 ++++ .../war/servlets/H2FATDriverServlet.java | 25 ++++- .../war/servlets/GetRequestSocketServlet.java | 47 ++++++++ .../test/war/servlets/SimplePushServlet.java | 2 +- 11 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/Http2RequestSocketTests.java create mode 100644 dev/com.ibm.ws.transport.http2_fat/publish/features/webcontainerlibertyinternals.mf create mode 100644 dev/com.ibm.ws.transport.http2_fat/publish/files/webContainerInternals.xml create mode 100644 dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/.gitignore create mode 100644 dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/bootstrap.properties create mode 100644 dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/server.xml create mode 100644 dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/GetRequestSocketServlet.java diff --git a/dev/com.ibm.ws.transport.http2_fat/bnd.bnd b/dev/com.ibm.ws.transport.http2_fat/bnd.bnd index ad7bba4fd16d..611acde490a1 100644 --- a/dev/com.ibm.ws.transport.http2_fat/bnd.bnd +++ b/dev/com.ibm.ws.transport.http2_fat/bnd.bnd @@ -25,6 +25,8 @@ fat.project: true com.ibm.websphere.javaee.servlet.4.0;version=latest,\ com.ibm.ws.transport.http;version=latest,\ com.ibm.ws.channelfw;version=latest,\ + com.ibm.websphere.appserver.spi.servlet;version=latest, \ + com.ibm.ws.webcontainer;version=latest, \ org.apache.httpcomponents.client5:httpclient5;version=5.0.2,\ org.apache.httpcomponents.core5:httpcore5;version=5.0.2,\ org.apache.httpcomponents.core5:httpcore5-h2;version=5.0.2 diff --git a/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/FATSuite.java b/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/FATSuite.java index 7ca4472931a9..a8a3e58f5de1 100755 --- a/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/FATSuite.java +++ b/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/FATSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2023 IBM Corporation and others. + * Copyright (c) 2018, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -46,7 +46,8 @@ Http2Config31H2Off.class, // FULL Http2Config31H2On.class, // FULL Http2WindowUpdateTests.class, //FULL - Http2CompressionTests.class //FULL + Http2CompressionTests.class, //FULL + Http2RequestSocketTests.class, // FULL //MultiSessionTests.class // FULL; disabled for now }) diff --git a/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/Http2RequestSocketTests.java b/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/Http2RequestSocketTests.java new file mode 100644 index 000000000000..eba4d3167606 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/fat/src/test/server/transport/http2/Http2RequestSocketTests.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package test.server.transport.http2; + +import static org.junit.Assert.assertNotNull; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.runner.RunWith; + +import com.ibm.ws.http2.client.SecureHttp2Client; + +import componenttest.custom.junit.runner.FATRunner; +import componenttest.custom.junit.runner.Mode; +import componenttest.custom.junit.runner.Mode.TestMode; +import componenttest.topology.impl.LibertyServer; +import componenttest.topology.impl.LibertyServerFactory; +import componenttest.topology.utils.FATServletClient; + +/** + * + */ +@RunWith(FATRunner.class) +@Mode(TestMode.FULL) +public class Http2RequestSocketTests extends FATServletClient { + + private static final String CLASS_NAME = Http2RequestSocketTests.class.getName(); + private static final Logger LOGGER = Logger.getLogger(CLASS_NAME); + private static SecureHttp2Client client; + + private final static LibertyServer server = LibertyServerFactory.getLibertyServer("com.ibm.ws.transport.http2.fat.requestsocket"); + private final static LibertyServer runtimeServer = LibertyServerFactory.getLibertyServer("http2ClientRuntime"); + + @Rule + public TestName testName = new TestName(); + + @BeforeClass + public static void before() throws Exception { + + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.logp(Level.INFO, CLASS_NAME, "before()", "Starting servers..."); + } + + H2FATApplicationHelper.addWarToServerDropins(runtimeServer, "H2FATDriver.war", true, "http2.test.driver.war.servlets"); + runtimeServer.startServer(true, true); + + H2FATApplicationHelper.addWarToServerDropins(server, "H2TestModule.war", true, "http2.test.war.servlets"); + server.installSystemFeature("webcontainerlibertyinternals"); + server.startServer(Http2SecureTests.class.getSimpleName() + ".log"); + assertNotNull("CWWKO0219I.*ssl not received", server.waitForStringInLog("CWWKO0219I.*ssl")); + client = new SecureHttp2Client(); + + } + + @AfterClass + public static void after() throws Exception { + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.logp(Level.INFO, CLASS_NAME, "after()", "Stopping servers......"); + } + // try for an orderly quiet shutdown + Thread.sleep(5000); + runtimeServer.stopServer(true); + Thread.sleep(5000); + server.stopServer(true); + } + + @Test + public void testGetRequestSocketSecure() throws Exception { + String[] requestUris = new String[] { "/H2TestModule/GetRequestSocketServlet" }; + int port = server.getHttpSecondarySecurePort(); + String expectedResponse = "RequestSocket called from socket LocalPort: " + port + System.lineSeparator(); + List results = client.makeSecureRequests(server.getHostname(), port, requestUris, 0); + validateSingleResponse(results, expectedResponse); + } + + @Test + public void testGetRequestSocketInsecure() throws Exception { + String testName = "testGetRequestSocketInsecure"; + FATServletClient.runTest(runtimeServer, + "H2FATDriver/H2FATDriverServlet?hostName=" + server.getHostname() + "&port=" + server.getHttpSecondaryPort(), + testName); + } + + private void validateSingleResponse(List results, String expectedResponse) { + Assert.assertTrue("At least one result not present, results size = " + results.size(), results.size() >= 1); + String firstResult = results.get(0); + Assert.assertEquals("Expected response not found in result", expectedResponse, firstResult); + } + +} diff --git a/dev/com.ibm.ws.transport.http2_fat/publish/features/webcontainerlibertyinternals.mf b/dev/com.ibm.ws.transport.http2_fat/publish/features/webcontainerlibertyinternals.mf new file mode 100644 index 000000000000..5ca1ad8a5e82 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/publish/features/webcontainerlibertyinternals.mf @@ -0,0 +1,8 @@ +Subsystem-ManifestVersion: 1 +Subsystem-SymbolicName: webcontainerlibertyinternals-1.0; visibility:=public +Subsystem-Version: 1.0.0 +Subsystem-Type: osgi.subsystem.feature +IBM-API-Package: com.ibm.wsspi.webcontainer.servlet; type="internal", + com.ibm.websphere.servlet.request; type="internal", + com.ibm.websphere.servlet.request.extended; type="internal" +IBM-Feature-Version: 2 diff --git a/dev/com.ibm.ws.transport.http2_fat/publish/files/webContainerInternals.xml b/dev/com.ibm.ws.transport.http2_fat/publish/files/webContainerInternals.xml new file mode 100644 index 000000000000..8b79b4a93ba9 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/publish/files/webContainerInternals.xml @@ -0,0 +1,31 @@ + + + jsp-2.3 + servlet-4.0 + timedexit-1.0 + transportSecurity-1.0 + webcontainerlibertyinternals-1.0 + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/.gitignore b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/.gitignore new file mode 100644 index 000000000000..fb4c540503df --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/.gitignore @@ -0,0 +1,2 @@ +/apps +/dropins \ No newline at end of file diff --git a/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/bootstrap.properties b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/bootstrap.properties new file mode 100644 index 000000000000..fbbf0add12c2 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/bootstrap.properties @@ -0,0 +1,5 @@ +com.ibm.ws.logging.trace.specification=*=info=enabled +com.ibm.ws.logging.max.file.size=0 + +ds.loglevel=debug +bootstrap.include=../testports.properties diff --git a/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/server.xml b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/server.xml new file mode 100644 index 000000000000..ec6e6d85d691 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/publish/servers/com.ibm.ws.transport.http2.fat.requestsocket/server.xml @@ -0,0 +1,23 @@ + + + servlet-4.0 + timedexit-1.0 + transportSecurity-1.0 + webcontainerlibertyinternals-1.0 + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.transport.http2_fat/test-applications/H2FATDriver.war/src/http2/test/driver/war/servlets/H2FATDriverServlet.java b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2FATDriver.war/src/http2/test/driver/war/servlets/H2FATDriverServlet.java index 9fdc9d30d5bd..8fb3c6958de0 100755 --- a/dev/com.ibm.ws.transport.http2_fat/test-applications/H2FATDriver.war/src/http2/test/driver/war/servlets/H2FATDriverServlet.java +++ b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2FATDriver.war/src/http2/test/driver/war/servlets/H2FATDriverServlet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2023 IBM Corporation and others. + * Copyright (c) 2018, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -4824,6 +4824,29 @@ public void testMaxStreamsRefused(HttpServletRequest request, } + public void testGetRequestSocketInsecure(HttpServletRequest request, HttpServletResponse response) throws InterruptedException, Exception { + + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.logp(Level.INFO, this.getClass().getName(), "testGetRequestSocketInsecure", "Started!"); + LOGGER.logp(Level.INFO, this.getClass().getName(), "testGetRequestSocketInsecure", + "Connecting to = " + request.getParameter("hostName") + ":" + request.getParameter("port")); + } + + CountDownLatch blockUntilConnectionIsDone = new CountDownLatch(1); + String testName = "testGetRequestSocketInsecure"; + + Http2Client h2Client = getDefaultH2Client(request, response, blockUntilConnectionIsDone); + String expectedResponse = "RequestSocket called from socket LocalPort: " + request.getParameter("port") + System.lineSeparator(); + + h2Client.addExpectedFrame(new FrameData(1, expectedResponse.getBytes(), 0, false, false, false)); + + setupDefaultUpgradedConnection(h2Client, "/H2TestModule/GetRequestSocketServlet"); + + blockUntilConnectionIsDone.await(); + handleErrors(h2Client, testName); + + } + void handleErrors(Http2Client client, String testName) { boolean testFailed = false; List errors = client.getReportedExceptions(); diff --git a/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/GetRequestSocketServlet.java b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/GetRequestSocketServlet.java new file mode 100644 index 000000000000..9ce5c842b2d3 --- /dev/null +++ b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/GetRequestSocketServlet.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package http2.test.war.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.Socket; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.ibm.websphere.servlet.request.IRequest; +import com.ibm.websphere.servlet.request.extended.IRequestExtended; +import com.ibm.wsspi.webcontainer.servlet.IExtendedRequest; + +@WebServlet("/GetRequestSocketServlet") +public class GetRequestSocketServlet extends HttpServlet { + static final long serialVersionUID = 9999L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + IExtendedRequest extRequest = (IExtendedRequest) req; + IRequest iRequest = extRequest.getIRequest(); + IRequestExtended iRequestExt = (IRequestExtended) iRequest; + Socket socket = iRequestExt.getRequestSocket(); + + PrintWriter writer = resp.getWriter(); + writer.println("RequestSocket called from " + + "socket LocalPort: " + socket.getLocalPort()); + + writer.flush(); + writer.close(); + } +} diff --git a/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/SimplePushServlet.java b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/SimplePushServlet.java index 8ac5c3bc8c9a..46de680e743a 100644 --- a/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/SimplePushServlet.java +++ b/dev/com.ibm.ws.transport.http2_fat/test-applications/H2TestModule.war/src/http2/test/war/servlets/SimplePushServlet.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: