Results 1 to 6 of 6

Thread: Interceptor problem

  1. #1
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Unhappy Interceptor problem

    Hi friends

    i am trying to study about interceptor

    i have a class (got from this form)
    Code:
    public class SecurityHandlerInterceptor extends HandlerInterceptorAdapter {
        
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
              System.out.println("Inside Intercepter");
            if (request.getSession(true).getAttribute("name") == null) {
                try {            
                  
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } catch (IOException e) {
                    
                    e.printStackTrace();
                    
                }
                return false;
            } else {
                return true;
            }
        }
    and in my -servlet.xml

    HTML Code:
     <bean id="interceptor" class="org.springframework.samples.imagedb.web.SecurityHandlerInterceptor" >
            
        </bean>
        
        <bean id="interceptedService" class="XXX">
            <property name="target">
                <ref bean="imageController"/>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>interceptor</value>
                </list>
            </property>
        </bean>
    and i does not know which class can used for bean id="interceptedService"

    and i am trying to control login

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    You have implemented a HandlerInterceptor which is different from the MethodInterceptor. The HandlerInterceptor is used with Handlers/Controllers and needs to be registered on the HandlerMapping.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    i am changed the code with your valueable sujection,

    and configered like this
    HTML Code:
      <bean id="interceptor" class="org.springframework.samples.imagedb.web.SecurityHandlerInterceptor" >
            
        </bean>
        
        <bean id="interceptedService" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="interceptor"/>
                </list>
            </property>
            <property name="mappings">
                <value>
                   /test=testPostController
                </value>
            </property> 
            
        </bean> 
    but it does not work

  4. #4
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    i got the problem it is due to method in org.springframework.web.servlet.HandlerInterceptor
    Code:
     public SecurityHandlerInterceptor() {
     }
    ONLY THIS METHOD WORKING
    plz help

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    You need to write full posts because your last post well ehr....

    You need to register the HandlerInterceptors with the SimpleUrlHandlerMapping you already use. You don't simply register it somewhere...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    could you explain with my example
    i am a beginer plz
    HTML Code:
    <property name="mappings">
                <props>
                   <prop key="/test">testPostController</prop> 
                </props>
            </property>
    Last edited by nidhin; Dec 18th, 2007 at 05:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •