Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testsuite to work correctly with interoperability handshake #110

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public void completed(ClientExchange result) {
// this method adds the factory to the request instead of response, this is more efficient
// we prevent adding when jakartaEE is already true and creating a new entry in the response attachment map
final ClientResponse response = result.getResponse();
if (protocolVersion == -1) {
// if the response represents an UNAUTHORIZED (401) HTTP response, do not update the protocol version (WEJBHTTP-110)
if (protocolVersion == -1 && response.getResponseCode() != 401) {
// we need to check for protocol version header to define the protocol version of the pool
if (LATEST_VERSION.equals(response.getResponseHeaders().getFirst(PROTOCOL_VERSION))) {
// this indicates this is the first response server sends, set the protocol to 2
Expand Down
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 @@ -88,6 +89,12 @@
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 +190,23 @@ 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);
registerServicesHandler(prefix, HttpServiceConfig.DEFAULT.wrap(wrappedHandler));
}

public static XnioWorker getWorker() {
return worker;
}
Expand Down Expand Up @@ -274,6 +298,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,7 @@ 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));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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));
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
<goals><goal>test</goal></goals>
<configuration>
<systemPropertyVariables>
<org.wildfly.ee.interoperable>true</org.wildfly.ee.interoperable>
<org.wildfly.ee.namespace.interop>true</org.wildfly.ee.namespace.interop>
</systemPropertyVariables>
<reportsDirectory>${project.build.directory}/surefire-ee-interoperable-reports</reportsDirectory>
</configuration>
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