Skip to content

Commit

Permalink
[pinpoint-apm#10077] Remove unnecessary servlet-context-web.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 26, 2023
1 parent 9baa49a commit 1a2216d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@Configuration
@ImportResource({
"classpath:applicationContext-web.xml",
"classpath:servlet-context-web.xml",

"classpath:applicationContext-web-dao-config.xml",
})
Expand Down
22 changes: 18 additions & 4 deletions web/src/main/java/com/navercorp/pinpoint/web/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package com.navercorp.pinpoint.web;

import com.navercorp.pinpoint.web.interceptor.AdminAuthInterceptor;
import com.navercorp.pinpoint.web.vo.tree.SortByRequestConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
Expand All @@ -47,20 +48,29 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Value("${pinpoint.web.cache-resources:false}")
private boolean cacheResource;

@Value("${admin.password:}")
private String password;

@Override
public void addViewControllers(ViewControllerRegistry registry) {
// For using like WelcomePageHandler
registry.addViewController("/").setViewName("forward:/index.html");
}

@Bean
public ResourceHandlerBuilder resourceHandlerBuilder() {

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AdminAuthInterceptor(password))
.addPathPatterns("/admin/**");
}

public ResourceHandlerBuilder newResourceHandlerBuilder() {
return new ResourceHandlerBuilder(cacheResource);
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
final ResourceHandlerBuilder builder = resourceHandlerBuilder();
final ResourceHandlerBuilder builder = newResourceHandlerBuilder();

// index.html no-cache
builder.apply(registry.addResourceHandler("/index.html")
Expand All @@ -87,6 +97,10 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
);
}

private ResourceHandlerBuilder newuilder() {
return new ResourceHandlerBuilder(cacheResource);
}

static class ResourceHandlerBuilder {

private final boolean cacheResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@

package com.navercorp.pinpoint.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.navercorp.pinpoint.common.util.StringUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Value;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.HandlerInterceptor;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* FIXME temporary interceptor for admin operations.
Expand All @@ -37,13 +33,14 @@
*/
public class AdminAuthInterceptor implements HandlerInterceptor {

private static final Charset UTF_8 = StandardCharsets.UTF_8;

private final Logger logger = LogManager.getLogger(this.getClass());

@Value("${admin.password:}")
private String password;

private final String password;

public AdminAuthInterceptor(String password) {
this.password = password;
}

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestUri = request.getRequestURI();
Expand Down
22 changes: 0 additions & 22 deletions web/src/main/resources/servlet-context-web.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@Disabled
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:servlet-context-web.xml", "classpath:applicationContext-web.xml"})
@ContextConfiguration(locations = {"classpath:applicationContext-web.xml"})
public class AlarmControllerTest {
private final static String APPLICATION_ID = "test-application";
private final static String APPLICATION_ID_UPDATED = "test-application-tomcat";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static com.navercorp.pinpoint.web.TestTraceUtils.hasKey;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static com.navercorp.pinpoint.web.TestTraceUtils.hasKey;

/**
* @author minwoo.jung
*/
@Disabled
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:servlet-context-web.xml", "classpath:applicationContext-web.xml"})
@ContextConfiguration(locations = {"classpath:applicationContext-web.xml"})
public class ConfigControllerTest {
private final Logger logger = LogManager.getLogger(this.getClass());
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static com.navercorp.pinpoint.web.TestTraceUtils.hasKey;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static com.navercorp.pinpoint.web.TestTraceUtils.hasKey;

/**
* @author minwoo.jung
*/
@Disabled
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:servlet-context-web.xml", "classpath:applicationContext-web.xml"})
@ContextConfiguration(locations = {"classpath:applicationContext-web.xml"})
public class UserControllerTest {

private final static String USER_ID = "naver00";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@Disabled
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:servlet-context-web.xml", "classpath:applicationContext-web.xml"})
@ContextConfiguration(locations = {"classpath:applicationContext-web.xml"})
public class UserGroupControllerTest {

private final static String TEST_USER_GROUP_ID = "testUserGroup";
Expand Down

0 comments on commit 1a2216d

Please sign in to comment.