aspose file tools*
The moose likes Servlets and the fly likes problem while giving a url pattern in filter mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem while giving a url pattern in filter mapping" Watch "problem while giving a url pattern in filter mapping" New topic
Author

problem while giving a url pattern in filter mapping

Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
Hello Everyone,

I am faced with a small challenge, where in I have one filter which is as below -
<filter>
<filter-name>SumitFilter</filter-name>
<filter-class>filter class name here</filter-class>
</filter>

<filter-mapping>
<filter-name>SumitFilter</filter-name>
<url-pattern>?</url-pattern>
</filter-mapping>

Now, the issue is that I want this filter to be applicable for all urls except one.

Let the url for which I dont want to use the filter is
http://com.uk.sumit.com:9250/nofilter/DontLikeFilter

Can somebody tell me how to do this ??

Many thanks,
Sumit Ranjan
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
I dont think that you can do this with the filter mapping.

Why not check in the filter for the excluded URL and do nothing if yo have this URL?
[ September 27, 2007: Message edited by: Michael Ku ]
Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
I dont think that you can do this with the filter mapping.

Why not check in the filter for the excluded URL and do nothing if yo have this URL?


Michael,

First of all my sincere thanks for replying to my query.. Now, coming to the problem let me tell you something more about the problem.. probably then, you would be able to tell me something. The filter that I showed in my post earlier, is a filter for Janus, used for Authentication for Web applications in my work place. I dont have the code or control to change their code. Now, what I want is that any request to access my web app coming should go through this JANUS authentication server except for a special case where the request comes from a third party tool and we dont want to authenticate them using Janus.

So, the idea here is if the request comes from any other URL other than the privelleged people who we dont want to mess with.. put Janus in the middle and let them prove that they have access to our APP..

Now, I guess you know the problem better..

Any suggestions how to achieve this ??

Thanks and Regards,
Sumit
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Yes, create a new filter to do what I suggested. If the condition is true then stop the execution of the filter chain and go where you want. You don't need the filter code to do this. This new filter would run before the janus filter.
[ September 27, 2007: Message edited by: Michael Ku ]
Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
Michael,

Apologies for the late reply and for not giving more information on the problem itself. Here is the info you might find useful to understand the problem -

1.) The application has 2 servlets,first one is ActionServlet provided by Struts which is the one that is used to access the application by our team.

2.) We have another servlet (say XYZServlet) which has been written specifically for the external system I specified above as they donot want access to our entire application and all that they need is being taken care of by this servlet.(Like fetching some records from our database and render it on their application)

3.)The <url-pattern> for this XYZServlet is /XYZServlet and that for the Action Servlet is *.do

4.)In an ideal situation, what I would want is that when I migrate our application to Janus Authentication Server using the Janus filter, all i need to protect is the ActionServlet(As that is wht is invoked when anyone invokes the URL of our application).So, in the <url-pattern> for Janus filter, i tried putting the element <servlet-name>action</servlet-name> instead of <url-pattern>/*</url-pattern>.

5.) With the above mentioned change, the third party is able to access the XYZServlet, but then in this case, the janus doesnt get invoked when we try to access our Webapp via the usual url that we had.

6.) Interesting thing to note here is,the context path(Say /root) is common whether i try to access the XYZServlet or the app via ActionServlet which is stored in the Tomcat Server parallel to ROOT.xml

So, I am hoping if somehow I am able to remove this context path in the call to XYZServlet, then probably I would be able to access it as

http:<...>:<port>/XYZServlet instead of http:<...>:<port>/root/XYZServlet
as I am doing it now. So, then even a url pattern of /* for the Janus filter wont act on the request to XYZServlet.(I am assuming a filter url pattern of /* would mean /root/* as the context is added for every request.)
Any help to solve the above would be much appreciated.

Thanks and Regards,
Sumit
Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
I also tried implementing a filter class for my problem as Michael said. This is how it looks -



Now, I think I can try putting the url pattern for CheopsFilter as /*. Meaning, I would expect my filter CheopsFilter to get invoked for every request and then pass on the request to either XYZServlet or JanusFilter depending on who is requesting - the third party system or someone else ?

But, even in that case, what urlpattern should i give for Janus Filter ??

Thanks in advance,
Sumit

[ October 10, 2007: Message edited by: Sumit Ranjan ]
[ October 10, 2007: Message edited by: Sumit Ranjan ]
Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
Hi Friends,

Forgive me for my impatience,Can somebody give me some guidance as to how to solve my problem ? If you need any more information please let me know. I would be more than happy to provide any information that can help you understand the problem.. and help me to solve it!!!

Cheers,
Sumit
Sumit Ranjan
Greenhorn

Joined: Dec 20, 2005
Posts: 24
Hello Ranchers,

Can someone help me with my doubt please.

Thanks a lot for your help in advance !!!

Sumit
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sumit Ranjan:
/* Here I would like to do something like this */

if (the request is from the third party system that wants to access just the XYZservlet)
then pass then control to XYZServlet
else

Call the filter for Janus to handle all other requests.

// Not sure how to invoke this ? [/b]chain.doFilter(request,response);
}

public void destroy() {
}
} [/CODE]


Put your filter before the Janus filter.
Give it a mapping that matches the URL that is exempt from Janus Authenitication.
In that filter, forward directly to your action servlet (or whichever servlet you want to service these requests).
Do not call filter.doChain.

By not calling doChain, you will break out of the filter chain, bypassing Janus.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem while giving a url pattern in filter mapping