Skip to Content

How to use j2ee Filters with SAP EP

This blog is about using j2ee Filters in SAP EP on SAP NetWeaver 7.0.

The Java Servlet specification version 2.3 introduces a new

component type, called a filter. A filter dynamically intercepts requests and

responses to transform or use the information contained in the requests or

responses. Filters typically do not themselves create responses, but instead

provide universal functions that can be “attached” to any type of

servlet or JSP page.

Generally, it is more efficient to modify the code to change the behavior of the resource itself rather than using filters to modify the resource. In some situations, using filters can add unnecessary complexity to an application and degrade performance. If you don’t have access to the source code, like with SAP EP, it is the only way to change the request  or response before it is send to the client.

For more information on Filters and their possible applications visit the  ( and/or  (

I will show you the 4 necessary steps to succesfully apply a Filter to SAP EP.

Step 1: Develop a Filter

Step 2: Create a library and deploy it

Step 3: Add a reference from SAP EP to the library

Step 4: Configure the Filter for SAP EP


Step 1: Develop a Filter

In NWDS you create a new Java project and add servlet.jar to the build path.


Create a new Java class which implements the javax.servlet.Filter interface. I will show you an easy example, quite unusefull actually, but you get the picture.This example will return a NOT_AUTHORIZED return code for every request made.

package com.topforce.filter;<br />import;<br /><br />import javax.servlet.Filter;<br />import javax.servlet.FilterChain;<br />import javax.servlet.FilterConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.ServletRequest;<br />import javax.servlet.ServletResponse;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />/*<br /><br />* To change the template for this generated type comment go to<br />* Window>Preferences>Java>Code Generation>Code and Comments<br />* @author Administrator<br />/<br />public class SystemsAvailableFilter implements Filter {<br />    /*<br />     * <br />     /<br />    private FilterConfig filterConfig = null;<br /><br />    public SystemsAvailableFilter() {<br />        super();<br />    }<br /><br />    / (non-Javadoc)<br />     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)<br />     /<br />    public void init(FilterConfig filterConfig) throws ServletException {<br />        this.filterConfig = filterConfig;<br />    }<br /><br />    / (non-Javadoc)<br />     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)<br />     /<br />    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {<br />        HttpServletRequest request = (HttpServletRequest)request;<br />        HttpServletResponse response = (HttpServletResponse)response; <br />        <br />        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);<br />    }<br /><br />    / (non-Javadoc)<br />     * @see javax.servlet.Filter#destroy()<br />     */<br />    public void destroy() {<br />        // TODO Auto-generated method stub<br />    }<br />}

Now create a jar file from your project by using the export function in NWDS. Remember where you put the jar, as you will need it in step 2.

Step 2: Create a library and deploy it

In NWDS now create a library project (located in the J2EE Server Component category).

Import the jar file you created in step 1, by right-clicking on the library project and select Import->File System->

Step 3: Add a reference from SAP EP to the library

Normally references between applications and libraries/services are being set during deployment. However you can create references after deployment without touching the original deployment xml files. You can use the Telnet Administration clinet for this. To start it open a command prompt and type:

telnet <host name> <telnet port>

By default the telnet port is 50008, but it could be different for your system. Login as an administrator.

Now jump to the right node using the command: jump 0

Now tell the engine that you want to modify the deployment references using the command: add deploy

And set the reference between the SAP Portal and your own custom library:

change_ref -m

That’s it. now quit the telnet session.

Create a refernce using telnet

The Portal application wil be restarted and you can check the results in Visual Administrator in the ClassLoader viewer:


1 Comment
You must be Logged on to comment or reply to a post.
  • Hi Peter,

    Given that there is no Visual Administrator in NW CE 7.11, instead you have the NW Administrator.
    Do you know how to add a reference from SAP EP to the library in NW CE 7.11?