[opencms-dev] How to use filters in OpenCMS module

Lubomir Kovac kovman at centrum.cz
Wed Jan 3 21:25:22 CET 2007


Thanks all for answers. Fortunately I found the mistake. I was probably 
blind :-/

In my filter I have tried to use CmsJspBean and this is not allowed:
03 I 2007 20:52:15,031 ERROR [lina.core.StandardWrapperValve: 260] 
Servlet.service() for servlet default threw exception
org.opencms.main.CmsRuntimeException: "org.opencms.jsp.CmsJspBean" is 
usable only on a OpenCms controlled JSP page.

Is there a way, how to get a PageContext in filter? I have tried this code:

       /*JspFactory jspFactory = JspFactory.getDefaultFactory();
        PageContext pageContext = 
jspFactory.getPageContext(null,request,response, null, false, 
JspWriter.DEFAULT_BUFFER, true);
       
        CmsJspActionElement cmsJspActionElement = new 
CmsJspActionElement(pageContext, req, res);
         */
        CmsJspActionElement cmsJspActionElement = new CmsJspActionElement();

first I have tried to create PageContext with JspFactory, then I have 
tried to create CmsJspActionElement with no arguments. I need 
CmsJspActionElement to do:
         cmsJspActionElement.getRequestContext().getUri();
In first case I have used null instead of servlet, but I have no clue, 
how to do it correctly :-/

Or, is there another way, how to get this uri? uri without opencms 
prefixes, uri starting after /sites/default/ in filter?
I can't do it hard way (remove server and prefixes from request.getUri();

thanks :-)

kovi

Christian Steinert  wrote / napísal(a):
>> -----Ursprüngliche Nachricht-----
>> Von: The OpenCms mailing list <opencms-dev at opencms.org>
>> Gesendet: 02.01.07 23:26:01
>> An: opencms-dev at opencms.org
>> Betreff: [opencms-dev] How to use filters in OpenCMS module
>>     
>
>
>   
>> Hi,
>>
>> I have created an javax.servlet.Filter in my module. I have created the 
>> Filter class, loaded to OpenCMS, published it as usually . I have 
>> registered this filter class to opencms web.xml as I usually do with web 
>> application. I have restarted the web server (Tomcat 5.5) but the only 
>> answer was:
>>
>>
>>       A server error occured!
>>
>>
>>         Server error 500
>>
>>
>>       Internal Server Error
>>
>> The server encountered an unexpected condition which prevented it from 
>> fulfilling the request.
>>
>> The server cannot complete the request because it encountered an error.
>>
>> Please try it again in a few minutes, or contact the server administrator.
>>
>> Powered by OpenCms - the open source content management system 
>> <http://www.opencms.org>
>>
>>
>> My class name is: cz.zcu.fav.FavLoadFilter.java
>>
>> web.xml mapping I have added:
>>     <filter>
>>         <filter-name>FavLoadFilter</filter-name>
>>         <filter-class>cz.zcu.fav.filter.FavLoadFilter</filter-class>
>>     </filter>
>>     <filter-mapping>
>>          <filter-name>FavLoadFilter</filter-name>
>>          <url-pattern>/*</url-pattern>
>>     </filter-mapping>
>>
>>
>> 1. Whats wrong?
>> 2. Do I have to register it somewhere else?
>> 3. When I export the module, how this filter setting will be exported? 
>> Does the importer needs to do some correction itself?
>> 4. Is there any other way, how to work with filters? Or does something 
>> similar exist in OpenCMS?
>>
>> I was looking around and didn't find a thing.
>>
>> thanks for ideas
>>
>>     
>
> I have only one idea - I think it's a hostname problem with the pseudo-request from your servlet filter: the request management of opencms uses the hostname to determine which website should be served. For example if your server has two names site1.com and site2.com and if the client sent the request to www.site1.com/... then in the opencms configuration you define which website should be triggered.
>
> If you use a servlet filter, then I would imagine that the name of the target host is something like 'localhost' or 127.0.0.1 so you should try to add an additional website setting in opencms that maps these names and your main server name to the website that your servlet filter tries to reach.
>
> hth
> christian
> __________________________________________________________________________
> Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!		
> Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>   



More information about the opencms-dev mailing list