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

dynamic httpconfiguration properties #176

Merged
merged 5 commits into from
Jan 30, 2024
Merged
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 @@ -20,8 +20,14 @@
import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* A {@link org.jboss.arquillian.container.spi.client.container.ContainerConfiguration} common base for the Jetty Embedded
Expand All @@ -40,6 +46,8 @@ public abstract class AbstractJettyEmbeddedConfiguration implements ContainerCon

private Map<String, String> inferredEncodings;

private Map<String, String> httpConfigurationProperties;

private int headerBufferSize = 0;

private File realmProperties;
Expand Down Expand Up @@ -196,7 +204,7 @@ public void setInferredEncodings(String inferredEncodings) {
for (int i = 0; i < splittedLines.length; i += 2) {
if (i + 1 >= splittedLines.length) {
throw new ConfigurationException(String.format(
"Mime Type definition should follow the format <extension> <type>[ <extension> <type>]*, for example js application/javascript but %s definition has been found.",
"InferredEncodings definition should follow the format <extension> <type>[ <extension> <type>]*, for example text/html iso-8859-1 but %s definition has been found.",
inferredEncodings));
}
this.inferredEncodings.put(splittedLines[i], splittedLines[i + 1]);
Expand Down Expand Up @@ -282,5 +290,26 @@ public boolean isH2cEnabled() {
public void setH2cEnabled(boolean h2cEnabled) {
this.h2cEnabled = h2cEnabled;
}

public Map<String, String> getHttpConfigurationProperties() {
return httpConfigurationProperties;
}

public void setHttpConfigurationProperties(String httpConfigurationProperties) {

Properties props = new Properties();
try (StringReader reader = new StringReader(httpConfigurationProperties)) {
try {
props.load(reader);
} catch (IOException e) {
// this should not happen
throw new RuntimeException(e);
}
}
this.httpConfigurationProperties = props.stringPropertyNames()
.stream()
.collect(Collectors.toMap(Function.identity(), props::getProperty));

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
package org.jboss.arquillian.container.jetty.embedded_10;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.DeploymentManager;
Expand All @@ -36,10 +40,10 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.webapp.WebAppContext;
import org.jboss.arquillian.container.jetty.EnvUtil;
import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
Expand Down Expand Up @@ -143,6 +147,20 @@ public void start() throws LifecycleException {
if(this.containerConfig.getResponseCookieCompliance()!=null) {
httpConfig.setResponseCookieCompliance(CookieCompliance.from(containerConfig.getResponseCookieCompliance()));
}

if(containerConfig.getHttpConfigurationProperties()!=null){
for(Map.Entry<String, String> propertyEntry:containerConfig.getHttpConfigurationProperties().entrySet()){
Method setter = ReflectionUtils.getSetter(propertyEntry.getKey(), httpConfig.getClass());
Class<?> setterClass = ReflectionUtils.getSetterType(setter);
Object value = TypeUtil.valueOf(setterClass, propertyEntry.getValue());
try {
setter.invoke(httpConfig, value);
} catch (IllegalAccessException | InvocationTargetException e) {
log.log(Level.WARNING, "Ignore error setting field with name " + propertyEntry.getKey() + " with value " + propertyEntry.getValue(), e);
}
}
}

}

ConnectionFactory connectionFactory = new HttpConnectionFactory(httpConfig);
Expand Down
5 changes: 4 additions & 1 deletion jetty-embedded-10/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
xsi:schemaLocation="http://jboss.org/schema/arquillian https://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<engine>
<!-- property name="deploymentExportPath">target/</property -->
Expand All @@ -15,6 +15,9 @@
js application/js
txt text/plain
</property>
<property name="httpConfigurationProperties">
relativeRedirectAllowed false
</property>
</configuration>
</container>
</arquillian>
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
package org.jboss.arquillian.container.jetty.embedded_11;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.DeploymentManager;
Expand All @@ -45,6 +49,7 @@
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;
import org.jboss.arquillian.container.jetty.EnvUtil;
Expand Down Expand Up @@ -312,6 +317,20 @@ private HttpConfiguration getHttpConfiguration() {
if(this.containerConfig.getResponseCookieCompliance()!=null) {
httpConfig.setResponseCookieCompliance(CookieCompliance.from(containerConfig.getResponseCookieCompliance()));
}

if(containerConfig.getHttpConfigurationProperties()!=null){
for(Map.Entry<String, String> propertyEntry:containerConfig.getHttpConfigurationProperties().entrySet()){
Method setter = ReflectionUtils.getSetter(propertyEntry.getKey(), httpConfig.getClass());
Class<?> setterClass = ReflectionUtils.getSetterType(setter);
Object value = TypeUtil.valueOf(setterClass, propertyEntry.getValue());
try {
setter.invoke(httpConfig, value);
} catch (IllegalAccessException | InvocationTargetException e) {
log.log(Level.WARNING, "Ignore error setting field with name " + propertyEntry.getKey() + " with value " + propertyEntry.getValue(), e);
}
}
}

}

SecureRequestCustomizer secureRequestCustomizer = httpConfig.getCustomizer(SecureRequestCustomizer.class);
Expand Down
5 changes: 4 additions & 1 deletion jetty-embedded-11/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
xsi:schemaLocation="http://jboss.org/schema/arquillian https://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<engine>
<!-- property name="deploymentExportPath">target/</property -->
Expand All @@ -19,6 +19,9 @@
text/html iso-8859-1
</property>
<property name="h2cEnabled">true</property>
<property name="httpConfigurationProperties">
relativeRedirectAllowed false
</property>
</configuration>
</container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum ClassLoaderBehavior
/**
* Classloader Search Order behavior.
* <p>
* Default for Arquillian is {@link JAVA_SPEC}.
* Default for Arquillian is {@link ClassLoaderBehavior#JAVA_SPEC}.
*/
private ClassLoaderBehavior classloaderBehavior = ClassLoaderBehavior.JAVA_SPEC;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
package org.jboss.arquillian.container.jetty.embedded_12_ee10;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.DeploymentManager;
Expand All @@ -42,6 +47,7 @@
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
Expand Down Expand Up @@ -304,6 +310,20 @@ private HttpConfiguration getHttpConfiguration() {
if(this.containerConfig.getResponseCookieCompliance()!=null) {
httpConfig.setResponseCookieCompliance(CookieCompliance.from(containerConfig.getResponseCookieCompliance()));
}

if(containerConfig.getHttpConfigurationProperties()!=null){
for(Map.Entry<String, String> propertyEntry:containerConfig.getHttpConfigurationProperties().entrySet()){
Method setter = ReflectionUtils.getSetter(propertyEntry.getKey(), httpConfig.getClass());
Class<?> setterClass = ReflectionUtils.getSetterType(setter);
Object value = TypeUtil.valueOf(setterClass, propertyEntry.getValue());
try {
setter.invoke(httpConfig, value);
} catch (IllegalAccessException | InvocationTargetException e) {
log.log(Level.WARNING, "Ignore error setting field with name " + propertyEntry.getKey() + " with value " + propertyEntry.getValue(), e);
}
}
}

}

SecureRequestCustomizer secureRequestCustomizer = httpConfig.getCustomizer(SecureRequestCustomizer.class);
Expand Down
3 changes: 3 additions & 0 deletions jetty-embedded-12-ee10/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</property>
<property name="h2cEnabled">true</property>
<!-- <property name="dumpServerAfterStart">true</property>-->
<property name="httpConfigurationProperties">
relativeRedirectAllowed false
</property>
</configuration>
</container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.jetty.ee9.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.ee9.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.ee9.webapp.FragmentConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
package org.jboss.arquillian.container.jetty.embedded_12_ee9;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.DeploymentManager;
Expand All @@ -41,6 +46,7 @@
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.ee9.servlet.ServletHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
Expand Down Expand Up @@ -303,6 +309,20 @@ private HttpConfiguration getHttpConfiguration() {
if(this.containerConfig.getResponseCookieCompliance()!=null) {
httpConfig.setResponseCookieCompliance(CookieCompliance.from(containerConfig.getResponseCookieCompliance()));
}

if(containerConfig.getHttpConfigurationProperties()!=null){
for(Map.Entry<String, String> propertyEntry:containerConfig.getHttpConfigurationProperties().entrySet()){
Method setter = ReflectionUtils.getSetter(propertyEntry.getKey(), httpConfig.getClass());
Class<?> setterClass = ReflectionUtils.getSetterType(setter);
Object value = TypeUtil.valueOf(setterClass, propertyEntry.getValue());
try {
setter.invoke(httpConfig, value);
} catch (IllegalAccessException | InvocationTargetException e) {
log.log(Level.WARNING, "Ignore error setting field with name " + propertyEntry.getKey() + " with value " + propertyEntry.getValue(), e);
}
}
}

}

SecureRequestCustomizer secureRequestCustomizer = httpConfig.getCustomizer(SecureRequestCustomizer.class);
Expand Down
6 changes: 5 additions & 1 deletion jetty-embedded-12-ee9/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
xsi:schemaLocation="http://jboss.org/schema/arquillian https://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<engine>
<!-- property name="deploymentExportPath">target/</property -->
Expand All @@ -20,7 +20,11 @@
</property>
<property name="h2cEnabled">true</property>
<!-- <property name="dumpServerAfterStart">true</property>-->
<property name="httpConfigurationProperties">
relativeRedirectAllowed false
</property>
</configuration>

</container>

<container qualifier="https">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
package org.jboss.arquillian.container.jetty.embedded_9;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
Expand All @@ -43,6 +47,7 @@
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.JavaUtilLog;
import org.eclipse.jetty.webapp.Configuration.ClassList;
import org.eclipse.jetty.webapp.FragmentConfiguration;
Expand Down Expand Up @@ -177,6 +182,18 @@ public void start() throws LifecycleException {
if(this.containerConfig.getResponseCookieCompliance()!=null) {
httpConfig.setResponseCookieCompliance(CookieCompliance.valueOf(containerConfig.getResponseCookieCompliance()));
}
if(containerConfig.getHttpConfigurationProperties()!=null){
for(Map.Entry<String, String> propertyEntry:containerConfig.getHttpConfigurationProperties().entrySet()){
Method setter = ReflectionUtils.getSetter(propertyEntry.getKey(), httpConfig.getClass());
Class<?> setterClass = ReflectionUtils.getSetterType(setter);
Object value = TypeUtil.valueOf(setterClass, propertyEntry.getValue());
try {
setter.invoke(httpConfig, value);
} catch (IllegalAccessException | InvocationTargetException e) {
log.log(Level.WARNING, "Ignore error setting field with name " + propertyEntry.getKey() + " with value " + propertyEntry.getValue(), e);
}
}
}
}

ConnectionFactory connectionFactory = new HttpConnectionFactory(httpConfig);
Expand Down
3 changes: 3 additions & 0 deletions jetty-embedded-9/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
js application/js
txt text/plain
</property>
<property name="httpConfigurationProperties">
relativeRedirectAllowed false
</property>
</configuration>
</container>
</arquillian>