Skip to content
Draft
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 @@ -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 @@ -274,6 +275,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 @@ -115,21 +115,29 @@ private abstract class NameHandler implements HttpHandler {

@Override
public final void handleRequest(HttpServerExchange exchange) throws Exception {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: calling handleRequest(%s)", exchange.getRequestPath());
PathTemplateMatch params = exchange.getAttachment(PathTemplateMatch.ATTACHMENT_KEY);
String name = URLDecoder.decode(params.getParameters().get(NAME_PATH_PARAMETER), UTF_8.name());
try {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: calling doOperation(name=%s)", name);
Object result = doOperation(exchange, name);
if (exchange.isComplete()) {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: exchange is complete, returning");
return;
}
if (result == null) {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: result is null, returning");
exchange.setStatusCode(StatusCodes.OK);
} else if (result instanceof Context) {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: result is context, returning");
exchange.setStatusCode(StatusCodes.NO_CONTENT);
} else {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: calling doMarshall");
doMarshall(exchange, result);
HttpNamingClientMessages.MESSAGES.infof("NameHandler: called doMarshall");
}
} catch (Throwable e) {
HttpNamingClientMessages.MESSAGES.infof("NameHandler: got exception, e = " +e);
sendException(exchange, httpServiceConfig, StatusCodes.INTERNAL_SERVER_ERROR, e);
}
}
Expand Down Expand Up @@ -268,6 +276,7 @@ public static void sendException(HttpServerExchange exchange, int status, Throwa
}

public static void sendException(HttpServerExchange exchange, HttpServiceConfig httpServiceConfig, int status, Throwable e) throws IOException {
HttpNamingClientMessages.MESSAGES.infof("HttpRemoteNamingService: sending exceptionto client, e = " + e);
HttpServerHelper.sendException(exchange, httpServiceConfig, status, e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.Unmarshaller;
import org.wildfly.common.annotation.NotNull;
import org.wildfly.httpclient.common.HttpMarshallerFactory;
import org.wildfly.httpclient.common.HttpTargetContext;
import org.wildfly.httpclient.common.WildflyHttpContext;
Expand Down Expand Up @@ -197,15 +198,19 @@ private static Unmarshaller createUnmarshaller(URI uri, HttpMarshallerFactory ht
}

private <T, R> R performWithRetry(NamingOperation<T, R> function, ProviderEnvironment environment, RetryContext context, Name name, T param) throws NamingException {

HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: calling performWithRetry");
// Directly pass-through single provider executions
if (context == null) {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: called peformWithRetry (retryContext == null)");
return function.apply(null, name, param);
}

for (int notFound = 0; ; ) {
try {
R result = function.apply(context, name, param);
environment.dropFromBlocklist(context.currentDestination());
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: called peformWithRetry (retryContext != null), notFound = %s", notFound);
return result;
} catch (NameNotFoundException e) {
if (notFound++ > MAX_NOT_FOUND_RETRY) {
Expand Down Expand Up @@ -253,7 +258,9 @@ private void updateBlocklist(ProviderEnvironment environment, RetryContext conte
environment.updateBlocklist(location);
}

private Object processInvocation(Name name, HttpString method, String pathSegment) throws NamingException {
private Object processInvocation(@NotNull Name name, @NotNull HttpString method, @NotNull String pathSegment) throws NamingException {

HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: calling Object processInvocation(name=%s, method=%s, pathSegment=%s)", name, method, pathSegment);
ProviderEnvironment environment = httpNamingProvider.getProviderEnvironment();
final RetryContext context = canRetry(environment) ? new RetryContext() : null;
return performWithRetry((contextOrNull, name1, param) -> {
Expand Down Expand Up @@ -287,7 +294,8 @@ private Object processInvocation(Name name, HttpString method, String pathSegmen
}, environment, context, name, null);
}

private Object performOperation(Name name, URI providerUri, HttpTargetContext targetContext, ClientRequest clientRequest) throws NamingException {
private Object performOperation(@NotNull Name name, @NotNull URI providerUri, @NotNull HttpTargetContext targetContext, @NotNull ClientRequest clientRequest) throws NamingException {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: calling Object performOperation(request = %s)", clientRequest);
final CompletableFuture<Object> result = new CompletableFuture<>();
final ProviderEnvironment providerEnvironment = httpNamingProvider.getProviderEnvironment();
final AuthenticationContext context = providerEnvironment.getAuthenticationContextSupplier().get();
Expand All @@ -306,13 +314,16 @@ private Object performOperation(Name name, URI providerUri, HttpTargetContext ta
targetContext.sendRequest(clientRequest, sslContext, authenticationConfiguration, null, (input, response, closeable) -> {
try {
if (response.getResponseCode() == StatusCodes.NO_CONTENT) {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext.HttpResultHandler: response has no content, completing");
result.complete(new HttpRemoteContext(HttpRootContext.this, name.toString()));
IoUtils.safeClose(input);
return;
}

httpNamingProvider.performExceptionAction((a, b) -> {

HttpNamingClientMessages.MESSAGES.infof("HttpRootContext.HttpResultHandler: response has content, unmarshalling");

Exception exception = null;
Object returned = null;
ClassLoader old = setContextClassLoader(tccl);
Expand All @@ -336,8 +347,10 @@ private Object performOperation(Name name, URI providerUri, HttpTargetContext ta
setContextClassLoader(old);
}
if (exception != null) {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext.HttpResultHandler: got exception, completingExceptionally future");
result.completeExceptionally(exception);
} else {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext.HttpResultHandler: got result, completing future");
result.complete(returned);
}
return null;
Expand Down Expand Up @@ -370,7 +383,9 @@ private Object performOperation(Name name, URI providerUri, HttpTargetContext ta
}


private void processInvocation(Name name, HttpString method, Object object, String pathSegment, Name newName) throws NamingException {
private void processInvocation(@NotNull Name name, @NotNull HttpString method, Object object, @NotNull String pathSegment, Name newName) throws NamingException {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: calling void processInvocation(name=%s, method=%s, pathSegment=%s)",
name, method, pathSegment);
ProviderEnvironment environment = httpNamingProvider.getProviderEnvironment();
final RetryContext context = canRetry(environment) ? new RetryContext() : null;
performWithRetry((contextOrNull, name1, param) -> {
Expand Down Expand Up @@ -417,7 +432,8 @@ private boolean canRetry(ProviderEnvironment environment) {
return environment.getProviderUris().size() > 1;
}

private void performOperation(URI providerUri, Object object, HttpTargetContext targetContext, ClientRequest clientRequest) throws NamingException {
private void performOperation(@NotNull URI providerUri, Object object, @NotNull HttpTargetContext targetContext, @NotNull ClientRequest clientRequest) throws NamingException {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: calling void performOperation(request = %s)", clientRequest);
final CompletableFuture<Object> result = new CompletableFuture<>();
final ProviderEnvironment providerEnvironment = httpNamingProvider.getProviderEnvironment();
final AuthenticationContext context = providerEnvironment.getAuthenticationContextSupplier().get();
Expand All @@ -444,6 +460,7 @@ private void performOperation(URI providerUri, Object object, HttpTargetContext
try {
result.complete(null);
} finally {
HttpNamingClientMessages.MESSAGES.infof("HttpRootContext: void performOperation(), closing channel");
IoUtils.safeClose(closeable);
}
}, result::completeExceptionally, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ public LocalContext(boolean readOnly) {
this.readOnly = readOnly;
}

private void dumpContext() {
HttpNamingClientMessages.MESSAGES.infof("dump LocalContext: context = %s", bindings);
}

@Override
public Object lookup(Name name) throws NamingException {
dumpContext();
return lookup(name.toString());
}

@Override
public Object lookup(String name) throws NamingException {
dumpContext();
Object res = bindings.get(name);
if (res == null) {
throw new NameNotFoundException();
Expand All @@ -63,11 +69,13 @@ public Object lookup(String name) throws NamingException {

@Override
public void bind(Name name, Object obj) throws NamingException {
dumpContext();
bind(name.toString(), obj);
}

@Override
public void bind(String name, Object obj) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("bind is read-only");
}
Expand All @@ -79,11 +87,13 @@ public void bind(String name, Object obj) throws NamingException {

@Override
public void rebind(Name name, Object obj) throws NamingException {
dumpContext();
rebind(name.toString(), obj);
}

@Override
public void rebind(String name, Object obj) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("rebind is read-only");
}
Expand All @@ -92,11 +102,13 @@ public void rebind(String name, Object obj) throws NamingException {

@Override
public void unbind(Name name) throws NamingException {
dumpContext();
unbind(name.toString());
}

@Override
public void unbind(String name) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("unbind is read-only");
}
Expand All @@ -108,11 +120,13 @@ public void unbind(String name) throws NamingException {

@Override
public void rename(Name oldName, Name newName) throws NamingException {
dumpContext();
rename(oldName.toString(), newName.toString());
}

@Override
public void rename(String oldName, String newName) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("rename is read-only");
}
Expand All @@ -125,11 +139,13 @@ public void rename(String oldName, String newName) throws NamingException {

@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
dumpContext();
return list(name.toString());
}

@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
dumpContext();
final Iterator<String> iterator = bindings.keySet().iterator();
return new NamingEnumeration<NameClassPair>() {
public NameClassPair next() {
Expand All @@ -156,11 +172,13 @@ public NameClassPair nextElement() {

@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
dumpContext();
return listBindings(name.toString());
}

@Override
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
dumpContext();
final Iterator<String> iterator = bindings.keySet().iterator();
return new NamingEnumeration<Binding>() {
public Binding next() {
Expand All @@ -187,11 +205,13 @@ public Binding nextElement() {

@Override
public void destroySubcontext(Name name) throws NamingException {
dumpContext();
destroySubcontext(name.toString());
}

@Override
public void destroySubcontext(String name) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("destroySubcontext is read-only");
}
Expand All @@ -207,11 +227,13 @@ public void destroySubcontext(String name) throws NamingException {

@Override
public Context createSubcontext(Name name) throws NamingException {
dumpContext();
return createSubcontext(name.toString());
}

@Override
public Context createSubcontext(String name) throws NamingException {
dumpContext();
if (readOnly) {
throw new OperationNotSupportedException("createSubcontext is read-only");
}
Expand All @@ -225,6 +247,7 @@ public Context createSubcontext(String name) throws NamingException {

@Override
public Object lookupLink(Name name) throws NamingException {
dumpContext();
return lookupLink(name.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ public void testReadOnlyBind() throws Exception {

@Test
public void testReadOnlyReBind() throws Exception {
HttpNamingClientMessages.MESSAGES.info("========= testReadOnlyRebind: start =========");
InitialContext ic = createContext();
try {
ic.rebind("name", "value");
Assert.fail("should fail");
} catch (Exception e) {
HttpNamingClientMessages.MESSAGES.info("result: got exception: " + e);
Assert.assertTrue(e instanceof NamingException);
Assert.assertEquals("rebind is read-only", e.getMessage());
} finally {
ic.close();
HttpNamingClientMessages.MESSAGES.info("========= testReadOnlyRebind: stop =========");
}
}

Expand Down
Loading