You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Gokey <cg...@sesda2.com> on 2014/07/01 23:08:51 UTC

Struts1 RequestProcessor

We've got some pretty old code that I'm trying to port over to Struts2 and
if someone could point me in the right direction in how I can rewrite this
 code that we subclassed in Struts1's RequestProcessor to handle the same
type of thing in Struts2, I'd really appreciate it.

Basically:

1) In Struts1, we implements a custom RequestProcessor, that overrides:

public class CustomRequestProcessor extends RequestProcessor
   protected void processForwardConfig(HttpServletRequest request,
                                        HttpServletResponse response,
                                        ForwardConfig forward) throws
            IOException, ServletException

2) In the method above, it grabs the path:

        String path = forward.getPath();

3) If the path is a .jsp file, it does things special and rewrites where
the JSP file is located.
    Then calls:

     newPath = determineNewPath(path);
     doForward(newPath, request, response);

I thought about overwriting StrutsPrepareAndExecuteFilter, but it isn't
obvious how I can grab the path and rewrite it, so any suggestions/help
would be greatly apprecicated.   Is this something that an Interceptor
would be best in handling?

Thanks,
Chris

Re: Struts1 RequestProcessor

Posted by Christopher Gokey <ch...@gmail.com>.
So I changed this slightly and think I've got something working...

// Referenced:
core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
// http://docs.oracle.com/javaee/5/api/javax/servlet/RequestDispatcher.html
public class KeywordResultType extends StrutsResultSupport {
    @Override
    protected void doExecute(String finalLocation, ActionInvocation
actionInvocation) throws Exception {
        System.out.println("finalDestination=" + finalLocation);
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        RequestDispatcher dispatcher =
request.getRequestDispatcher("/HelloWorld2.jsp");
        dispatcher.forward(request, response);
    }
}





On Tue, Jul 1, 2014 at 5:35 PM, Christopher Gokey <ch...@gmail.com>
wrote:

> Thanks Paul,
>
> So based on what you said, I looked up creating a custom result type:
>
> http://indreshtech.blogspot.com/2013/03/implementing-custom-resulttype-in.html
>
> And added this code (struts.xml):
>         <result-types>
>             <result-type name="keyword-result-type"
> class="example.framework.KeywordResultType"></result-type>
>         </result-types>
>
> And using it like so (struts.xml):
>         <action name="Titles" class="example.application.TitlesAction"
> method="execute">
>             <result type="keyword-result-type"
> name="success">/HelloWorld.jsp</result>
>         </action>
>
> In the output from these statements:
>
> public class KeywordResultType implements Result {
>     public void execute(ActionInvocation actionInvocation) throws
> Exception {
>         System.out.println("result
> code="+actionInvocation.getResultCode());
>         System.out.println("result="+actionInvocation.getResult());
>     }
> }
>
> I'm getting:
> result code=success
> result=example.framework.KeywordResultType@12da22e9
>
> So how can I get the actual JSP file (/HelloWorld.jsp) it is going to and
> rewrite that rather than just "success"?
>
> Chris
>
>
> On Jul 1, 2014, at 5:12 PM, Paul Benedict <pb...@apache.org> wrote:
>
> > It sounds like what you want is to create a new result type.
> >
> >
> > Cheers,
> > Paul
> >
> >
> > On Tue, Jul 1, 2014 at 4:08 PM, Christopher Gokey <cg...@sesda2.com>
> wrote:
> >
> >> We've got some pretty old code that I'm trying to port over to Struts2
> and
> >> if someone could point me in the right direction in how I can rewrite
> this
> >> code that we subclassed in Struts1's RequestProcessor to handle the same
> >> type of thing in Struts2, I'd really appreciate it.
> >>
> >> Basically:
> >>
> >> 1) In Struts1, we implements a custom RequestProcessor, that overrides:
> >>
> >> public class CustomRequestProcessor extends RequestProcessor
> >>   protected void processForwardConfig(HttpServletRequest request,
> >>                                        HttpServletResponse response,
> >>                                        ForwardConfig forward) throws
> >>            IOException, ServletException
> >>
> >> 2) In the method above, it grabs the path:
> >>
> >>        String path = forward.getPath();
> >>
> >> 3) If the path is a .jsp file, it does things special and rewrites where
> >> the JSP file is located.
> >>    Then calls:
> >>
> >>     newPath = determineNewPath(path);
> >>     doForward(newPath, request, response);
> >>
> >> I thought about overwriting StrutsPrepareAndExecuteFilter, but it isn't
> >> obvious how I can grab the path and rewrite it, so any suggestions/help
> >> would be greatly apprecicated.   Is this something that an Interceptor
> >> would be best in handling?
> >>
> >> Thanks,
> >> Chris
> >>
>
>

