This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #88: Jersey server configuration properties are ignored
A new type was introduced called ApplicationConfiguration. Clients can register an implementation as an OSGi service. The connector tracks all ApplicationConfigurations and uses its properties to configure the JAX-RS Application. The connector is aware of dynamic ApplicationConfigurations. So it's possible to register them anytime.
- Loading branch information
hstaudacher
committed
Mar 18, 2015
1 parent
3ef18c4
commit c03759e
Showing
14 changed files
with
569 additions
and
110 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...ource.jaxrs.publisher/src/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 EclipseSource and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Holger Staudacher - initial API and implementation, ongoing development | ||
******************************************************************************/ | ||
package com.eclipsesource.jaxrs.publisher; | ||
|
||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.Application; | ||
|
||
/** | ||
* <p> | ||
* Service that allows configuration of the JAX-RS {@link Application}. Multiple registrations will be tracked. | ||
* </p> | ||
* | ||
* @since 4.3 | ||
*/ | ||
public interface ApplicationConfiguration { | ||
|
||
/** | ||
* <p> | ||
* Will be called before the JAX-RS {@link Application} is registered. Please note that | ||
* one {@link ApplicationConfiguration} can overwrite the values of other {@link ApplicationConfiguration}s. It | ||
* depends on the order they are available in the OSGi container. | ||
* </p> | ||
* | ||
* @see Application#getProperties() | ||
*/ | ||
Map<String, Object> getProperties(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...isher/src/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 Holger Staudacher and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Holger Staudacher - initial API and implementation | ||
******************************************************************************/ | ||
package com.eclipsesource.jaxrs.publisher.internal; | ||
|
||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.ServiceReference; | ||
import org.osgi.util.tracker.ServiceTracker; | ||
|
||
import com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; | ||
|
||
/** | ||
* <p> | ||
* Tracker for OSGi Services implementing the {@link ApplicationConfiguration} interface. | ||
* </p> | ||
*/ | ||
public class ApplicationConfigurationTracker extends ServiceTracker { | ||
|
||
private final JAXRSConnector connector; | ||
|
||
ApplicationConfigurationTracker( BundleContext context, JAXRSConnector connector ) { | ||
super( context, ApplicationConfiguration.class.getName(), null ); | ||
this.connector = connector; | ||
} | ||
|
||
@Override | ||
public Object addingService( ServiceReference reference ) { | ||
return connector.addApplicationConfiguration( reference ); | ||
} | ||
|
||
@Override | ||
public void removedService( ServiceReference reference, Object service ) { | ||
if( service instanceof ApplicationConfiguration ) { | ||
connector.removeApplicationConfiguration( reference, ( ApplicationConfiguration )service ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...isher/src/com/eclipsesource/jaxrs/publisher/internal/DefaultApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 EclipseSource and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Holger Staudacher - initial API and implementation, ongoing development | ||
******************************************************************************/ | ||
package com.eclipsesource.jaxrs.publisher.internal; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.glassfish.jersey.server.ServerProperties; | ||
|
||
import com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; | ||
|
||
|
||
public class DefaultApplicationConfiguration implements ApplicationConfiguration { | ||
|
||
private final Configuration configuration; | ||
|
||
public DefaultApplicationConfiguration( Configuration configuration ) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getProperties() { | ||
Map<String, Object> properties = new HashMap<>(); | ||
// don't look for implementations described by META-INF/services/* | ||
properties.put( ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, false ); | ||
// disable auto discovery on server, as it's handled via OSGI | ||
properties.put( ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true ); | ||
diableWadlToConfiguration( properties ); | ||
return properties; | ||
} | ||
|
||
/** | ||
* 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. | ||
* | ||
* @param disableWadl <code>true</code> to disable WADL feature | ||
*/ | ||
@SuppressWarnings( "deprecation" ) | ||
private void diableWadlToConfiguration( Map<String, Object> properties ) { | ||
properties.put( ServerProperties.WADL_FEATURE_DISABLE, configuration.isWadlDisabled() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.