views:

44

answers:

2

Hi ...

I'm trying to integration SAIF plugin to intercept my struts action. I learn from http://struts.sourceforge.net/saif/index.html

I've write configuration like this: struts-config.xml

<plug-in className="net.sf.struts.saif.SAIFPlugin">
    <set-property property="interceptor-config" value="/WEB-INF/interceptor-config.xml" />
</plug-in>

interceptor-config.xml

<interceptor-config>
 <interceptor name="componentInterceptor" type="net.sf.struts.saif.ComponentInterceptor"/>
 <interceptor name="testInterceptor" type="net.sf.struts.saif.TestInterceptor"/>

 <default-interceptors>
  <interceptor name="componentInterceptor"/>
 </default-interceptors>

 <action type="org.apache.struts.webapp.example.EditRegistrationAction">
  <interceptor name="testInterceptor"/>
 </action>
</interceptor-config> 

I got error like this:

javax.servlet.UnavailableException: Specified RequestProcessor not compatible with saif.
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)

can you help me to solve this problem ?

A: 

I haven't worked with the Struts Action Invocation Framework before but the exception message is familiar to me from Tiles. Tiles throws a message like this: Specified RequestProcessor not compatible with TilesRequestProcessor so I think that besides the familiarity of the message (in your case Specified RequestProcessor not compatible with saif) there is also a chance that the cause be the same.

Here is an article that fixes this on the Tiles plugin. Might help you.

When the Struts Servlet is initialized it does an init of all the plugins. The message should come from the init method of your plugin and if it is the same as Tiles then a test with Class.isAssignableFrom should be the cause.

EDIT: Looked up the source code for the SAIF plugin and found this in it:

protected void initRequestProcessorClass(ActionServlet servlet, ModuleConfig config) throws ServletException {
  .........
  .........
  ControllerConfig ctrlConfig = config.getControllerConfig();
  String configProcessorClassname = ctrlConfig.getProcessorClass();
  .........
  .........
  // Check if specified request processor is compatible with saif.
  try {
    Class saifProcessorClass = SAIFRequestProcessor.class;
    Class saifTilesProcessorClass = SAIFTilesRequestProcessor.class;
    Class configProcessorClass = Class.forName(configProcessorClassname);
    if (!saifProcessorClass.isAssignableFrom(configProcessorClass)
       && !saifTilesProcessorClass.isAssignableFrom(configProcessorClass)) {
      String msg = "Specified RequestProcessor not compatible with saif.";
      throw new ServletException(msg);
    }
  } catch (Exception ex) {
    throw new ServletException(ex);
  } 
  .........
  .........
}

It seems to be the same as with Tiles plugin so the article that I indicated contains the answer.

dpb
what you mean is create new SAIF Plugin extends and remove throw new ServletException(msg); ?I've try that way, But the method is not intercepted
adisembiring
SAIF Plugin throws that exception because it expects your application's request processor to be of type SAIFRequestProcessor, SAIFTilesRequestProcessor or a child of one of them (that is what the above test is doing). Your request processor is not of that type (maybe you have a custom one; any <controller> tag in your struts-config.xml?). You DO NOT extend the SAIFPlugin class and remove the "throw new ServletException(msg)"; that has a purpose there. If you remove it you are only silencing the exception, it won't mean that the plugin will work afterwards.
dpb
A: 

Quoting this message from the struts users mailing list:

It's unlikely that SAIF would work with the default S1.3 config since the request processor is different--you could try using the old request processor if your application doesn't rely on it.

AFAICT SAIF wouldn't work with anything other than the standard (old) request processor, but it might be possible to hack it up so it would.

Pascal Thivent