Skip to content

Commit 4f720f7

Browse files
Fix transport-h2 unit tests
1 parent 4aa3284 commit 4f720f7

File tree

7 files changed

+199
-10
lines changed

7 files changed

+199
-10
lines changed

modules/kernel/src/org/apache/axis2/kernel/http/HTTPConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ public class HTTPConstants {
227227
*/
228228
public static final String HEADER_PROTOCOL_10 = "HTTP/1.0";
229229

230+
/**
231+
* Field HEADER_PROTOCOL_20
232+
*/
233+
public static final String HEADER_PROTOCOL_20 = "HTTP/2.0";
234+
230235
/**
231236
* Field HEADER_PRAGMA
232237
*/

modules/transport-h2/src/test/java/org/apache/axis2/transport/h2/H2SOAPCompatibilityTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
package org.apache.axis2.transport.h2;
2020

21-
import static com.google.common.truth.Truth.assertAbout;
22-
import static org.apache.axiom.truth.xml.XMLTruth.xml;
23-
2421
import java.io.IOException;
2522
import java.util.ArrayList;
2623
import java.util.Iterator;
@@ -39,14 +36,12 @@
3936
import org.apache.axiom.soap.SOAP11Constants;
4037
import org.apache.axiom.soap.SOAP12Constants;
4138
import org.apache.axis2.AxisFault;
42-
import org.apache.axis2.Constants;
4339
import org.apache.axis2.context.ConfigurationContext;
4440
import org.apache.axis2.context.ConfigurationContextFactory;
4541
import org.apache.axis2.context.MessageContext;
4642
import org.apache.axis2.context.NamedValue;
4743
import org.apache.axis2.description.Parameter;
4844
import org.apache.axis2.description.TransportOutDescription;
49-
import org.apache.axis2.engine.Handler.InvocationResponse;
5045
import org.apache.axis2.kernel.http.HTTPConstants;
5146
import org.apache.axis2.transport.h2.impl.httpclient5.H2TransportSender;
5247

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.axis2.transport.h2;
21+
22+
import junit.framework.TestCase;
23+
import org.apache.axis2.AxisFault;
24+
import org.apache.axis2.context.ConfigurationContext;
25+
import org.apache.axis2.description.Parameter;
26+
import org.apache.axis2.description.TransportOutDescription;
27+
import org.apache.axis2.engine.AxisConfiguration;
28+
import org.apache.axis2.transport.h2.impl.httpclient5.H2TransportSender;
29+
30+
/**
31+
* Test to verify that the HTTP/2.0 PROTOCOL parameter validation fix works correctly.
32+
*/
33+
public class ProtocolValidationTest extends TestCase {
34+
35+
public void testHTTP2ProtocolValidation() throws Exception {
36+
// Create minimal configuration context
37+
AxisConfiguration axisConfig = new AxisConfiguration();
38+
ConfigurationContext configContext = new ConfigurationContext(axisConfig);
39+
40+
// Create transport description with HTTP/2.0 protocol
41+
TransportOutDescription transportOut = new TransportOutDescription("h2");
42+
transportOut.addParameter(new Parameter("PROTOCOL", "HTTP/2.0"));
43+
44+
// Create H2TransportSender
45+
H2TransportSender transportSender = new H2TransportSender();
46+
47+
try {
48+
// This should NOT throw an exception after the fix
49+
transportSender.init(configContext, transportOut);
50+
51+
// If we get here, the fix worked
52+
System.out.println("SUCCESS: H2TransportSender.init() accepted HTTP/2.0 protocol");
53+
54+
// Verify the protocol parameter was preserved
55+
Parameter protocolParam = transportOut.getParameter("PROTOCOL");
56+
assertNotNull("Protocol parameter should not be null", protocolParam);
57+
assertEquals("Protocol parameter should be HTTP/2.0", "HTTP/2.0", protocolParam.getValue());
58+
59+
} catch (AxisFault e) {
60+
// If we get the old error, the fix didn't work
61+
if (e.getMessage().contains("Can have values only HTTP/1.0 or HTTP/1.1")) {
62+
fail("FIX FAILED: Still getting protocol validation error: " + e.getMessage());
63+
} else {
64+
// Some other error - re-throw it
65+
throw e;
66+
}
67+
} finally {
68+
// Clean up
69+
try {
70+
transportSender.stop();
71+
} catch (Exception e) {
72+
// Ignore cleanup errors
73+
}
74+
}
75+
}
76+
77+
public void testHTTP11StillWorks() throws Exception {
78+
// Verify that HTTP/1.1 still works after our changes
79+
AxisConfiguration axisConfig = new AxisConfiguration();
80+
ConfigurationContext configContext = new ConfigurationContext(axisConfig);
81+
82+
TransportOutDescription transportOut = new TransportOutDescription("h2");
83+
transportOut.addParameter(new Parameter("PROTOCOL", "HTTP/1.1"));
84+
85+
H2TransportSender transportSender = new H2TransportSender();
86+
87+
try {
88+
// This should work fine
89+
transportSender.init(configContext, transportOut);
90+
91+
// Verify the protocol parameter was preserved
92+
Parameter protocolParam = transportOut.getParameter("PROTOCOL");
93+
assertNotNull("Protocol parameter should not be null", protocolParam);
94+
assertEquals("Protocol parameter should be HTTP/1.1", "HTTP/1.1", protocolParam.getValue());
95+
96+
} finally {
97+
try {
98+
transportSender.stop();
99+
} catch (Exception e) {
100+
// Ignore cleanup errors
101+
}
102+
}
103+
}
104+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.axis2.transport.h2;
21+
22+
import junit.framework.TestCase;
23+
import org.apache.axis2.AxisFault;
24+
import org.apache.axis2.context.ConfigurationContext;
25+
import org.apache.axis2.description.Parameter;
26+
import org.apache.axis2.description.TransportOutDescription;
27+
import org.apache.axis2.engine.AxisConfiguration;
28+
import org.apache.axis2.kernel.http.HTTPConstants;
29+
import org.apache.axis2.transport.h2.impl.httpclient5.H2TransportSender;
30+
31+
/**
32+
* Simple test to verify HTTP/2.0 protocol support works with the cleaner approach.
33+
*/
34+
public class SimpleProtocolTest extends TestCase {
35+
36+
public void testHTTP2ProtocolSupport() throws Exception {
37+
System.out.println("Testing clean HTTP/2.0 protocol support...");
38+
39+
// Create minimal test setup
40+
AxisConfiguration axisConfig = new AxisConfiguration();
41+
ConfigurationContext configContext = new ConfigurationContext(axisConfig);
42+
TransportOutDescription transportOut = new TransportOutDescription("h2");
43+
44+
// Set HTTP/2.0 protocol parameter
45+
transportOut.addParameter(new Parameter("PROTOCOL", HTTPConstants.HEADER_PROTOCOL_20));
46+
47+
H2TransportSender sender = new H2TransportSender();
48+
49+
try {
50+
// This should work with our clean fix
51+
sender.init(configContext, transportOut);
52+
System.out.println("✅ SUCCESS: HTTP/2.0 protocol accepted!");
53+
54+
// Verify parameter is still HTTP/2.0
55+
Parameter protocol = transportOut.getParameter("PROTOCOL");
56+
assertEquals("HTTP/2.0 parameter should be preserved",
57+
HTTPConstants.HEADER_PROTOCOL_20, protocol.getValue());
58+
59+
} catch (AxisFault e) {
60+
System.err.println("❌ FAILED: " + e.getMessage());
61+
throw e;
62+
} finally {
63+
try {
64+
sender.stop();
65+
} catch (Exception ignored) {}
66+
}
67+
}
68+
69+
public void testConstantValue() {
70+
// Verify our constant is correct
71+
assertEquals("HTTP/2.0 constant should match expected value",
72+
"HTTP/2.0", HTTPConstants.HEADER_PROTOCOL_20);
73+
System.out.println("✅ HTTP/2.0 constant value is correct: " + HTTPConstants.HEADER_PROTOCOL_20);
74+
}
75+
}

modules/transport/http/src/main/java/org/apache/axis2/transport/http/AbstractHTTPTransportSender.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public void init(ConfigurationContext confContext,
8787
setHTTPClientVersion(confContext);
8888

8989
// <parameter name="PROTOCOL">HTTP/1.0</parameter> or
90-
// <parameter name="PROTOCOL">HTTP/1.1</parameter> is
90+
// <parameter name="PROTOCOL">HTTP/1.1</parameter> or
91+
// <parameter name="PROTOCOL">HTTP/2.0</parameter> is
9192
// checked
9293
Parameter version = transportOut
9394
.getParameter(HTTPConstants.PROTOCOL_VERSION);
@@ -106,10 +107,15 @@ public void init(ConfigurationContext confContext,
106107
} else if (HTTPConstants.HEADER_PROTOCOL_10.equals(version
107108
.getValue())) {
108109
defaultHttpVersion = HTTPConstants.HEADER_PROTOCOL_10;
110+
} else if (HTTPConstants.HEADER_PROTOCOL_20.equals(version
111+
.getValue())) {
112+
defaultHttpVersion = HTTPConstants.HEADER_PROTOCOL_20;
113+
// HTTP/2.0 supports multiplexing, so enable chunked by default
114+
defaultChunked = true;
109115
} else {
110116
throw new AxisFault("Parameter "
111117
+ HTTPConstants.PROTOCOL_VERSION
112-
+ " Can have values only HTTP/1.0 or HTTP/1.1");
118+
+ " Can have values only HTTP/1.0, HTTP/1.1, or HTTP/2.0");
113119
}
114120
}
115121

modules/transport/http/src/main/java/org/apache/axis2/transport/http/HTTPSender.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ public void setHttpVersion(String version) throws AxisFault {
9696
this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
9797
// chunked is not possible with HTTP/1.0
9898
this.chunked = false;
99+
} else if (HTTPConstants.HEADER_PROTOCOL_20.equals(version)) {
100+
this.httpVersion = HTTPConstants.HEADER_PROTOCOL_20;
101+
// HTTP/2.0 supports multiplexing, enable chunked
102+
this.chunked = true;
99103
} else {
100104
throw new AxisFault(
101105
"Parameter " + HTTPConstants.PROTOCOL_VERSION
102-
+ " Can have values only HTTP/1.0 or HTTP/1.1");
106+
+ " Can have values only HTTP/1.0, HTTP/1.1, or HTTP/2.0");
103107
}
104108
}
105109
}

