-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a3cf0e
commit 8952324
Showing
6 changed files
with
132 additions
and
28 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
core/src/main/java/com/flipkart/gjex/core/web/filter/HttpAccessLogFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.flipkart.gjex.core.web.filter; | ||
|
||
import com.flipkart.gjex.core.logging.Logging; | ||
import com.flipkart.gjex.core.service.Api; | ||
import com.google.inject.AbstractModule; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Filter for logging http access log requests | ||
* @author ajay.jalgaonkar | ||
* | ||
*/ | ||
|
||
@Singleton | ||
@Named("HttpAccessLogFilter") | ||
public class HttpAccessLogFilter implements Filter, Logging { | ||
private long startTime; | ||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException {} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
startTime = System.currentTimeMillis(); | ||
chain.doFilter(request, response); | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(request.getRemoteAddr()).append(" "); | ||
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse){ | ||
HttpServletRequest httpServletRequest= (HttpServletRequest) request; | ||
HttpServletResponse httpServletResponse = (HttpServletResponse) response; | ||
sb.append(httpServletRequest.getRequestURI()).append(" ") | ||
.append(httpServletResponse.getStatus()).append(" ") | ||
.append(httpServletResponse.getHeader("Content-Length")).append(" "); | ||
} else { | ||
sb.append("Did not get HTTP request").append(" "); | ||
} | ||
sb.append(System.currentTimeMillis()-startTime); | ||
error(sb.toString()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/com/flipkart/gjex/core/web/filter/HttpFilterParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.flipkart.gjex.core.web.filter; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import javax.servlet.Filter; | ||
|
||
/** | ||
* Parameters for creating http filters | ||
* @author ajay.jalgaonkar | ||
* | ||
*/ | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Builder | ||
public class HttpFilterParams { | ||
private final Filter filter; | ||
private final String pathSpec; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters