Skip to content

Commit

Permalink
W-17369306: Update Jetty/Wiremock to latest in the whole Uber
Browse files Browse the repository at this point in the history
  • Loading branch information
elrodro83 committed Jan 6, 2025
1 parent 1304aae commit 44e348c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import static java.util.Optional.ofNullable;

import static org.reflections.ReflectionUtils.getAllFields;
import static org.reflections.ReflectionUtils.withAnnotation;
import static org.reflections.ReflectionUtils.getAllMethods;
import static org.reflections.util.ReflectionUtilsPredicates.withAnnotation;

import org.mule.runtime.api.service.Service;
import org.mule.runtime.api.service.ServiceProvider;
import org.mule.runtime.module.service.api.discoverer.ServiceResolutionError;
import org.mule.runtime.module.service.api.manager.ServiceRegistry;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
Expand Down Expand Up @@ -82,6 +84,39 @@ public void inject(ServiceProvider serviceProvider) throws ServiceResolutionErro
e);
}
}
for (Method method : getAllMethods(serviceProvider.getClass(), withAnnotation(Inject.class))) {
if (method.getParameters().length == 1) {
try {
Class<?> dependencyType = method.getParameterTypes()[0];

boolean asOptional = false;
if (dependencyType.equals(Optional.class)) {
Type type = ((ParameterizedType) (method.getGenericParameterTypes()[0])).getActualTypeArguments()[0];
if (type instanceof ParameterizedType) {
dependencyType = (Class<?>) ((ParameterizedType) type).getRawType();
} else {
dependencyType = (Class<?>) type;
}
asOptional = true;
}

Object dependency = resolveObjectToInject(dependencyType, asOptional);
if (dependency != null) {
method.invoke(serviceProvider, dependency);
} else if (!asOptional) {
throw new ServiceResolutionError(format("Cannot find a service to inject into field '%s#%s' of service provider '%s'",
method.getDeclaringClass().getName(),
method.getName(),
serviceProvider.getServiceDefinition().getServiceClass().getName()));
}
} catch (Exception e) {
throw new RuntimeException(format("Could not inject dependency on method %s of type %s", method.getName(),
serviceProvider.getClass().getName()),
e);
}
}

}
}

private Object resolveObjectToInject(Class<?> dependencyType, boolean asOptional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/
package org.mule.functional.junit4.rules;

import static org.mule.functional.util.http.SimpleHttpServer.createServer;

import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
import static org.mule.functional.util.http.SimpleHttpServer.createServer;

import org.mule.functional.util.http.SimpleHttpServer;
import org.mule.tck.junit4.rule.FreePortFinder;
Expand All @@ -19,7 +20,10 @@
* JUnit rule to create an HTTP server
*
* @since 4.0
*
* @deprecated since 4.10 use WireMock instead
*/
@Deprecated
public class HttpServerRule extends ExternalResource {

private final String portSystemPropertyKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import org.mule.runtime.api.util.MultiMap;
import org.mule.runtime.core.api.util.IOUtils;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;

import jakarta.servlet.http.HttpServletRequest;

public class HttpMessage {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import java.io.IOException;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* Simple HTTP server implementation for testing purposes.
*
Expand Down

0 comments on commit 44e348c

Please sign in to comment.