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

Resteasy 3078 has property #3029

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,15 @@

import static org.junit.Assert.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class Mime4JWorkaroundTest {

private static final Map<String, String> preTestProperties = new HashMap<>();

@BeforeClass
public static void saveCurrentStateOfMemThresholdProperty()
{
if (System.getProperties().containsKey(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY))
{
String value = System.getProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY);
preTestProperties.put(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, value);
}
}

@AfterClass
public static void resetPropertiesToPreTestValues()
{
if (!preTestProperties.containsKey(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY))
{
System.clearProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY);
}
else
{
preTestProperties.forEach(System::setProperty);
}
}

@Before
public void unsetMemThresholdProperty()
{
public void unsetMemThresholdProperty() {
System.clearProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY);
}

@Test
public void testMemThresholdDefault()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.jboss.resteasy.microprofile.client.headers;

import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.hamcrest.CoreMatchers;
import org.jboss.resteasy.annotations.jaxrs.HeaderParam;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.hamcrest.MatcherAssert;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ClientHeaderFillingTest {
private static final String HEADER_NAME = "GENERATED_HEADER";

private static UndertowJaxrsServer server;
private static WeldContainer container;

@BeforeClass
public static void init() {
Weld weld = new Weld();
weld.addBeanClass(HeaderPassingResource.class);
weld.addBeanClass(HeaderSendingClient.class);
weld.addBeanClass(ClientInvokingBean.class);
container = weld.initialize();
server = new UndertowJaxrsServer().start();
server.deploy(MyApp.class);
}

@Test
public void checkIfFillerFactoryWithHigherPrioritySelected() {
List<String> result = container.select(ClientInvokingBean.class).get().getHeaders();
MatcherAssert.assertThat(result, CoreMatchers.hasItems("high", "prio"));
}

@AfterClass
public static void stop() {
server.stop();
container.shutdown();
}

@Path("/")
@RegisterRestClient(baseUri="http://localhost:8081")
public interface HeaderSendingClient {
@GET
@ClientHeaderParam(name = HEADER_NAME, value = "{someMethod}")
String headerValues();

default List<String> someMethod() {
return Arrays.asList("foo", "bar");
}
}

@Path("/")
public static class HeaderPassingResource {
@GET
public String headerValues(@HeaderParam(HEADER_NAME) List<String> headers) {
return String.join(",", headers);
}
}

@ApplicationScoped
public static class ClientInvokingBean {
@RestClient
@Inject
private HeaderSendingClient client;

public List<String> getHeaders() {
String headers = client.headerValues();
return Arrays.asList(headers.split(","));
}
}

@ApplicationPath("")
public static class MyApp extends Application {

@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> classes = new HashSet<>();
classes.add(HeaderPassingResource.class);
return classes;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ private CompletableFuture<ClientResponse> submit(final ClientInvocation request)

options.setURI(uri.getRawPath());


Object timeout = request.getConfiguration().getProperty(REQUEST_TIMEOUT_MS);
if (timeout != null) {
long timeoutMs = unwrapTimeout(timeout);
if (request.getConfiguration().hasProperty(REQUEST_TIMEOUT_MS)) {
long timeoutMs = unwrapTimeout(
request.getConfiguration().getProperty(REQUEST_TIMEOUT_MS));
if (timeoutMs > 0) {
options.setTimeout(timeoutMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private Response cachedResponse(BrowserCache.Entry entry)
@Override
public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException
{
if (!request.getMethod().equalsIgnoreCase("GET") || request.getProperty("cached") != null) return;
if (!request.getMethod().equalsIgnoreCase("GET") || request.hasProperty("cached")) return;
else if (response.getStatus() == 304)
{
BrowserCache.Entry entry = (BrowserCache.Entry)request.getProperty("expired.cache.entry");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,19 @@ public ResteasyClient build()
*/
private void setProxyIfNeeded(ClientConfiguration clientConfig) {
try {
Object proxyHostProp = clientConfig.getProperty(ResteasyClientBuilder.PROPERTY_PROXY_HOST);
if (proxyHostProp != null) {
Object proxyPortProp = clientConfig.getProperty(ResteasyClientBuilder.PROPERTY_PROXY_PORT);
// default if the port is not set or if it is not string or number
if (clientConfig.hasProperty(ResteasyClientBuilder.PROPERTY_PROXY_HOST)) {
Object proxyHostProp = clientConfig.getProperty(ResteasyClientBuilder.PROPERTY_PROXY_HOST);
Integer proxyPort = -1;
if (proxyPortProp != null && proxyPortProp instanceof Number) {
proxyPort = ((Number) proxyPortProp).intValue();
} else if (proxyPortProp != null && proxyPortProp instanceof String) {
proxyPort = Integer.parseInt((String) proxyPortProp);
if (clientConfig.hasProperty(ResteasyClientBuilder.PROPERTY_PROXY_PORT)) {
// default if the port is not set or if it is not string or number
Object proxyPortProp = clientConfig.getProperty(ResteasyClientBuilder.PROPERTY_PROXY_PORT);
if (proxyPortProp instanceof Number) {
proxyPort = ((Number) proxyPortProp).intValue();
} else if (proxyPortProp instanceof String) {
proxyPort = Integer.parseInt((String) proxyPortProp);
}
}

Object proxySchemeProp = clientConfig.getProperty(ResteasyClientBuilder.PROPERTY_PROXY_SCHEME);
defaultProxy((String)proxyHostProp, proxyPort, (String)proxySchemeProp);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
package org.jboss.resteasy.client.jaxrs.engines;

import static org.junit.Assert.assertEquals;
import static org.jboss.resteasy.client.jaxrs.engines.ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY;

import java.util.HashMap;
import java.util.Map;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ManualClosingApacheHttpClient43EngineTest {

private static final Map<String, String> preTestProperties = new HashMap<>();

@BeforeClass
public static void saveCurrentStateOfMemThresholdProperty()
{
if (System.getProperties().containsKey(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY))
{
String value = System.getProperty(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY);
preTestProperties.put(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, value);
}
}

@AfterClass
public static void resetPropertiesToPreTestValues()
{
if (!preTestProperties.containsKey(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY))
{
System.clearProperty(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY);
}
else
{
preTestProperties.forEach(System::setProperty);
}
}

@Before
public void unsetMemThresholdProperty()
{
public void unsetMemThresholdProperty() {
System.clearProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY);
}
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class DigitalVerificationInterceptor implements ReaderInterceptor
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException
{
LogMessages.LOGGER.debugf("Interceptor : %s, Method : aroundReadFrom", getClass().getName());
Verifier verifier = (Verifier) context.getProperty(Verifier.class.getName());
if (verifier == null)
if (!context.hasProperty(Verifier.class.getName()))
{
return context.proceed();
}
Expand Down Expand Up @@ -64,6 +63,7 @@ public Object aroundReadFrom(ReaderInterceptorContext context) throws IOExceptio
context.setInputStream(stream);
Object rtn = context.proceed();
byte[] body = stream.toByteArray();
Verifier verifier = (Verifier) context.getProperty(Verifier.class.getName());

if (verifier.getRepository() == null)
{
Expand Down