springboot 프로젝트에서 모든requestmapping의 URL 경로를 가져옵니다.

3839 단어 G 작업 중 문제

현재 프로젝트가 출시된 후 다른 사람이 악의적으로 프로젝트를 요청하여 프로젝트 메모리가 다음과 같은 오류가 발생했습니다.

2019/06/26-02:42 [http-bio-19000-exec-273] ERROR org.springframework.boot.web.support.ErrorPageFilter- Forwarding to error page from request [error/n/n/n] due to exception [Java heap space]
java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:3332)
	at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:421)
	at java.lang.StringBuffer.append(StringBuffer.java:272)
	at java.text.MessageFormat.subformat(MessageFormat.java:1335)
	at java.text.MessageFormat.format(MessageFormat.java:821)
	at org.apache.naming.StringManager.getString(StringManager.java:142)
	at org.apache.naming.resources.BaseDirContext.getAttributes(BaseDirContext.java:1179)
	at org.apache.naming.resources.BaseDirContext.getAttributes(BaseDirContext.java:1110)
	at org.apache.naming.resources.ProxyDirContext.cacheLoad(ProxyDirContext.java:1611)
	at org.apache.naming.resources.ProxyDirContext.cacheLookup(ProxyDirContext.java:1534)
	at org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:295)
	at org.apache.tomcat.util.http.mapper.Mapper.internalMapWrapper(Mapper.java:1061)
	at org.apache.tomcat.util.http.mapper.Mapper.map(Mapper.java:762)
	at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:522)
	at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:222)
	at org.apache.catalina.core.ApplicationHttpRequest.getRequestDispatcher(ApplicationHttpRequest.java:338)
	at org.springframework.web.servlet.view.InternalResourceView.getRequestDispatcher(InternalResourceView.java:223)
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:148)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1271)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

따라서 다른 사람이 다시 악의적인 요청으로 인해 프로젝트 라인에 메모리가 넘치는 것을 방지하기 위해 모든 URL 요청이 Requestmapping에 존재하는지 판단합니다
	private static List urls = new ArrayList();
	@Autowired
	WebApplicationContext applicationContext;
	public List urls() {
		RequestMappingHandlerMapping mapping = applicationContext
				.getBean(RequestMappingHandlerMapping.class);
		//  url 
		Map map = mapping
				.getHandlerMethods();
		for (RequestMappingInfo info : map.keySet()) {
			//  url Set , url
			Set patterns = info.getPatternsCondition().getPatterns();
			for (String url : patterns) {
				// 
				urls.add(url);
			}
		}
		return urls;
	}```
 , do something;

좋은 웹페이지 즐겨찾기