| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
package net.admin4j.util; |
| 15 | |
|
| 16 | |
import java.io.IOException; |
| 17 | |
import java.util.ArrayList; |
| 18 | |
import java.util.Enumeration; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.servlet.ServletConfig; |
| 22 | |
import javax.servlet.ServletException; |
| 23 | |
import javax.servlet.http.HttpServletRequest; |
| 24 | |
import javax.servlet.http.HttpSession; |
| 25 | |
|
| 26 | |
import net.admin4j.deps.commons.lang3.StringUtils; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 0 | public class ServletUtils { |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public static void reThrowServletFilterException(Throwable t) throws ServletException, |
| 42 | |
IOException { |
| 43 | 24 | if (t instanceof ServletException) { |
| 44 | 3 | throw (ServletException)t; |
| 45 | |
} |
| 46 | 21 | if (t instanceof IOException) { |
| 47 | 3 | throw (IOException) t; |
| 48 | |
} |
| 49 | 18 | if (t instanceof RuntimeException) { |
| 50 | 18 | throw (RuntimeException) t; |
| 51 | |
} |
| 52 | 0 | throw new ServletException(t); |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
@SuppressWarnings("rawtypes") |
| 61 | |
public static List<NameValuePair> listSessionAttributes(HttpSession session) { |
| 62 | 18 | List<NameValuePair> list = new ArrayList<NameValuePair>(); |
| 63 | 18 | Enumeration attrNames = session.getAttributeNames(); |
| 64 | |
String name; |
| 65 | |
Object value; |
| 66 | |
|
| 67 | 24 | while (attrNames.hasMoreElements()) { |
| 68 | 6 | name = (String)attrNames.nextElement(); |
| 69 | 6 | value = session.getAttribute(name); |
| 70 | |
|
| 71 | 6 | list.add(new NameValuePair(name, value.toString())); |
| 72 | |
} |
| 73 | |
|
| 74 | 18 | return list; |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
@SuppressWarnings("rawtypes") |
| 83 | |
public static List<NameValuePair> listRequestAttributes(HttpServletRequest request) { |
| 84 | |
|
| 85 | 27 | List<NameValuePair> list = new ArrayList<NameValuePair>(); |
| 86 | 27 | Enumeration parmNames = request.getParameterNames(); |
| 87 | |
String name; |
| 88 | |
Object value; |
| 89 | |
|
| 90 | 36 | while (parmNames.hasMoreElements()) { |
| 91 | |
|
| 92 | 9 | name = (String)parmNames.nextElement(); |
| 93 | 9 | if ("javax.faces.ViewState".equals(name)) |
| 94 | |
{ |
| 95 | 0 | value = "[suppressed]"; |
| 96 | |
} |
| 97 | |
else |
| 98 | |
{ |
| 99 | 9 | value = request.getParameter(name); |
| 100 | |
} |
| 101 | |
|
| 102 | 9 | list.add(new NameValuePair(name, value.toString())); |
| 103 | |
} |
| 104 | |
|
| 105 | 27 | return list; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
public static String getApplicationName(HttpServletRequest request) { |
| 114 | 18 | return request.getRequestURI().substring(1, request.getRequestURI().indexOf("/", 1)); |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
public static String getConfigurationSetting(String[] settingKeysInPrecedenceOrder, ServletConfig config) { |
| 125 | 75 | String value = null; |
| 126 | 162 | for (String key: settingKeysInPrecedenceOrder) { |
| 127 | 114 | value = config.getInitParameter(key); |
| 128 | 0 | if (!StringUtils.isEmpty(value)) { |
| 129 | 27 | return value; |
| 130 | |
} |
| 131 | |
} |
| 132 | |
|
| 133 | 48 | return value; |
| 134 | |
} |
| 135 | |
|
| 136 | |
} |