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

[WEJBHTTP-139] Final round of cleanup refactorings accross all modules #259

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9d631d7
[WEJBHTTP-139] Refactoring - moving static imports to the top of impo…
ropalka Nov 29, 2024
682a83f
[WEJBHTTP-139] Refactoring - moving ByteOutputs classes to common module
ropalka Nov 29, 2024
a8be101
[WEJBHTTP-139] Refactoring - making all ByteOutputs wrapping OutputSt…
ropalka Nov 29, 2024
3bfbb00
[WEJBHTTP-139] Refactoring - unify OutputStream variable names
ropalka Nov 29, 2024
357e420
[WEJBHTTP-139] Removing remaining deprecated methods & constructors
ropalka Nov 29, 2024
1dde42a
[WEJBHTTP-139] Refactoring - use HttpServerHelper utility method via …
ropalka Nov 29, 2024
85b5810
[WEJBHTTP-139] Refactoring - merge transaction/Utils , naming/Utils &…
ropalka Dec 5, 2024
c4208da
[WEJBHTTP-139] Refactoring - merge common/Utils & common/HttpMarshall…
ropalka Dec 5, 2024
d2c8137
[WEJBHTTP-139] Refactoring - unify parameter names in Serializers
ropalka Dec 6, 2024
11abf95
[WEJBHTTP-139] Refactoring - unify parameter names in ClientHandlers
ropalka Dec 6, 2024
424ce0e
[WEJBHTTP-139] Refactoring - Introducing ByteInputs utility class
ropalka Dec 6, 2024
4509263
[WEJBHTTP-139] Refactoring - renaming httpServiceConfig variable to c…
ropalka Dec 6, 2024
1585469
[WEJBHTTP-139] Removing unused HttpRemoteEjbService.cancellationFlags…
ropalka Dec 6, 2024
c526cb3
[WEJBHTTP-139] Refactoring - reordering method parameters - let HttpS…
ropalka Dec 6, 2024
f47e24c
[WEJBHTTP-139] Refactoring - be consistent and always use HeaderMap.p…
ropalka Dec 10, 2024
9b3515d
[WEJBHTTP-139] Refactoring - Use Headers fields via static imports
ropalka Dec 10, 2024
b1f577d
[WEJBHTTP-139] Refactoring - Use StatusCodes fields via static imports
ropalka Dec 10, 2024
35e8968
[WEJBHTTP-139] Refactoring - always use HeadersHelper methods for bet…
ropalka Dec 10, 2024
3a7d2b8
[WEJBHTTP-139] Refactoring - Enhance HeadersHelper methods to enhance…
ropalka Dec 10, 2024
50ba294
[WEJBHTTP-139] Refactoring - use parseBoolean via static import
ropalka Dec 10, 2024
928e111
[WEJBHTTP-139] Refactoring - introducing OPC query parameter constant
ropalka Dec 10, 2024
0d91d27
[WEJBHTTP-139] Refactoring - use NEW_QUERY_PARAMETER constant
ropalka Dec 10, 2024
1b4f665
[WEJBHTTP-139] Refactoring - unify ClientRequest variable names
ropalka Dec 10, 2024
b1e7ff3
[WEJBHTTP-139] Refactoring - unify ClientResponse variable names
ropalka Dec 10, 2024
bd13773
[WEJBHTTP-139] Refactoring - use EJB_SESSION_ID via static import
ropalka Dec 10, 2024
43d0acd
[WEJBHTTP-139] Enhancement according to peer review - always throw Il…
ropalka Jan 16, 2025
32c4a0e
[WEJBHTTP-139] Enhancement according to peer review - use 'input' and…
ropalka Jan 16, 2025
b79131a
[WEJBHTTP-139] Enhancement according to peer review - don't use Objec…
ropalka Jan 16, 2025
41b44a2
[WEJBHTTP-139] Enhancement according to peer review - use txnInfo ins…
ropalka Jan 16, 2025
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
80 changes: 40 additions & 40 deletions ejb/src/main/java/org/wildfly/httpclient/ejb/ClientHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ private ClientHandlers() {
// forbidden instantiation
}

