Announcement Announcement Module
Collapse
No announcement yet.
RESTful controller - Redirect to other page Issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RESTful controller - Redirect to other page Issue

    I was trying to use Spring-OAuth 2.0 for provider implementation. After client\customer successful authentication want to redirect user to authorization page. Below is my controller code (using Spring RESTful)

    @RequestMapping(value = "/confirm_access", method = RequestMethod.GET)
    @ResponseBody
    protected View authenticateClient(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ClientAuthenticationToken clientAuth = getAuthenticationCache().getAuthentication(request , response);
    if (clientAuth == null) {
    throw new IllegalStateException("No client authentication request to authorize.");
    }
    // Logic to auth client id, secrect key and user credential
    ClientDetails client = getClientDetailsService().loadClientByClientId(cli entAuth.getClientId());
    TreeMap<String, Object> model = new TreeMap<String, Object>();
    model.put("auth_request", clientAuth);
    model.put("client", client);
    View view = new RedirectView("access_confirmation",true);
    ((RedirectView)view).setAttributesMap(model);
    return view;
    }

    It give exception while trying to redirect (want to redirect to http://localhost:8080/access_confirmation.jsp or within WEB-INF\access_confirmation.jsp). I have also tried to use ModelAndView("access_confirmation",model); - But it open file with name "confirm_access" having JSON model data. Please suggest what I am missing? I am badly stuck due to this.

    Code:
    Problem accessing /oauth/confirm_access. Reason: 
    
        ApplicationObjectSupport instance [org.springframework.web.servlet.view.RedirectView: unnamed; URL [access_confirmation]] does not run in an ApplicationContext (through reference chain: org.springframework.web.servlet.view.RedirectView["applicationContext"])
    
    Caused by:
    org.codehaus.jackson.map.JsonMappingException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.RedirectView: unnamed; URL [access_confirmation]] does not run in an ApplicationContext (through reference chain: org.springframework.web.servlet.view.RedirectView["applicationContext"])
    	at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:218)
    	at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:183)
    	at org.codehaus.jackson.map.ser.SerializerBase.wrapAndThrow(SerializerBase.java:128)
    	at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:183)
    	at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    	at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:606)
    	at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:280)
    	at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1341)
    	at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:153)
    	at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:975)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:933)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:882)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:428)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
    	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.oauth2.provider.OAuth2ProtectedResourceFilter.doFilter(OAuth2ProtectedResourceFilter.java:57)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    	at org.springframework.security.oauth2.provider.verification.VerificationCodeFilter.doFilter(VerificationCodeFilter.java:105)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.oauth2.provider.OAuth2ExceptionHandlerFilter.doFilter(OAuth2ExceptionHandlerFilter.java:36)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.oauth2.provider.verification.BasicUserApprovalFilter.doFilter(BasicUserApprovalFilter.java:41)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
    Caused by: java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.RedirectView: unnamed; URL [access_confirmation]] does not run in an ApplicationContext

  • #2
    I was able to resolve issue after getting pointer from this forum.

    As workaround I used --> response.sendRedirect("URI"). That pointed I was doing silly mistake. Removing @ResponseBody annotation resolved this issue.

    Comment

    Working...
    X