Skip to content

Commit

Permalink
Merge pull request #386 from groldan/qa
Browse files Browse the repository at this point in the history
QA Improvements based on SonarCloud analysis
  • Loading branch information
groldan authored Dec 6, 2023
2 parents a41aab2 + fe9da6a commit 286821b
Show file tree
Hide file tree
Showing 396 changed files with 5,693 additions and 3,889 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
*/
@SuppressWarnings("deprecation")
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
Expand Down Expand Up @@ -102,17 +103,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

protected ServletRequest adaptRequest(HttpServletRequest request) {
final String requestURI = request.getRequestURI();
final int restIdx = requestURI.indexOf("/rest");
final String restBasePath = "/rest";
final int restIdx = requestURI.indexOf(restBasePath);
if (restIdx > -1) {
final String pathToRest = requestURI.substring(0, restIdx + "/rest".length());
final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length());
final String pathInfo = requestURI.substring(pathToRest.length());

return new HttpServletRequestWrapper(request) {
public @Override String getServletPath() {
return "/rest";
@Override
public String getServletPath() {
return restBasePath;
}

public @Override String getPathInfo() {
@Override
public String getPathInfo() {
return pathInfo;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class GeoWebCacheApplicationTest {
class GeoWebCacheApplicationTest {

@Autowired private TestRestTemplate restTemplate;

Expand All @@ -37,15 +37,15 @@ void before() {
}

@Test
public void testRESTDefaultContentType() throws ParseException {
void testRESTDefaultContentType() throws ParseException {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
assertThat(parsed.isJsonArray());
}

@Test
public void testRESTPathExtensionContentNegotiation() {
void testRESTPathExtensionContentNegotiation() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers.json", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
* https://github.com/spring-projects/spring-framework/issues/24179}
*/
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
Expand All @@ -68,8 +69,6 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping(

handlerMapping.setUseSuffixPatternMatch(true);
handlerMapping.setUseRegisteredSuffixPatternMatch(true);
// handlerMapping.setUseTrailingSlashMatch(true);
// handlerMapping.setAlwaysUseFullPath(true);

return handlerMapping;
}
Expand Down Expand Up @@ -98,17 +97,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

protected ServletRequest adaptRequest(HttpServletRequest request) {
final String requestURI = request.getRequestURI();
final int restIdx = requestURI.indexOf("/rest");
final String restBasePath = "/rest";
final int restIdx = requestURI.indexOf(restBasePath);
if (restIdx > -1) {
final String pathToRest = requestURI.substring(0, restIdx + "/rest".length());
final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length());
final String pathInfo = requestURI.substring(pathToRest.length());

return new HttpServletRequestWrapper(request) {
public @Override String getServletPath() {
return "/rest";
@Override
public String getServletPath() {
return restBasePath;
}

public @Override String getPathInfo() {
@Override
public String getPathInfo() {
return pathInfo;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class RestConfigApplicationTest {
class RestConfigApplicationTest {

@Autowired private TestRestTemplate restTemplate;

Expand All @@ -33,14 +33,14 @@ void before() {
}

@Test
public void testDefaultContentType() {
void testDefaultContentType() {

testPathExtensionContentType("/rest/workspaces", APPLICATION_JSON);
testPathExtensionContentType("/rest/layers", APPLICATION_JSON);
}

@Test
public void testPathExtensionContentNegotiation() {
void testPathExtensionContentNegotiation() {

testPathExtensionContentType("/rest/styles/line.json", APPLICATION_JSON);
testPathExtensionContentType("/rest/styles/line.xml", APPLICATION_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/
package org.geoserver.cloud.wcs;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.geoserver.ows.Dispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -16,13 +18,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
public @Controller class WCSController {

private @Autowired Dispatcher geoserverDispatcher;
private final @NonNull Dispatcher geoserverDispatcher;

private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher;
private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher;

private @Autowired VirtualServiceVerifier virtualServiceVerifier;
private final @NonNull VirtualServiceVerifier virtualServiceVerifier;

@GetMapping("/")
public RedirectView redirectRootToGetCapabilities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/
package org.geoserver.cloud.wcs;

import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader;
import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
Expand All @@ -22,7 +24,7 @@
public class WcsApplicationConfiguration {

@Bean
VirtualServiceVerifier virtualServiceVerifier() {
return new VirtualServiceVerifier();
VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) {
return new VirtualServiceVerifier(catalog);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@SpringBootTest
@ActiveProfiles("test")
public class WcsApplicationTest {
class WcsApplicationTest {

@Test
public void contextLoads() {}
void contextLoads() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,21 @@ TestWfsPost testWfsPostServlet() {
@Bean
ServletRegistrationBean<GeoServerWicketServlet> geoServerWicketServletRegistration() {
GeoServerWicketServlet servlet = geoServerWicketServlet();
ServletRegistrationBean<GeoServerWicketServlet> registration;
registration =
new ServletRegistrationBean<GeoServerWicketServlet>(servlet, "/web", "/web/*");

return registration;
return new ServletRegistrationBean<>(servlet, "/web", "/web/*");
}

/** Register the {@link TestWfsPost servlet} */
@Bean
ServletRegistrationBean<TestWfsPost> wfsTestServletRegistration() {
TestWfsPost servlet = testWfsPostServlet();
ServletRegistrationBean<TestWfsPost> registration;
registration = new ServletRegistrationBean<TestWfsPost>(servlet, "/TestWfsPost");

return registration;
return new ServletRegistrationBean<>(servlet, "/TestWfsPost");
}

@Bean
HeaderContribution geoserverCloudCssTheme() {
HeaderContribution contribution = new HeaderContribution();
contribution.setScope(GeoServerBasePage.class);
contribution.setCSSFilename("geoserver-cloud.css");
// contribution.setFaviconFilename("favicon.ico");
return contribution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.core;

import lombok.extern.slf4j.Slf4j;

import org.geoserver.cloud.autoconfigure.core.GeoServerWebMvcMainAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.demo.DemosAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.extension.ExtensionsAutoConfiguration;
Expand All @@ -15,16 +13,11 @@
import org.geoserver.cloud.autoconfigure.web.wfs.WfsAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.wms.WmsAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.wps.WpsAutoConfiguration;
import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.GeoServerInfo.WebUIMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;

@AutoConfiguration(after = {GeoServerWebMvcMainAutoConfiguration.class})
@Import({ //
WebCoreConfiguration.class, // this one is mandatory
Expand All @@ -37,27 +30,10 @@
DemosAutoConfiguration.class,
ToolsAutoConfiguration.class
})
@Slf4j
public class WebUIApplicationAutoConfiguration {

private @Autowired GeoServer geoServer;
private @Autowired Environment environment;

public @PostConstruct void setDefaults() {
GeoServerInfo global = geoServer.getGlobal();
WebUIMode webUIMode = global.getWebUIMode();
if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) {
log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode);
global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT);
geoServer.save(global);
}

Boolean hidefs =
environment.getProperty(
"geoserver.web-ui.file-browser.hide-file-system", Boolean.class);
if (Boolean.TRUE.equals(hidefs)) {
log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property");
System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true");
}
@Bean
WebUIInitializer webUIDefaultsInitializer(Environment env) {
return new WebUIInitializer(env);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
* GPL 2.0 license, available at the root application directory.
*/
package org.geoserver.cloud.autoconfigure.web.core;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.GeoServerInfo.WebUIMode;
import org.geoserver.config.GeoServerInitializer;
import org.springframework.core.env.Environment;

@Slf4j
@RequiredArgsConstructor
class WebUIInitializer implements GeoServerInitializer {

private final @NonNull Environment environment;

@Override
public void initialize(GeoServer geoServer) throws Exception {
GeoServerInfo global = geoServer.getGlobal();
WebUIMode webUIMode = global.getWebUIMode();
if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) {
log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode);
global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT);
geoServer.save(global);
}

Boolean hidefs =
environment.getProperty(
"geoserver.web-ui.file-browser.hide-file-system", Boolean.class);
if (Boolean.TRUE.equals(hidefs)) {
log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property");
System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.demo;

import lombok.Getter;

import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration;
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -27,5 +25,8 @@ public class DemoRequestsConfiguration extends AbstractWebUIAutoConfiguration {

static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".demo-requests";

private final @Getter String configPrefix = CONFIG_PREFIX;
@Override
public String getConfigPrefix() {
return CONFIG_PREFIX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.demo;

import lombok.Getter;

import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -31,5 +29,8 @@ public class DemosAutoConfiguration extends AbstractWebUIAutoConfiguration {

static final String CONFIG_PREFIX = "geoserver.web-ui.demos";

private final @Getter String configPrefix = CONFIG_PREFIX;
@Override
public String getConfigPrefix() {
return CONFIG_PREFIX;
}
}
Loading

0 comments on commit 286821b

Please sign in to comment.