Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can we expand interceptor-stack from Confluence plugin?

Dmitry_Zharikhin April 28, 2014

I need to create functionality like PageAware in my plugin. There's non-standard entity I need to deal with xwork actions and I want to encapsulate enity resolving methods in some interceptor, which can inject the dependency in my EntityAware actions. Is it possible?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Dmitry_Zharikhin May 19, 2014
So, I finally won!
First, you actually can extend interceptor-stack.
from the examples we have xml structure like that:
<package name="example" extends="default" namespace="/example">
   <interceptors>
        <interceptor name="timer" class=".."/>
        <interceptor name="logger" class=".."/>
        <interceptor-stack name="myStack">
           <interceptor-ref name="timer"/>
           <interceptor-ref name="logger"/>
        </interceptor-stack>
    </interceptors>
<action name="login"
     class="tutuorial.Login">
         <interceptor-ref name="myStack"/>
         <result name="input">login.jsp</result>
         <result name="success"
             type="redirectAction">/secure/home</result>
</action>
</package>

But looking at the XWorkModuleDescriptor.java we can see that there's no handler for "interceptors" tag. So, if you want to declare the new one interceptor or stack you shoud reduce <interceptors> wrapper, like that:
<package name="example" extends="default" namespace="/example">
            <interceptor name="exampleInterceptor" class="com.confluence.plugin.ExampleInterceptor"/>
            <interceptor-stack name="exampleStack">
                <interceptor-ref name="exampleInterceptor"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
  <action name="login"
     class="tutuorial.Login">
         <interceptor-ref name="exampleStack"/>
<result name="input">login.jsp</result> <result name="success" type="redirectAction">/secure/home</result> </action> </package>

After that webwork framework will be able to create instances of your interceptor.

And now second. You must remember that inside framework instances are created with ObjectFactory using reflection. So, you must have default constructor with no params in your interceptor (to make newInstance() call successful). And that instance won't be autowired in any way even manually because webwork doesn't know about your plugins context.
For me that was a huge problem, so I found the way to get my plugins context with OSGi, but this is out of question.
Thank you for help!
0 votes
Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2014

I'm not sure, but try your own spring-application context in your plugin, maybe you can achieve your goal via this way.

Dmitry_Zharikhin May 13, 2014

So, I tried according to Advanced Configuration with Spring XML Files. It doesn't work.

There are some classpath issues, I think. Log message:

Caused by: Unable to find interceptor class referenced by ref-name customStack

Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2014

One more point, I think, this will only work in your bundle. If the code, you want to intercept is not in your bundle, you will have a problem.

Dmitry_Zharikhin May 14, 2014

The interceptor code is in my bundle near to actions, but it seems that interceptor stack building is more complicated and is predefined and not extensible for some reason. Even if I create interceptor bean directly from the local spring context.

The message in log is from method "constructInterceptorReference" so that seems to be some OSGi classpath issues

The extension mechanism for interceptors is defined in struts, but I didn't see any examples of such extension in atlassian docs and src.

So, for now I just want to be shure, that it's not possible.

Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2014

if you have classpath issues, find and add the missing dependencies to your plugin bundle. Just add the dependency with no scope to your plugin.

In my first post I was somehow on aop interceptors... :(

I'm not sure, if this is working, but you can try the conveyorlib and the conveyor-plugin.

Dmitry_Zharikhin May 19, 2014

That's pretty bad idea for any class instance which represents some service, it may cause non-clear OSGi issues.

This way can be used only for shurely local usage classes(and artefacts in general)

0 votes
Dmitry_Zharikhin May 13, 2014

Nobody deals with it? really?

TAGS
AUG Leaders

Atlassian Community Events