Re: Struts1 RequestProcessor

Posted by Christopher Gokey <ch...@gmail.com>.
Thanks Paul,

So based on what you said, I looked up creating a custom result type:
http://indreshtech.blogspot.com/2013/03/implementing-custom-resulttype-in.html

And added this code (struts.xml):
        <result-types>
            <result-type name="keyword-result-type" class="example.framework.KeywordResultType"></result-type>
        </result-types>

And using it like so (struts.xml):
        <action name="Titles" class="example.application.TitlesAction" method="execute">
            <result type="keyword-result-type" name="success">/HelloWorld.jsp</result>
        </action>

In the output from these statements:

public class KeywordResultType implements Result {
    public void execute(ActionInvocation actionInvocation) throws Exception {
        System.out.println("result code="+actionInvocation.getResultCode());
        System.out.println("result="+actionInvocation.getResult());
    }
}

I'm getting:
result code=success
result=example.framework.KeywordResultType@12da22e9

So how can I get the actual JSP file (/HelloWorld.jsp) it is going to and rewrite that rather than just "success"?

Chris


On Jul 1, 2014, at 5:12 PM, Paul Benedict <pb...@apache.org> wrote:

> It sounds like what you want is to create a new result type.
> 
> 
> Cheers,
> Paul
> 
> 
> On Tue, Jul 1, 2014 at 4:08 PM, Christopher Gokey <cg...@sesda2.com> wrote:
> 
>> We've got some pretty old code that I'm trying to port over to Struts2 and
>> if someone could point me in the right direction in how I can rewrite this
>> code that we subclassed in Struts1's RequestProcessor to handle the same
>> type of thing in Struts2, I'd really appreciate it.
>> 
>> Basically:
>> 
>> 1) In Struts1, we implements a custom RequestProcessor, that overrides:
>> 
>> public class CustomRequestProcessor extends RequestProcessor
>>   protected void processForwardConfig(HttpServletRequest request,
>>                                        HttpServletResponse response,
>>                                        ForwardConfig forward) throws
>>            IOException, ServletException
>> 
>> 2) In the method above, it grabs the path:
>> 
>>        String path = forward.getPath();
>> 
>> 3) If the path is a .jsp file, it does things special and rewrites where
>> the JSP file is located.
>>    Then calls:
>> 
>>     newPath = determineNewPath(path);
>>     doForward(newPath, request, response);
>> 
>> I thought about overwriting StrutsPrepareAndExecuteFilter, but it isn't
>> obvious how I can grab the path and rewrite it, so any suggestions/help
>> would be greatly apprecicated.   Is this something that an Interceptor
>> would be best in handling?
>> 
>> Thanks,
>> Chris
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts1 RequestProcessor

Posted by Paul Benedict <pb...@apache.org>.
It sounds like what you want is to create a new result type.


Cheers,
Paul


On Tue, Jul 1, 2014 at 4:08 PM, Christopher Gokey <cg...@sesda2.com> wrote:

> We've got some pretty old code that I'm trying to port over to Struts2 and
> if someone could point me in the right direction in how I can rewrite this
>  code that we subclassed in Struts1's RequestProcessor to handle the same
> type of thing in Struts2, I'd really appreciate it.
>
> Basically:
>
> 1) In Struts1, we implements a custom RequestProcessor, that overrides:
>
> public class CustomRequestProcessor extends RequestProcessor
>    protected void processForwardConfig(HttpServletRequest request,
>                                         HttpServletResponse response,
>                                         ForwardConfig forward) throws
>             IOException, ServletException
>
> 2) In the method above, it grabs the path:
>
>         String path = forward.getPath();
>
> 3) If the path is a .jsp file, it does things special and rewrites where
> the JSP file is located.
>     Then calls:
>
>      newPath = determineNewPath(path);
>      doForward(newPath, request, response);
>
> I thought about overwriting StrutsPrepareAndExecuteFilter, but it isn't
> obvious how I can grab the path and rewrite it, so any suggestions/help
> would be greatly apprecicated.   Is this something that an Interceptor
> would be best in handling?
>
> Thanks,
> Chris
>