src/site/xdoc/docs/http2-transport-additions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ options.setProperty("MAX_CONCURRENT_STREAMS", 20);
191191
<p>The H2TransportSender provides three processing modes optimized for different payload sizes:</p>
192192

193193
<ul>
194-
<li><strong>Standard Processing</strong> (&amp;lt;10MB): Regular HTTP/2 features</li>
194+
<li><strong>Standard Processing</strong> (0MB-10MB): Regular HTTP/2 features</li>
195195
<li><strong>Multiplexing Mode</strong> (10-50MB): Enhanced concurrent processing</li>
196196
<li><strong>Streaming Mode</strong> (50MB+): Memory-efficient streaming with chunked processing</li>
197197
</ul>
@@ -621,7 +621,7 @@ httpAsyncClient.start();
621621
<p>For SOAP services using HTTP/2 transport:</p>
622622

623623
<ul>
624-
<li><strong>Small SOAP Messages (&amp;lt;1MB):</strong> 5-15% latency improvement due to connection multiplexing</li>
624+
<li><strong>Small SOAP Messages (0MB-1MB):</strong> 5-15% latency improvement due to connection multiplexing</li>
625625
<li><strong>Medium SOAP Messages (1-10MB):</strong> 10-20% improvement from header compression</li>
626626
<li><strong>Large SOAP Messages (10MB+):</strong> 15-25% improvement from streaming, but still much slower than equivalent JSON</li>
627627
<li><strong>Concurrent SOAP Calls:</strong> 20-40% improvement from stream multiplexing</li>

0 commit comments

Comments
 (0)