새소식

300x250
2. 웹개발/Error모음

[Spring] java.lang.IllegalArgumentException 에러 해결

  • -
728x90

[Spring] java.lang.IllegalArgumentException 에러 원인

 

현재 운영중인 Project 중 
@Controller에서 요청을 받아 특정 url로 redirect시켜주는 컨트롤러가 있다. 
ex) (redirect:http://goddaehee.tistory.com/322 ))

 

예를 들어 특정 케이스의 경우 특정 포스팅 Page로 redirect 시켜주는 Controller가 있다고 하자.

다음과 같은 프로세스로 돌아가는 Controller가 있다고 가정하고, 하기 에러 로그부터 따라 가보자.


ex) pageNumber에 포스팅 번호를 바인딩 하여 Redirect 처리
1) https://goddaehee.tistory.com/{pageNumber}
2) {pageNumber}에 실제 포스팅 번호를 바인딩
3) 최종 Redirect할 URL : https://goddaehee.tistory.com/322

 

1. 에러 로그
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Model has no value for key 'pageNumber'] with root cause
java.lang.IllegalArgumentException: Model has no value for key 'pageNumber'
	at org.springframework.web.servlet.view.RedirectView.replaceUriTemplateVariables(RedirectView.java:387)
	at org.springframework.web.servlet.view.RedirectView.createTargetUrl(RedirectView.java:346)
	at org.springframework.web.servlet.view.RedirectView.renderMergedOutputModel(RedirectView.java:307)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1400)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1145)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1084)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at com.navercorp.lucy.security.xss.servletfilter.XssEscapeServletFilter.doFilter(XssEscapeServletFilter.java:36)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at lfcp.arch.common.filter.SessionValidationFilter.doFilter(SessionValidationFilter.java:173)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at lfcp.arch.common.filter.InboundFilter.doFilter(InboundFilter.java:148)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:121)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
... 중략

 

2. 케이스 및 원인 확인

1) 오류 원인

▶ 어떠한 오류에 의해 리다이렉트 하려는 URL이 pageNumber가 올바르게 바인딩 되지 못하여 다음과 같았다.

 - url : https://goddaehee.tistory.com/{pageNumber}

 

▶ pageNumber를 감싸고 있는 중괄호{}가 문제 이다. 

▶ 브라우저는 URL에 사용된 중괄호를 구문 분석할 수 없다.

 

2) URL redirect할 경우 사용하면 안되는 문자열

 - 유효한 URL을 작성할 때는 유효한 URL 문자 요약 표에 표시된 문자만 사용해야 한다.

 

2.1) URL에서 특별한 의미로 예약되어 있는 문자열

 - ! * ' ( ) ; : @ & = + $ , / ? % # [ ]
※참고 :  http://tools.ietf.org/html/rfc3986#section-2.2

 

2.2) 인터넷 게이트웨이와 프로토콜에서 혼동되는 문자열

(게이트웨이와 같은 여러 전송 에이전트에서 불안전하게 다루기 때문에 제한)
 - { } | \ ~ [ ] `

2.3) 일부 일반 문자중에서도 다음과 같이 인코딩되어야 하는 경우
 - 안전하지 않은 문자 : 인코딩된 값

안전하지 않은 문자 인코딩된 값
공백 %20
" %22
< %3C
> %3E
# %23
% %25
| %7C

 

※ 결국 나와 같은 경우 바인딩이 올바르게 되지 않아, {} 문자열이 있었기 때문에 오류가 발생했다.
  위와 같은 문자열에 대해서는 꼭 필요한 경우 인코딩을 하여 넘기도록 해야 한다.

 

300x250
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.