Reputation: 1
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
Reputation: 5115
Upvotes: 0
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