Rana Asghar
Rana Asghar

Reputation: 1

Websphere Application Server: web.xml location for servlet deployment descriptor and log file location where a filter servlet will log

I have deployed a filter in Tomcat which logs the URLs and a request parameter for all servlets. Now I want to deploy the same in Websphere Application server. 1. Where to copy my Filter Class file? 2. Location of web.xml in which I have to enter the Filter class deployment descriptor xml tags. 3. The log file in which the filter class will log the URLs and request parameters.

Below is the code of my Filter class.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;

import java.util.Date;

public class T24RequestTime implements Filter {

  private FilterConfig config = null;

  Date dt = new Date();

  public void init(FilterConfig config) throws ServletException {

    this.config = config;

  }

  public void destroy() {

    config = null;

  }

  public void doFilter(ServletRequest request, ServletResponse response,

                     FilterChain chain) throws IOException, ServletException {

    long before = System.currentTimeMillis();

    chain.doFilter(request, response);

    long after = System.currentTimeMillis();

    SimpleDateFormat dateFormat = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss]");

    String endDate = dateFormat.format(new Date());    

    String name = "";

    if (request instanceof HttpServletRequest) {

      name = ((HttpServletRequest)request).getRequestURI();

    }

    config.getServletContext().log("T24: !Date-Time: !"+endDate+ "! Total Elapsed Time: !" +         (after - before) + "!ms!"+"! Company: !"+((HttpServletRequest)request).getParameter("companyId")+"! User: !"+((HttpServletRequest)request).getParameter("user")+"! Version: !"+((HttpServletRequest)request).getParameter("version")+"! Application: !"+((HttpServletRequest)request).getParameter("application")+"! Routine Name: !"+((HttpServletRequest)request).getParameter("routineName")+"! Timing: !"+((HttpServletRequest)request).getParameter("timing")+"! URL: !"+ name );

    System.out.println("fsfsfsd");

  }
}

Upvotes: 0

Views: 6640

Answers (2)

Doug Breaux
Doug Breaux

Reputation: 5115

  1. Your filter class file should usually be deployed into your WAR file along with the other application classes. If you want to apply this filter to multiple applications without deploying to each, see this article on using common application files.
  2. Unlike Tomcat, WebSphere doesn't have a shared/global web.xml, so you'll have to configure the filter in each WAR's web.xml.

Upvotes: 0

home
home

Reputation: 12538

In WebSphere you should really deploy the whole EAR file. Do not try to modify the deployment descriptors (web.xml, etc.) after deployment. After changing a deployment descriptor you should build and redeploy. Believe me, everything else will not work or at least generate trouble in operations.

Per default WebSphere logs to <profilepath>/logs/<servername> into SystemOut.log or trace.txt. Logging configuration depends on your environment.

Upvotes: 2

Related Questions