1 19 20 package com.sslexplorer.core.stringreplacement; 21 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 27 public class ServletRequestReplacer extends AbstractReplacementVariableReplacer { 28 29 private HttpServletRequest request; 30 31 public ServletRequestReplacer(HttpServletRequest request) { 32 super(); 33 this.request = request; 34 } 35 36 @Override 37 public String processReplacementVariable(Pattern pattern, Matcher matcher, 38 String replacementPattern, String type, String key) 39 throws Exception { 40 if (type.equalsIgnoreCase("request")) { 41 if (request == null) { 42 return null; 43 } else if (key.equals("serverName")) { 44 return request.getServerName(); 45 } else if (key.equals("serverPort")) { 46 return String.valueOf(request.getServerPort()); 47 } else if (key.startsWith("param.")) { 48 return request.getParameter(key.substring(6)); 49 } else if (key.startsWith("attr.")) { 50 return request.getAttribute(key.substring(5)).toString(); 51 } else if (key.equals("userAgent")) { 52 return request.getHeader("User-Agent"); 53 } 54 } 55 return null; 56 } 57 } | Popular Tags |