Skip to content

Commit 1b1d5e9

Browse files
committed
Allow singleton handlers defined in the testsuite to participate in handshake logic.
1 parent 6b6decc commit 1b1d5e9

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

common/src/test/java/org/wildfly/httpclient/common/HTTPTestServer.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.undertow.server.handlers.BlockingHandler;
3030
import io.undertow.server.handlers.CanonicalPathHandler;
3131
import io.undertow.server.handlers.PathHandler;
32+
import io.undertow.server.handlers.RequestDumpingHandler;
3233
import io.undertow.server.handlers.error.SimpleErrorPageHandler;
3334
import io.undertow.util.NetworkUtils;
3435
import org.junit.runner.Description;
@@ -83,11 +84,18 @@
8384
import java.util.Map;
8485
import java.util.Objects;
8586
import java.util.Set;
87+
import java.util.function.Function;
8688
import java.util.stream.Collectors;
8789

8890
import static org.wildfly.security.password.interfaces.ClearPassword.ALGORITHM_CLEAR;
8991

9092
/**
93+
* HttpTestServer is a JUnit test runner which provides a configured local instance of Undertow to be used
94+
* as a target of invocations carried out in tests. In addition to providing default configurations for
95+
* security, buffer pools and XnioWorkers, the test runner also permits setting general context path handlers
96+
* as well as service handlers for the /wildfly-services context paths representing invokable services used by
97+
* the ejb, naming and transaction services.
98+
* -
9199
* @author Stuart Douglas
92100
*/
93101
public class HTTPTestServer extends BlockJUnit4ClassRunner {
@@ -183,6 +191,24 @@ public static void registerServicesHandler(String path, HttpHandler handler) {
183191
registeredServices.add(path);
184192
}
185193

194+
/*
195+
* Register a service handler wrapped with the interoperability logic.
196+
* This allows registering context paths of the form:
197+
* /prefix/{v1,v2}/postfix
198+
* The interoperability logic will handle the version parameter
199+
* automatically, according to the interoperability handshake.
200+
*
201+
* @param prefix the prefix context path before the version
202+
* @param postfix the postfix context path after the version
203+
* @param handler the handler to invoke for the context path
204+
*/
205+
public static void registerWrappedServicesHandler(String prefix, String postfix, HttpHandler handler) {
206+
PathHandler wrappedHandler = new PathHandler();
207+
wrappedHandler.addPrefixPath(postfix, handler);
208+
SERVICES_HANDLER.addPrefixPath(prefix, HttpServiceConfig.DEFAULT.wrap(wrappedHandler));
209+
registeredServices.add(prefix);
210+
}
211+
186212
public static XnioWorker getWorker() {
187213
return worker;
188214
}
@@ -274,6 +300,7 @@ protected HttpHandler getRootHandler() {
274300
root = new AuthenticationCallHandler(root);
275301
root = new SimpleErrorPageHandler(root);
276302
root = new CanonicalPathHandler(root);
303+
root = new RequestDumpingHandler(root);
277304
return root;
278305
}
279306

ejb/src/test/java/org/wildfly/httpclient/ejb/AsyncInvocationTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class AsyncInvocationTestCase {
4646

4747
@Before
4848
public void before() {
49-
EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
49+
EJBTestServer.registerWrappedServicesHandler("/common", "/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
50+
// EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
5051
}
5152

5253
@Test

ejb/src/test/java/org/wildfly/httpclient/ejb/SimpleInvocationTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public class SimpleInvocationTestCase {
5656

5757
@Before
5858
public void before() {
59-
EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
59+
EJBTestServer.registerWrappedServicesHandler("/common", "/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
60+
// EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
6061
StringBuilder sb = new StringBuilder();
6162
for (int i = 0; i < 10000; ++i) {
6263
sb.append("Hello World ");

naming/src/test/java/org/wildfly/httpclient/naming/ReadOnlyNamingOperationTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.wildfly.httpclient.naming;
2020

2121
import io.undertow.server.handlers.CookieImpl;
22+
import io.undertow.util.Headers;
2223
import org.junit.Assert;
2324
import org.junit.Before;
2425
import org.junit.Test;
@@ -35,7 +36,7 @@ public class ReadOnlyNamingOperationTestCase {
3536

3637
@Before
3738
public void setup() {
38-
HTTPTestServer.registerServicesHandler("/common/v1/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
39+
HTTPTestServer.registerWrappedServicesHandler("/common", "/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
3940
HTTPTestServer.registerServicesHandler("/naming", new HttpRemoteNamingService(new LocalContext(true), f -> false).createHandler());
4041
}
4142

naming/src/test/java/org/wildfly/httpclient/naming/SimpleNamingOperationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class SimpleNamingOperationTestCase {
5252

5353
@Before
5454
public void setup() {
55-
HTTPTestServer.registerServicesHandler("common/v1/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
55+
HTTPTestServer.registerWrappedServicesHandler("common", "/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
5656
HTTPTestServer.registerServicesHandler("naming", new HttpRemoteNamingService(new LocalContext(false), DEFAULT_CLASS_FILTER).createHandler());
5757
}
5858

transaction/src/test/java/org/wildfly/httpclient/transaction/SimpleTransactionOperationsTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class SimpleTransactionOperationsTestCase {
6767

6868
@Before
6969
public void setup() {
70-
HTTPTestServer.registerServicesHandler("common/v1/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
70+
HTTPTestServer.registerWrappedServicesHandler("/common", "/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
7171
HTTPTestServer.registerServicesHandler("txn", new HttpRemoteTransactionService(new LocalTransactionContext(new LocalTransactionProvider() {
7272
@Override
7373
public TransactionManager getTransactionManager() {

0 commit comments

Comments
 (0)