static HttpTargetContext.HttpMarshaller invokeHttpMarshaller(final Marshaller marshaller, final TransactionInfo txnInfo, final Object[] parameters, final Map<String, Object> contextData) {
return new InvokeHttpMarshaller(marshaller, txnInfo, parameters, contextData);
static HttpTargetContext.HttpMarshaller invokeHttpMarshaller(final Marshaller marshaller, final TransactionInfo txn, final Object[] objects, final Map<String, Object> map) {
ropalka marked this conversation as resolved.
Show resolved Hide resolved
return new InvokeHttpMarshaller(marshaller, txn, objects, map);
}

static HttpTargetContext.HttpMarshaller createSessionHttpMarshaller(final Marshaller marshaller, final TransactionInfo txnInfo) {
return new CreateSessionHttpMarshaller(marshaller, txnInfo);
static HttpTargetContext.HttpMarshaller createSessionHttpMarshaller(final Marshaller marshaller, final TransactionInfo txn) {
return new CreateSessionHttpMarshaller(marshaller, txn);
}

static <T> HttpTargetContext.HttpResultHandler emptyHttpResultHandler(final CompletableFuture<T> result, final Function<ClientResponse, T> function) {
Expand All @@ -76,8 +76,8 @@ static HttpTargetContext.HttpResultHandler discoveryHttpResultHandler(final Unma
return new DiscoveryHttpResultHandler(unmarshaller, result);
}

static HttpTargetContext.HttpResultHandler invokeHttpResultHandler(final Unmarshaller unmarshaller, final EJBReceiverInvocationContext receiverContext, final EJBClientInvocationContext clientInvocationContext) {
return new EjbClassLoaderAwareHttpResultHandler(unmarshaller, receiverContext, clientInvocationContext);
static HttpTargetContext.HttpResultHandler invokeHttpResultHandler(final Unmarshaller unmarshaller, final EJBReceiverInvocationContext receiverCtx, final EJBClientInvocationContext clientCtx) {
return new EjbClassLoaderAwareHttpResultHandler(unmarshaller, receiverCtx, clientCtx);
}

static Function<ClientResponse, Boolean> cancelInvocationResponseFunction() {
Expand All @@ -94,43 +94,43 @@ private static HttpTargetContext.HttpResultHandler invokeHttpResultHandlerIntern

private static final class InvokeHttpMarshaller implements HttpTargetContext.HttpMarshaller {
private final Marshaller marshaller;
private final TransactionInfo txnInfo;
private final Object[] parameters;
private final Map<String, Object> contextData;
private final TransactionInfo txn;
private final Object[] objects;
private final Map<String, Object> map;

private InvokeHttpMarshaller(final Marshaller marshaller, final TransactionInfo txnInfo, final Object[] parameters, final Map<String, Object> contextData) {
private InvokeHttpMarshaller(final Marshaller marshaller, final TransactionInfo txn, final Object[] objects, final Map<String, Object> map) {
this.marshaller = marshaller;
this.txnInfo = txnInfo;
this.parameters = parameters;
this.contextData = contextData;
this.txn = txn;
this.objects = objects;
this.map = map;
}

@Override
public void marshall(final OutputStream os) throws Exception {
try (ByteOutput out = byteOutputOf(os)) {
marshaller.start(out);
serializeTransaction(marshaller, txnInfo);
serializeObjectArray(marshaller, parameters);
serializeMap(marshaller, contextData);
serializeTransaction(marshaller, txn);
serializeObjectArray(marshaller, objects);
serializeMap(marshaller, map);
marshaller.finish();
}
}
}

private static final class CreateSessionHttpMarshaller implements HttpTargetContext.HttpMarshaller {
private final Marshaller marshaller;
private final TransactionInfo txnInfo;
private final TransactionInfo txn;

private CreateSessionHttpMarshaller(final Marshaller marshaller, final TransactionInfo txnInfo) {
private CreateSessionHttpMarshaller(final Marshaller marshaller, final TransactionInfo txn) {
this.marshaller = marshaller;
this.txnInfo = txnInfo;
this.txn = txn;
}

@Override
public void marshall(final OutputStream os) throws Exception {
try (ByteOutput out = byteOutputOf(os)) {
marshaller.start(out);
serializeTransaction(marshaller, txnInfo);
serializeTransaction(marshaller, txn);
marshaller.finish();
}
}
Expand All @@ -146,7 +146,7 @@ private EmptyHttpResultHandler(final CompletableFuture<T> result, final Function
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try {
result.complete(function != null ? function.apply(httpResponse) : null);
} finally {
Expand All @@ -156,17 +156,17 @@ public void handleResult(final InputStream httpBodyResponseStream, final ClientR
}

private static final class DiscoveryHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<Set<EJBModuleIdentifier>> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<Set<EJBModuleIdentifier>> result;

private DiscoveryHttpResultHandler(final Unmarshaller unmarshaller, final CompletableFuture<Set<EJBModuleIdentifier>> result) {
this.unmarshaller = unmarshaller;
this.result = result;
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(httpBodyResponseStream)) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(is)) {
Set<EJBModuleIdentifier> modules;
unmarshaller.start(in);
modules = deserializeSet(unmarshaller);
Expand All @@ -188,36 +188,36 @@ private static final class EjbClassLoaderAwareHttpResultHandler implements HttpT
WELL_KNOWN_KEYS.add("jboss.source.address");
}

private final EJBReceiverInvocationContext receiverContext;
private final EJBClientInvocationContext clientInvocationContext;
private final Unmarshaller unmarshaller;
private final EJBReceiverInvocationContext receiverCtx;
private final EJBClientInvocationContext clientCtx;

private EjbClassLoaderAwareHttpResultHandler(final Unmarshaller unmarshaller, final EJBReceiverInvocationContext receiverContext, final EJBClientInvocationContext clientInvocationContext) {
private EjbClassLoaderAwareHttpResultHandler(final Unmarshaller unmarshaller, final EJBReceiverInvocationContext receiverCtx, final EJBClientInvocationContext clientCtx) {
this.unmarshaller = unmarshaller;
this.receiverContext = receiverContext;
this.clientInvocationContext = clientInvocationContext;
this.receiverCtx = receiverCtx;
this.clientCtx = clientCtx;
}

public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
receiverContext.resultReady(new EJBReceiverInvocationContext.ResultProducer() {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
receiverCtx.resultReady(new EJBReceiverInvocationContext.ResultProducer() {
@Override
public Object getResult() throws Exception {
final CompletableFuture<InvocationInfo> result = new CompletableFuture<>();
invokeHttpResultHandlerInternal(unmarshaller, result).handleResult(httpBodyResponseStream, httpResponse, doneCallback);
invokeHttpResultHandlerInternal(unmarshaller, result).handleResult(is, httpResponse, doneCallback);

// WEJBHTTP-83 - remove jboss.returned.keys values from the local context data, so that after unmarshalling the response, we have the correct ContextData
Set<String> returnedContextDataKeys = (Set<String>) clientInvocationContext.getContextData().get(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY);
Set<String> returnedContextDataKeys = (Set<String>) clientCtx.getContextData().get(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY);
if(returnedContextDataKeys != null) {
clientInvocationContext.getContextData().keySet().removeIf(k -> (!k.equals(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY)));
clientCtx.getContextData().keySet().removeIf(k -> (!k.equals(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY)));
}
Set<String> returnedKeys = (Set<String>) clientInvocationContext.getContextData().get(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY);
Set<String> returnedKeys = (Set<String>) clientCtx.getContextData().get(EJBClientInvocationContext.RETURNED_CONTEXT_DATA_KEY);

// If there are any attachments, add them to the client invocation's context data
if (result.get().getAttachments() != null) {
for (Map.Entry<String, Object> entry : result.get().getAttachments().entrySet()) {
if (entry.getValue() != null &&
((returnedKeys != null && returnedKeys.contains(entry.getKey())) || WELL_KNOWN_KEYS.contains(entry.getKey()))) {
clientInvocationContext.getContextData().put(entry.getKey(), entry.getValue());
clientCtx.getContextData().put(entry.getKey(), entry.getValue());
}
}
}
Expand All @@ -227,25 +227,25 @@ public Object getResult() throws Exception {
@Override
public void discardResult() {
IoUtils.safeClose(doneCallback);
IoUtils.safeClose(httpBodyResponseStream);
IoUtils.safeClose(is);
}
});

}
}

private static final class InvokeHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<InvocationInfo> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<InvocationInfo> result;

private InvokeHttpResultHandler(final Unmarshaller unmarshaller, final CompletableFuture<InvocationInfo> result) {
this.unmarshaller = unmarshaller;
this.result = result;
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(httpBodyResponseStream)) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(is)) {
unmarshaller.start(in);
final Object returned = deserializeObject(unmarshaller);
final Map<String, Object> attachments = deserializeMap(unmarshaller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private EmptyHttpResultHandler(final CompletableFuture<T> result, final Function
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try {
result.complete(function != null ? function.apply(httpResponse) : null);
} finally {
Expand All @@ -105,8 +105,8 @@ public void handleResult(final InputStream httpBodyResponseStream, final ClientR
}

private static final class OptionalObjectHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<Object> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<Object> result;
private final NamingProvider namingProvider;
private final ClassLoader classLoader;

Expand All @@ -118,15 +118,15 @@ private OptionalObjectHttpResultHandler(final Unmarshaller unmarshaller, final C
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try {
namingProvider.performExceptionAction((a, b) -> {
ClassLoader old = setContextClassLoader(classLoader);
try {
if (httpResponse.getResponseCode() == StatusCodes.NO_CONTENT) {
emptyHttpResultHandler(result, null).handleResult(httpBodyResponseStream, httpResponse, doneCallback);
emptyHttpResultHandler(result, null).handleResult(is, httpResponse, doneCallback);
} else {
objectHttpResultHandler(unmarshaller, result).handleResult(httpBodyResponseStream, httpResponse, doneCallback);
objectHttpResultHandler(unmarshaller, result).handleResult(is, httpResponse, doneCallback);
}
} finally {
setContextClassLoader(old);
Expand All @@ -140,17 +140,17 @@ public void handleResult(final InputStream httpBodyResponseStream, final ClientR
}

private static final class ObjectHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<Object> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<Object> result;

private ObjectHttpResultHandler(final Unmarshaller unmarshaller, final CompletableFuture<Object> result) {
this.unmarshaller = unmarshaller;
this.result = result;
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(httpBodyResponseStream)) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(is)) {
unmarshaller.start(in);
Object object = deserializeObject(unmarshaller);
unmarshaller.finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private EmptyHttpResultHandler(final CompletableFuture<T> result, final Function
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try {
result.complete(function != null ? function.apply(httpResponse) : null);
} finally {
Expand All @@ -104,17 +104,17 @@ public void handleResult(final InputStream httpBodyResponseStream, final ClientR
}

private static final class XidHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<Xid> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<Xid> result;

private XidHttpResultHandler(final Unmarshaller unmarshaller, final CompletableFuture<Xid> result) {
this.unmarshaller = unmarshaller;
this.result = result;
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(httpBodyResponseStream)) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(is)) {
unmarshaller.start(in);
Xid xid = deserializeXid(unmarshaller);
unmarshaller.finish();
Expand All @@ -128,17 +128,17 @@ public void handleResult(final InputStream httpBodyResponseStream, final ClientR
}

private static final class XidArrayHttpResultHandler implements HttpTargetContext.HttpResultHandler {
private final CompletableFuture<Xid[]> result;
private final Unmarshaller unmarshaller;
private final CompletableFuture<Xid[]> result;

private XidArrayHttpResultHandler(final Unmarshaller unmarshaller, final CompletableFuture<Xid[]> result) {
this.unmarshaller = unmarshaller;
this.result = result;
}

@Override
public void handleResult(final InputStream httpBodyResponseStream, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(httpBodyResponseStream)) {
public void handleResult(final InputStream is, final ClientResponse httpResponse, final Closeable doneCallback) {
try (ByteInput in = new InputStreamByteInput(is)) {
unmarshaller.start(in);
Xid[] ret = deserializeXidArray(unmarshaller);
unmarshaller.finish();
Expand Down