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