-
Notifications
You must be signed in to change notification settings - Fork 98
Jersey server configuration properties are ignored #88
Comments
Hi, This would allow you to register it as an service e.g. MyJerseyConfiguration and add the properties the way you like it e.g. ConfigAdmin, SysProperties etc. This interface can look like this: public interface ApplicationConfiguration {
void configure( Application application );
} What do you think? |
Btw. this would also clean up the current wadl etc. handling because they could be registered in a DefaultConfiguration instead of the current pass-through mess. |
Pretty much similar to ServletConfiguration? Sounds good. I am guessing you are going to keep the two properties 'root' and 'publishDelay', right? I took the liberty and created a patch for that. Tell me if it's ok and I will create a pull request. diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java
new file mode 100644
index 0000000..81fdd1d
--- /dev/null
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java
@@ -0,0 +1,8 @@
+package com.eclipsesource.jaxrs.publisher;
+
+import javax.ws.rs.core.Application;
+
+public interface ApplicationConfiguration {
+
+ void configure(Application application);
+}
diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Activator.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Activator.java
index c0e10ef..40e1bff 100644
--- a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Activator.java
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Activator.java
@@ -39,6 +39,7 @@ public class Activator implements BundleActivator {
private ResourceTracker allTracker;
private ServletConfigurationTracker servletConfigurationTracker;
private ServiceRegistration configRegistration;
+ private ApplicationConfigurationTracker applicationConfigurationTracker;
@Override
public void start( BundleContext context ) throws Exception {
@@ -51,6 +52,7 @@ public class Activator implements BundleActivator {
openHttpServiceTracker( context );
openServletConfigurationTracker( context );
openAllServiceTracker( context );
+ openApplicationConfigurationTracker( context );
}
private void registerConfiguration( BundleContext context ) {
@@ -83,6 +85,11 @@ public class Activator implements BundleActivator {
allTracker = new ResourceTracker( context, allResourceFilter.getFilter(), jaxRsConnector );
allTracker.open();
}
+
+ private void openApplicationConfigurationTracker( BundleContext context ) {
+ applicationConfigurationTracker = new ApplicationConfigurationTracker( context, jaxRsConnector );
+ applicationConfigurationTracker.open();
+ }
private ResourceFilter getResourceFilter( BundleContext context ) {
ServiceReference filterReference = context.getServiceReference( ResourceFilter.class.getName() );
@@ -97,6 +104,7 @@ public class Activator implements BundleActivator {
httpTracker.close();
servletConfigurationTracker.close();
allTracker.close();
+ applicationConfigurationTracker.close();
connectorRegistration.unregister();
configRegistration.unregister();
}
diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java
new file mode 100644
index 0000000..8f156d8
--- /dev/null
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java
@@ -0,0 +1,32 @@
+
+package com.eclipsesource.jaxrs.publisher.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import com.eclipsesource.jaxrs.publisher.ApplicationConfiguration;
+
+public class ApplicationConfigurationTracker extends ServiceTracker {
+
+ private JAXRSConnector connector;
+ private final BundleContext context;
+
+ public ApplicationConfigurationTracker(BundleContext context, JAXRSConnector connector) {
+ super(context, ApplicationConfiguration.class.getName(), null);
+ this.context = context;
+ this.connector = connector;
+ }
+
+ @Override
+ public Object addingService( ServiceReference reference ) {
+ return connector.setApplicationConfiguration(reference);
+ }
+
+ @Override
+ public void removedService( ServiceReference reference, Object service ) {
+ if( service instanceof ApplicationConfiguration ) {
+ connector.unsetApplicationConfiguration(reference, ( ApplicationConfiguration ) service);
+ }
+ }
+}
diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Configuration.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Configuration.java
index d1c119b..4cc7522 100644
--- a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Configuration.java
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/Configuration.java
@@ -22,7 +22,6 @@ public class Configuration implements ManagedService {
static final String CONFIG_SERVICE_PID = "com.eclipsesource.jaxrs.connector";
static final String PROPERTY_ROOT = "root";
- static final String PROPERTY_WADL_DISABLE = "disableWadl";
static final String PROPERTY_PUBLISH_DELAY = "publishDelay";
static final long DEFAULT_PUBLISH_DELAY = 150;
@@ -39,7 +38,7 @@ public class Configuration implements ManagedService {
ensureRootIsPresent( root );
String rootPath = ( String )root;
ensureRootIsValid( rootPath );
- connector.updateConfiguration( rootPath, getPublishDelay( properties ), properties );
+ connector.updateConfiguration( rootPath, getPublishDelay( properties ) );
}
}
diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java
index 24bf39d..9df8e17 100644
--- a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java
@@ -19,6 +19,7 @@ import java.util.Map;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
+import com.eclipsesource.jaxrs.publisher.ApplicationConfiguration;
import com.eclipsesource.jaxrs.publisher.ServletConfiguration;
import com.eclipsesource.jaxrs.publisher.internal.ServiceContainer.ServiceHolder;
@@ -36,9 +37,9 @@ public class JAXRSConnector {
private final BundleContext bundleContext;
private final List<ServiceHolder> resourceCache;
private ServletConfiguration servletConfiguration;
+ private ApplicationConfiguration applicationConfiguration;
private String rootPath;
private long publishDelay;
- private Dictionary jerseyServerProperties;
JAXRSConnector( BundleContext bundleContext ) {
this.bundleContext = bundleContext;
@@ -49,15 +50,14 @@ public class JAXRSConnector {
this.publishDelay = Configuration.DEFAULT_PUBLISH_DELAY;
}
- void updateConfiguration( String rootPath, long publishDelay, Dictionary jerseyServerProperties ) {
+ void updateConfiguration( String rootPath, long publishDelay ) {
synchronized( lock ) {
- doUpdateConfiguration( rootPath, publishDelay, jerseyServerProperties );
+ doUpdateConfiguration( rootPath, publishDelay );
}
}
- private void doUpdateConfiguration( String rootPath, long publishDelay, Dictionary jerseyServerProperties ) {
+ private void doUpdateConfiguration( String rootPath, long publishDelay ) {
this.rootPath = rootPath;
- this.jerseyServerProperties = jerseyServerProperties;
this.publishDelay = publishDelay;
doUpdateHttpServices();
}
@@ -97,7 +97,7 @@ public class JAXRSConnector {
ServiceHolder serviceHolder = httpServices.add( reference );
HttpService service = ( HttpService )serviceHolder.getService();
contextMap.put( service,
- createJerseyContext( service, rootPath, jerseyServerProperties, publishDelay, servletConfiguration ) );
+ createJerseyContext( service, rootPath, publishDelay, applicationConfiguration, servletConfiguration ) );
clearCache();
return service;
}
@@ -209,10 +209,26 @@ public class JAXRSConnector {
// For testing purpose
JerseyContext createJerseyContext( HttpService service,
String rootPath,
- Dictionary jerseyServerProperties,
long publishDelay,
+ ApplicationConfiguration applicationConfiguration,
ServletConfiguration servletConfiguration )
{
- return new JerseyContext( service, rootPath, jerseyServerProperties, publishDelay, servletConfiguration );
+ return new JerseyContext( service, rootPath, publishDelay, applicationConfiguration, servletConfiguration );
}
+
+ ApplicationConfiguration setApplicationConfiguration(ServiceReference reference) {
+ if (applicationConfiguration == null ) {
+ applicationConfiguration = (ApplicationConfiguration) bundleContext.getService(reference);
+ return applicationConfiguration;
+ }
+ return null;
+ }
+
+ void unsetApplicationConfiguration(ServiceReference reference, ApplicationConfiguration service) {
+ if( applicationConfiguration == service ) {
+ applicationConfiguration = null;
+ bundleContext.ungetService( reference );
+ doUpdateHttpServices();
+ }
+ }
}
diff --git a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java
index 582a1c2..4c85f05 100644
--- a/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java
+++ b/com.eclipsesource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java
@@ -23,6 +23,7 @@ import org.glassfish.jersey.server.ServerProperties;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
+import com.eclipsesource.jaxrs.publisher.ApplicationConfiguration;
import com.eclipsesource.jaxrs.publisher.ServletConfiguration;
@@ -34,27 +35,24 @@ public class JerseyContext {
private final String rootPath;
private final ServletContainerBridge servletContainerBridge;
private final ServletConfiguration servletConfigurationService;
+ private final ApplicationConfiguration applicationConfiguration;
private final ResourcePublisher resourcePublisher;
private boolean isApplicationRegistered;
- private final Dictionary jerseyServerProperties;
- public JerseyContext( HttpService httpService, String rootPath, Dictionary jerseyServerProperties, long publishDelay ) {
- this( httpService, rootPath, jerseyServerProperties, publishDelay, null );
+ public JerseyContext( HttpService httpService, String rootPath, long publishDelay ) {
+ this( httpService, rootPath, publishDelay, null, null );
}
public JerseyContext( HttpService httpService,
String rootPath,
- Dictionary jerseyServerProperties,
long publishDelay,
+ ApplicationConfiguration applicationConfiguration,
ServletConfiguration servletConfigurationService )
{
this.httpService = httpService;
- this.jerseyServerProperties = jerseyServerProperties;
+ this.applicationConfiguration = applicationConfiguration;
this.rootPath = rootPath == null ? "/services" : rootPath;
this.application = new RootApplication();
- applyJerseyConfiguration();
- disableAutoDiscovery();
- disableWadl();
this.servletContainerBridge = new ServletContainerBridge( application );
this.servletConfigurationService = servletConfigurationService;
this.resourcePublisher = new ResourcePublisher( servletContainerBridge, publishDelay );
@@ -67,43 +65,6 @@ public class JerseyContext {
this.application.addProperty(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true );
}
- /**
- * WADL generation is enabled in Jersey by default. This means that OPTIONS methods are added by
- * default to each resource and an auto-generated /application.wadl resource is deployed too. In
- * case you want to disable that you can set this property to true.
- *
- * @deprecated The 'disableWadl' property can be directly injected to Jersey's configuration
- * via the 'jerseyProperties' dictionary, hence this could be marked as deprecated and can be removed.
- */
- private void disableWadl() {
- final boolean disableWadl;
- {
- Object o = jerseyServerProperties.get(ServerProperties.WADL_FEATURE_DISABLE);
- if (o == null) {
- disableWadl = false;
- } else {
- disableWadl = Boolean.parseBoolean((String) o);
- }
- }
- this.application.addProperty( ServerProperties.WADL_FEATURE_DISABLE, disableWadl );
- }
-
- /**
- * Apply the jersey configuration. The Server configuration properties that are supported can be
- * found in {@link org.glassfish.jersey.server.ServerProperties}
- */
- private void applyJerseyConfiguration() {
- Enumeration enumeration = jerseyServerProperties.keys();
- while(enumeration.hasMoreElements()) {
- String key = (String) enumeration.nextElement();
-
- if (key.startsWith("jersey.config") || key.startsWith("javax.ws.rs")) {
- Object value = jerseyServerProperties.get(key);
- this.application.addProperty(key, value);
- }
- }
- }
-
public void addResource( Object resource ) {
getRootApplication().addResource( resource );
registerServletWhenNotAlreadyRegistered();
@@ -113,6 +74,7 @@ public class JerseyContext {
void registerServletWhenNotAlreadyRegistered() {
if( !isApplicationRegistered ) {
isApplicationRegistered = true;
+ applicationConfiguration.configure(application);
registerApplication();
}
} |
Hi, thanks for your work but I also started yesterday implementing it ;). I took the chance and refactor the Configuration class to get rid of all the property references. Will have a version ready this evening I guess. When I'm publishing a RC p2 repo can you test it? |
Hehe, no problem Sure |
@isole I will provide an RC tomorrow morning in a separate issue and link it here. Will also update the included jersey version before. |
We are going to use the connector in production and we are missing the ability to set some Jersey server configuration properties. The connector only considers two of them, i.e jersey.config.server.disableMetainfServicesLookup and jersey.config.server.disableAutoDiscovery, which basically disable the auto discovery feature, and ignores the rest. It would be nice if a more generic approach were used to consider all of them, or at least consider them by introducing new properties to the connector and map those with Jersey's sever configuration properties.
Patch proposal attached
The text was updated successfully, but these errors were encountered: