Bhushan
Bhushan

Reputation: 6181

make servlet filter applicable for all web applications in EAR

I am developing a web application using JSP & Servlets.

I have developed a servlet filter for Login purpose. Which checks whether user is logged in or not, if user is logged in then it allows access to the requested resource, else it redirects request to the Login page. And it works perfectly.

Web.xml

<filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>com.myfilter.MyFilter</filter-class>
    <init-param>
        <param-name>PARAM_NAME_HERE</param-name>
        <param-value>PARAM_VALUES_HERE</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

If I put above code in Tomcat Home-> conf-> Web.xml then the filter was applicable for all the applications deployed in Tomcat.(This is what I want to achieve in Glassfish for a EAR file)

But now for some reasons I have decided to shift to Glassfish. And now I have created A EAR file which contains two applications(WAR) 1.Login and 2. Profiles. Filter is in com.filter package which is in Login Application and not present in Profiles.

My question is that where should I put above XML code, which will make sure that the filter is applicable for All applications(WARs) in the EAR?

Update1

If I put above XML code in defualt-web.xml which is under the directory glassfish\domains\domain1\config\ then it is applicable for Login Applicaion but not for the Profiles application which is in the same EAR file.

There is Error in the log:
Exception starting filter MyFilterName java.lang.InstantiationException
.....
.....
Caused by: java.lang.ClassNotFoundException: com.myfilter.MyFilterName

[Note: Filter is in the Login application(WAR) and not in the Profiles application(WAR)]

So how should I make this applicable to Profiles(all WARs in EAR).

Upvotes: 1

Views: 1176

Answers (1)

Michael
Michael

Reputation: 10319

Put the jar contains your filter into glassfish\domains\domain1\lib folder

Upvotes: 1

Related Questions