Skip to content

Commit

Permalink
Allow singleton handlers defined in the testsuite to participate in h…
Browse files Browse the repository at this point in the history
…andshake logic.
  • Loading branch information
rachmatowicz committed Apr 6, 2023
1 parent 6b6decc commit 1b1d5e9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.undertow.server.handlers.BlockingHandler;
import io.undertow.server.handlers.CanonicalPathHandler;
import io.undertow.server.handlers.PathHandler;
import io.undertow.server.handlers.RequestDumpingHandler;
import io.undertow.server.handlers.error.SimpleErrorPageHandler;
import io.undertow.util.NetworkUtils;
import org.junit.runner.Description;
Expand Down Expand Up @@ -83,11 +84,18 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

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

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

/*
* Register a service handler wrapped with the interoperability logic.
* This allows registering context paths of the form:
* /prefix/{v1,v2}/postfix
* The interoperability logic will handle the version parameter
* automatically, according to the interoperability handshake.
*
* @param prefix the prefix context path before the version
* @param postfix the postfix context path after the version
* @param handler the handler to invoke for the context path
*/
public static void registerWrappedServicesHandler(String prefix, String postfix, HttpHandler handler) {
PathHandler wrappedHandler = new PathHandler();
wrappedHandler.addPrefixPath(postfix, handler);
SERVICES_HANDLER.addPrefixPath(prefix, HttpServiceConfig.DEFAULT.wrap(wrappedHandler));
registeredServices.add(prefix);
}

public static XnioWorker getWorker() {
return worker;
}
Expand Down Expand Up @@ -274,6 +300,7 @@ protected HttpHandler getRootHandler() {
root = new AuthenticationCallHandler(root);
root = new SimpleErrorPageHandler(root);
root = new CanonicalPathHandler(root);
root = new RequestDumpingHandler(root);
return root;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class AsyncInvocationTestCase {

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class SimpleInvocationTestCase {

@Before
public void before() {
EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
EJBTestServer.registerWrappedServicesHandler("/common", "/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
// EJBTestServer.registerServicesHandler("common/v1/affinity", httpServerExchange -> httpServerExchange.getResponseHeaders().put(Headers.SET_COOKIE, "JSESSIONID=" + EJBTestServer.INITIAL_SESSION_AFFINITY));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; ++i) {
sb.append("Hello World ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wildfly.httpclient.naming;

import io.undertow.server.handlers.CookieImpl;
import io.undertow.util.Headers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -35,7 +36,7 @@ public class ReadOnlyNamingOperationTestCase {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SimpleNamingOperationTestCase {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SimpleTransactionOperationsTestCase {

@Before
public void setup() {
HTTPTestServer.registerServicesHandler("common/v1/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
HTTPTestServer.registerWrappedServicesHandler("/common", "/affinity", exchange -> exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", "foo")));
HTTPTestServer.registerServicesHandler("txn", new HttpRemoteTransactionService(new LocalTransactionContext(new LocalTransactionProvider() {
@Override
public TransactionManager getTransactionManager() {
Expand Down

0 comments on commit 1b1d5e9

Please sign in to comment.