Solved

Custom Struts 2 Interceptor intercept() method not running

Posted on 2007-11-28
7
6,952 Views
Last Modified: 2013-11-24
I'm trying to create a Struts 2 Interceptor that will change the request to HTTPS and forward all of the parameters.  I must have made a mistake in setting it up because the intercept() method is not working.  The init() method is running when I start Tomcat up, but when it comes time to run the intercept() method, nothing happens.  My code is below split into sections:
//inside the package tag in the struts.xml:

<interceptors>

     <interceptor name="isSSL" class="com.StrutsApp.Interceptors.SSLInterceptor"/>

</interceptors>
 

// this action is defined within my package tag

<action name="newUserProfile"   class="com.StrutsApp.Login.Actions.NewUserProfileAction">

       <interceptor-ref name="isSSL"/>

       <result type="tiles">CreateUserProfile</result>            

</action>
 
 

//Ineterceptor class
 
 

package com.StrutsApp.Interceptors;
 

import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import com.opensymphony.xwork2.ActionInvocation;
 

public class SSLInterceptor extends AbstractInterceptor {

    public java.lang.String intercept(ActionInvocation actionInvocation) throws java.lang.Exception {

        //String retVal = (String) actionInvocation.getAction();

        Object obj = actionInvocation.getAction();

        System.out.println("############## We hit the interceptor");    

        return actionInvocation.invoke();

    }

    public void init() {

        System.out.println("########### Interceptor is initialized");

    }

	public void destroy() { }

}

Open in new window

0
Comment
Question by:icentris
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:summerian
ID: 20441505
Is the interceptor defined in the same package that action "newUserProfile"?

Is the action invoked ?
0
 
LVL 5

Expert Comment

by:summerian
ID: 20452208
Did you resolve the problem?
0
 

Author Comment

by:icentris
ID: 20504805
Initially the Interceptor class was not in the same package.  I moved it into the same package with the same result.  The action is invoked.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Accepted Solution

by:
summerian earned 125 total points
ID: 20505403
I mean in the same 'struts' package, that is if the following is the case:

<package ...>
<interceptors>
     <interceptor name="isSSL" class="com.StrutsApp.Interceptors.SSLInterceptor"/>
</interceptors>
 
// *THE SAME PACKAGE*
<action name="newUserProfile"   class="com.StrutsApp.Login.Actions.NewUserProfileAction">
       <interceptor-ref name="isSSL"/>
       <result type="tiles">CreateUserProfile</result>            
</action>
</package>

If you define interceptor in another package, and action package does not derive from that package, then that interceptor is unknown at that point, and will not be invoked (there should be an error message also, however).

You should also check spelling, there might be some spelling mistake.

If that is not the case, post whole struts.xml file.
0
 

Author Comment

by:icentris
ID: 20508684
They are defined in the same package...here is my struts.xml file.  I appreciate you looking into this.
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">
 

<struts>
 

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="true" />

<constant name="struts.multipart.saveDir" value="/home/paul/Desktop/tmp" />  
 

    <!--<include file="fileupload.xml" />-->
 

    <package name="DatingSite" namespace="/DatingSite" extends="struts-default">

        <result-types>

          <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>

        </result-types>

        <interceptors>

           <interceptor name="isSSL" class="com.StrutsApp.Login.Actions.SSLInterceptor"/>

        </interceptors>

        <global-results>

            <result name="login" type="tiles">frontPage</result>

            <result name="login-success">/WEB-INF/pages/Index.jsp</result>

        </global-results>

        <action name="newUserProfile" class="com.StrutsApp.Login.Actions.NewUserProfileAction">

            <interceptor-ref name="isSSL"/>

            <result type="tiles">CreateUserProfile</result>

        </action>
 
 

        

        

        <action name="init" class="com.StrutsApp.Actions.InitAction">

            <result type="tiles">frontPage</result>

        </action>

        <action name="email" class="com.StrutsApp.Email.Actions.EmailSenderAction">

            <result name="ERROR">/jsp/LandingPage.jsp</result>

            <result>/jsp/LandingPage.jsp</result>

        </action>
 

        <action name="CheckAndCreateAccount" class="com.StrutsApp.Login.Actions.CheckAndCreateAccount">

            <result name="error">/jsp/LandingPage.jsp</result>

            <result type="tiles">CreateUserProfile</result>

            <result name="input" type="tiles">CreateUserProfile</result>

        </action>

        <action name="Contact">

            <result name="ERROR"></result>

            <result type="tiles">contacts</result>

        </action>

        <action name="Profile">

            <result name="ERROR"></result>

            <result type="tiles">profile</result>

        </action>

        <action name="SimpleSearch">

            <result name="ERROR"></result>

            <result type="tiles">simpleSearch</result>

        </action>

        <action name="EmailCompose">

            <result name="ERROR"></result>

            <result type="tiles">emailCompose</result>

        </action>
 
 

        <action name="SelectImage">

            <result name="ERROR"></result>

            <result type="tiles">selectImage</result>

        </action>

        <action name="SaveImages" class="com.StrutsApp.ImageUpload.Actions.SaveImage" method="excute">

            <result name="ERROR"></result>

            <result type="tiles">savedImages</result>

        </action>

        <action name="ManageImages">

            <result name="ERROR"></result>

            <result type="tiles">manageImages</result>

        </action>

        <action name="newUserProfile" class="com.StrutsApp.Login.Actions.NewUserProfileAction">

            <result name="ERROR"></result>

            <result type="tiles">CreateUserProfile</result>

        </action>

        <action name="profilePage1" class="com.StrutsApp.Profile.Actions.InitProfilePage1">

            <result name="ERROR"></result>

            <result type="tiles">profilePage1</result>

        </action>

        <action name="saveProfilePage1" class="com.StrutsApp.Profile.Actions.SaveProfilePage1">

            <result name="ERROR"></result>

            <result type="tiles">profilePage2</result>

        </action>

        <action name="saveProfilePage2" class="com.StrutsApp.Profile.Actions.SaveProfilePage2">

            <result name="ERROR"></result>

            <result type="tiles">profilePage3</result>

        </action>

        <action name="saveProfilePage3" class="com.StrutsApp.Profile.Actions.SaveProfilePage3">

            <result name="ERROR"></result>

            <result type="tiles">profilePage4</result>

        </action>

        <action name="saveProfilePage4" class="com.StrutsApp.Profile.Actions.SaveProfilePage4">

            <result name="ERROR"></result>

            <result type="tiles">profilePageFinish</result>

        </action>

    </package>

</struts>

Open in new window

0
 

Author Comment

by:icentris
ID: 20509859
The problem was that I had a duplicate action name.  It happened to be the action that I wanted the interceptor on....Thanks for help!
0
 

Author Closing Comment

by:icentris
ID: 31411524
I ended up fixing it myself only because you didn't have time to look at it after I sent the complete struts.xml.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
struts spring hibernate example 12 86
twoTwo  challenge 35 86
zeroFront challenge 7 71
JAVA part two 5 41
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now