This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
The following commit(s) were added to refs/heads/master by this push:
new b3dcad805a Add unit test to prevent axiom loading with
enableJSONOnly=true
b3dcad805a is described below
commit b3dcad805a1a973387a2fb9d61142889961581db
Author: Robert Lazarski <[email protected]>
AuthorDate: Mon Nov 24 08:25:49 2025 -1000
Add unit test to prevent axiom loading with enableJSONOnly=true
---
.../sample/asyncdoclit/client/AsyncClient.java | 2 +-
.../test-resources/axis2_addressing.xml | 2 +-
.../org/apache/axis2/testutils/Axis2Server.java | 13 ++++++++--
.../org/apache/axis2/testutils/PortAllocator.java | 29 +++++++++++++++++++++-
modules/transport/http/pom.xml | 5 ++++
.../apache/axis2/transport/http/AxisServlet.java | 6 +++--
6 files changed, 50 insertions(+), 7 deletions(-)
diff --git
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/asyncdoclit/client/AsyncClient.java
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/asyncdoclit/client/AsyncClient.java
index 664be75596..b0ed24edae 100644
---
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/asyncdoclit/client/AsyncClient.java
+++
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/asyncdoclit/client/AsyncClient.java
@@ -23,7 +23,7 @@ import java.util.concurrent.TimeoutException;
public class AsyncClient {
- private static final int max_isasleep_check = 30;
+ private static final int max_isasleep_check = 60;
/**
* Auxiliary method used for doiing isAsleep checks. Will perform isAsleep
diff --git a/modules/jaxws-integration/test-resources/axis2_addressing.xml
b/modules/jaxws-integration/test-resources/axis2_addressing.xml
index 244f7eb48d..30c898b017 100644
--- a/modules/jaxws-integration/test-resources/axis2_addressing.xml
+++ b/modules/jaxws-integration/test-resources/axis2_addressing.xml
@@ -173,7 +173,7 @@
<!-- ================================================= -->
<transportReceiver name="http"
class="org.apache.axis2.transport.http.SimpleHTTPServer">
- <parameter name="port">9090</parameter>
+ <!-- <parameter name="port">9090</parameter> Port dynamically
allocated by test framework -->
<!-- Here is the complete list of supported parameters (see example
settings further below):
port: the port to listen on (default 6060)
hostname: if non-null, url prefix used in reply-to endpoint
references (default null)
diff --git
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
index 3497ee0a1a..bd58a3f757 100644
---
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
+++
b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
@@ -73,8 +73,17 @@ public class Axis2Server extends AbstractAxis2Server {
@Override
protected void stopServer() {
System.out.println("[Axis2Server] stopServer() invoked, setting port
to -1");
+ if (server != null) {
+ server.stop();
+ server = null;
+
+ // Add small delay to ensure port is fully released before next
test
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
port = -1;
- server.stop();
- server = null;
}
}
diff --git
a/modules/testutils/src/main/java/org/apache/axis2/testutils/PortAllocator.java
b/modules/testutils/src/main/java/org/apache/axis2/testutils/PortAllocator.java
index d8fdf8ef60..ef575d8820 100644
---
a/modules/testutils/src/main/java/org/apache/axis2/testutils/PortAllocator.java
+++
b/modules/testutils/src/main/java/org/apache/axis2/testutils/PortAllocator.java
@@ -20,13 +20,14 @@ package org.apache.axis2.testutils;
import java.io.IOException;
import java.net.ServerSocket;
+import java.util.concurrent.ThreadLocalRandom;
public final class PortAllocator {
private PortAllocator() {}
/**
* Allocate a TCP port.
- *
+ *
* @return the allocated port
*/
public static int allocatePort() {
@@ -34,6 +35,32 @@ public final class PortAllocator {
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
+
+ // Add retry mechanism to reduce race condition where another
process
+ // grabs the port between close() and actual bind
+ for (int retry = 0; retry < 5; retry++) {
+ try {
+ // Test if the port is still available by trying to bind
again
+ ServerSocket testSocket = new ServerSocket(port);
+ testSocket.close();
+
+ // Add small random delay to reduce parallel test conflicts
+ if (retry > 0) {
+ Thread.sleep(ThreadLocalRandom.current().nextInt(10,
50));
+ }
+
+ return port;
+ } catch (IOException bindEx) {
+ // Port already taken, try allocating a new one
+ ss = new ServerSocket(0);
+ port = ss.getLocalPort();
+ ss.close();
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ break;
+ }
+ }
+
return port;
} catch (IOException ex) {
throw new Error("Unable to allocate TCP port", ex);
diff --git a/modules/transport/http/pom.xml b/modules/transport/http/pom.xml
index 893d7f47ed..07678b356a 100644
--- a/modules/transport/http/pom.xml
+++ b/modules/transport/http/pom.xml
@@ -82,6 +82,11 @@
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
index dfbbaea645..96f99098f5 100644
---
a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
+++
b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java
@@ -247,8 +247,10 @@ public class AxisServlet extends HttpServlet {
throw new ServletException(e2);
}
} finally {
- closeStaxBuilder(msgContext);
- TransportUtils.deleteAttachments(msgContext);
+ if (!enableJSONOnly) {
+ closeStaxBuilder(msgContext);
+ TransportUtils.deleteAttachments(msgContext);
+ }
}
} else {
if (!disableREST) {