DATAREST-1386 - Add HAL Explorer module
We now ship a module containing the HAL Explorer [0] as an alternative to the HAL Browser which seems to be mostly out of maintenance and the WebJar refers to a jQuery version with a CVE. The new module still contains some customization code that we had in place for the browser to customize the POST/PUT forms to use the JSON Schema exposed for the aggregates. The HAL Browser extension is now deprecated in the form that its inclusion causes a warn log to recommend switching to the explorer. A couple of general coding improvements: package scope for controllers and handler methods. Better use of constants and newer request mapping annotations. Tweaked the configuration of static resource handlers to resolve the implicit cyclic dependency between the browser/explorer and the WebMVC module by introducing a Spring Factories backed extension SPI. [0] https://github.com/toedter/hal-explorer
This commit is contained in:
@@ -46,6 +46,7 @@ import org.springframework.context.support.ReloadableResourceBundleMessageSource
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.data.auditing.AuditableBeanWrapperFactory;
|
||||
import org.springframework.data.auditing.MappingAuditableBeanWrapperFactory;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -883,16 +884,10 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
|
||||
// Register HAL browser if present
|
||||
RepositoryRestConfiguration configuration = repositoryRestConfiguration();
|
||||
|
||||
if (ClassUtils.isPresent("org.springframework.data.rest.webmvc.halbrowser.HalBrowser",
|
||||
getClass().getClassLoader())) {
|
||||
|
||||
String basePath = repositoryRestConfiguration().getBasePath().toString().concat("/browser");
|
||||
String rootLocation = "classpath:META-INF/spring-data-rest/hal-browser/";
|
||||
|
||||
registry.addResourceHandler(basePath.concat("/**")).addResourceLocations(rootLocation);
|
||||
}
|
||||
SpringFactoriesLoader.loadFactories(StaticResourceProvider.class, beanClassLoader)
|
||||
.forEach(it -> it.customizeResources(registry, configuration));
|
||||
}
|
||||
|
||||
private static class ResourceSupportHttpMessageConverter extends TypeConstrainedMappingJackson2HttpMessageConverter
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.config;
|
||||
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
||||
/**
|
||||
* SPI to be able to register extensions that add static resource routes.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 3.2
|
||||
* @see org.springframework.data.rest.webmvc.halbrowser.HalBrowserConfiguration
|
||||
* @see org.springframework.data.rest.webmvc.halexplorer.HalExplorerConfiguration
|
||||
*/
|
||||
public interface StaticResourceProvider {
|
||||
|
||||
/**
|
||||
* Customize the given {@link ResourceHandlerRegistry}.
|
||||
*
|
||||
* @param registry must not be {@literal null}.
|
||||
* @param configuration must not be {@literal null}.
|
||||
*/
|
||||
void customizeResources(ResourceHandlerRegistry registry, RepositoryRestConfiguration configuration);
|
||||
}
|
||||
Reference in New Issue
Block a user