Decompose configureBaseApplication() method further
@@ -375,14 +375,11 @@ public abstract class Application<T extends RestConfig> {
* client.
*/
public void configureBaseApplication(Configurable<?> config, Map<String, String> metricTags) {
- registerJsonProvider(config, true);
+ T restConfig = getConfiguration();
- RestConfig restConfig = getConfiguration();
-
- config.register(ValidationFeature.class);
- config.register(ConstraintViolationExceptionMapper.class);
- config.register(new WebApplicationExceptionMapper(restConfig));
- config.register(new GenericExceptionMapper(restConfig));
+ registerJsonProvider(config, restConfig, true);
+ registerFeatures(config, restConfig);
+ registerExceptionMappers(config, restConfig);
config.register(new MetricsResourceMethodApplicationListener(metrics, "jersey",
metricTags, restConfig.getTime()));
@@ -393,11 +390,12 @@ public abstract class Application<T extends RestConfig> {
/**
* Register a body provider and optional exception mapper for (de)serializing JSON in
* request/response entities.
- * @param config The config to register the provider
+ * @param config The config to register the provider with
+ * @param restConfig The application's configuration
* @param registerExceptionMapper Whether or not to register an additional exception mapper for
* handling errors in (de)serialization
*/
- protected void registerJsonProvider(Configurable<?> config, boolean registerExceptionMapper) {
+ protected void registerJsonProvider(Configurable<?> config, T restConfig, boolean registerExceptionMapper) {
ObjectMapper jsonMapper = getJsonMapper();
JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(jsonMapper);
config.register(jsonProvider);
@@ -406,6 +404,26 @@ public abstract class Application<T extends RestConfig> {
}
}
+ /**
+ * Register server features
+ * @param config The config to register the features with
+ * @param restConfig The application's configuration
+ */
+ protected void registerFeatures(Configurable<?> config, T restConfig) {
+ config.register(ValidationFeature.class);
+ }
+
+ /**
+ * Register handlers for translating exceptions into responses.
+ * @param config The config to register the mappers with
+ * @param restConfig The application's configuration
+ */
+ protected void registerExceptionMappers(Configurable<?> config, T restConfig) {
+ config.register(ConstraintViolationExceptionMapper.class);
+ config.register(new WebApplicationExceptionMapper(restConfig));
+ config.register(new GenericExceptionMapper(restConfig));
+ }
+
public T getConfiguration() {
return this.config;
}
