1 | <%-- |
---|
2 | See http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html |
---|
3 | http://www.informit.com/articles/article.aspx?p=30946&seqNum=7 |
---|
4 | --%> |
---|
5 | |
---|
6 | <%@ page import="java.util.*, java.net.*,java.io.*"%> |
---|
7 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> |
---|
8 | |
---|
9 | |
---|
10 | <% |
---|
11 | String s="x"; |
---|
12 | String urlAddress = request.getParameter("url"); |
---|
13 | |
---|
14 | int size = 0; |
---|
15 | String compressed = null; |
---|
16 | if(request.getParameter("compress") != null) compressed = "checked"; |
---|
17 | HttpURLConnection huc = null; |
---|
18 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
19 | Set propertiesKeySet = null; |
---|
20 | if(urlAddress != null) |
---|
21 | { |
---|
22 | try |
---|
23 | { |
---|
24 | URL url = new URL(urlAddress); |
---|
25 | huc = (HttpURLConnection)url.openConnection(); |
---|
26 | huc.setRequestProperty("user-agent", "Mozilla(MSIE)"); |
---|
27 | if(compressed == null) |
---|
28 | huc.setRequestProperty("accept-encoding", ""); |
---|
29 | else |
---|
30 | huc.setRequestProperty("accept-encoding", "gzip"); |
---|
31 | propertiesKeySet = huc.getRequestProperties().keySet(); // get these before open connection... |
---|
32 | huc.connect(); |
---|
33 | InputStream is = huc.getInputStream(); |
---|
34 | int i = 0; |
---|
35 | while(i != -1) |
---|
36 | { |
---|
37 | i = is.read(); |
---|
38 | if(i != -1) baos.write(i); |
---|
39 | } |
---|
40 | baos.flush(); |
---|
41 | baos.close(); |
---|
42 | byte[] b1 = baos.toByteArray(); |
---|
43 | size = b1.length; |
---|
44 | } |
---|
45 | catch(Exception e) { e.printStackTrace(); } |
---|
46 | } |
---|
47 | |
---|
48 | if(urlAddress == null) urlAddress = "http://ibis.health.utah.gov/home/Welcome.html"; |
---|
49 | %> |
---|
50 | |
---|
51 | <% String pageTitle = "IBIS-PH - HTTP Test/Information"; %> |
---|
52 | |
---|
53 | <html> |
---|
54 | |
---|
55 | <head> |
---|
56 | |
---|
57 | <%@include file="WEB-INF/jsp/_head.jsp"%> |
---|
58 | |
---|
59 | <style> |
---|
60 | #page |
---|
61 | { |
---|
62 | background-color: white; |
---|
63 | padding: 8px; |
---|
64 | width:850px; |
---|
65 | } |
---|
66 | table.Info |
---|
67 | { |
---|
68 | width: 100%; |
---|
69 | } |
---|
70 | th.Section |
---|
71 | { |
---|
72 | width: 180px; |
---|
73 | } |
---|
74 | </style> |
---|
75 | </head> |
---|
76 | |
---|
77 | <body><table id="page"><tr><td> |
---|
78 | |
---|
79 | <div id="content"> |
---|
80 | <h1>HTTP Info And Content Test Page</h1> |
---|
81 | |
---|
82 | <h2>Request Content Test</h2> |
---|
83 | <table border="1" class="Info"> |
---|
84 | <tr class="Title"><th colspan="2">Submission Control</th></tr> |
---|
85 | <tr> |
---|
86 | <th class="Section">Test URL</th> |
---|
87 | <td> |
---|
88 | <form action="http_test.jsp" method="POST"> |
---|
89 | <input name="url" size="80" value="<%=urlAddress%>"><br/> |
---|
90 | <input type="checkbox" name="compress" value="true" <%=compressed%> >Accept GZIP<br/> |
---|
91 | <input type="submit" value=" Submit "> |
---|
92 | </form> |
---|
93 | </td> |
---|
94 | </tr> |
---|
95 | |
---|
96 | <%if(huc != null) { %> |
---|
97 | <tr class="Title"><th colspan="2">Connection Info</th></tr> |
---|
98 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
99 | <tr><th class="Section">Content Encoding</th> <td class="Info"><%=huc.getContentEncoding()%> </td></tr> |
---|
100 | <tr><th class="Section">Content Length</th> <td class="Info"><%=huc.getContentLength()%> </td></tr> |
---|
101 | <tr><th class="Section">Default Use Caches</th><td class="Info"><%=huc.getDefaultUseCaches()%> </td></tr> |
---|
102 | <tr><th class="Section">Expiration</th> <td class="Info"><%=huc.getExpiration()%> </td></tr> |
---|
103 | |
---|
104 | <tr class="Title"><th colspan="2">Request Headers</th></tr> |
---|
105 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
106 | <% |
---|
107 | Map headerFieldsMap = huc.getHeaderFields(); |
---|
108 | Set keySet = headerFieldsMap.keySet(); |
---|
109 | Iterator it = keySet.iterator(); |
---|
110 | while(it.hasNext() && huc != null) |
---|
111 | { |
---|
112 | Object o = it.next(); |
---|
113 | s = (String)o; |
---|
114 | out.print("<tr><th class=\"Section\">"); |
---|
115 | out.print(s); |
---|
116 | out.print("</hd><td>"); |
---|
117 | out.print(huc.getHeaderField(s)); |
---|
118 | out.println("</td></tr>"); |
---|
119 | } |
---|
120 | %> |
---|
121 | |
---|
122 | <tr class="Title"><th colspan="2">Request Properties</th></tr> |
---|
123 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
124 | <% |
---|
125 | it = propertiesKeySet.iterator(); |
---|
126 | while(it.hasNext() && huc != null) |
---|
127 | { |
---|
128 | Object o = it.next(); |
---|
129 | s = (String)o; |
---|
130 | out.print("<tr><th class=\"Section\">"); |
---|
131 | out.print(s); |
---|
132 | out.print("</th><td>"); |
---|
133 | out.print(huc.getRequestProperty(s)); |
---|
134 | out.println("</td></tr>"); |
---|
135 | } |
---|
136 | %> |
---|
137 | |
---|
138 | <tr class="Title"><th colspan="2">Content Returned</th></tr> |
---|
139 | <tr> |
---|
140 | <td colspan="2"> |
---|
141 | <textarea rows="10" cols="150" style="font-size: smaller"> |
---|
142 | <%=baos.toString()%> |
---|
143 | </textarea><br/> |
---|
144 | Size (bytes): <%=size%> |
---|
145 | </td> |
---|
146 | </tr> |
---|
147 | <%}%> |
---|
148 | </table><br/> |
---|
149 | |
---|
150 | |
---|
151 | <h2>Info About This JSP Page Request</h2> |
---|
152 | <table border="1" class="Info"> |
---|
153 | |
---|
154 | <tr class="Title"><th colspan="2">Request Properties</th></tr> |
---|
155 | <tr class="Section"><th>Item</th><th>Value</th></tr> |
---|
156 | <tr><th class="Section">Request URL</th> <td class="Info"><%=request.getRequestURL()%> </td></tr> |
---|
157 | <tr><th class="Section">Request URI</th> <td class="Info"><%=request.getRequestURI()%> </td></tr> |
---|
158 | <tr><th class="Section">Context Path</th> <td class="Info"><%=request.getContextPath()%> </td></tr> |
---|
159 | <tr><th class="Section">Servlet Path</th> <td class="Info"><%=request.getServletPath()%> </td></tr> |
---|
160 | <tr><th class="Section">Path Info</th> <td class="Info"><%=request.getPathInfo()%> </td></tr> |
---|
161 | <tr><th class="Section">Query Str</th> <td class="Info"><%=request.getQueryString()%> </td></tr> |
---|
162 | <tr><th class="Section">Locale</th> <td class="Info"><%=request.getLocale()%> </td></tr> |
---|
163 | <tr><th class="Section">Character Encoding</th><td class="Info"><%=request.getCharacterEncoding()%> </td></tr> |
---|
164 | <tr><th class="Section">Scheme</th> <td class="Info"><%=request.getScheme()%> </td></tr> |
---|
165 | <tr><th class="Section">Server Name</th> <td class="Info"><%=request.getServerName()%> </td></tr> |
---|
166 | <tr><th class="Section">Local Addr</th> <td class="Info"><%=request.getLocalAddr()%> </td></tr> |
---|
167 | <tr><th class="Section">Remote Addr</th> <td class="Info"><%=request.getRemoteAddr()%> </td></tr> |
---|
168 | <tr><th class="Section">Remote Host</th> <td class="Info"><%=request.getRemoteHost()%> </td></tr> |
---|
169 | <tr><th class="Section">Remote User</th> <td class="Info"><%=request.getRemoteUser()%> </td></tr> |
---|
170 | <tr><th class="Section">Auth Type</th> <td class="Info"><%=request.getAuthType()%> </td></tr> |
---|
171 | |
---|
172 | <tr class="Title"><th colspan="2">Request Parameters</th></tr> |
---|
173 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
174 | <% |
---|
175 | String [] sa; |
---|
176 | Enumeration e = request.getParameterNames(); |
---|
177 | if(e != null) |
---|
178 | while(e.hasMoreElements()) |
---|
179 | { |
---|
180 | s = (String)e.nextElement(); |
---|
181 | if(s != null) |
---|
182 | { |
---|
183 | sa = request.getParameterValues(s); |
---|
184 | for(int i=0; i< sa.length; i++) |
---|
185 | { |
---|
186 | out.print("<tr><th class=\"Section\">"); |
---|
187 | out.print(s); |
---|
188 | out.print("</th><td>"); |
---|
189 | out.print(i); |
---|
190 | out.print(" - "); |
---|
191 | out.print(sa[i]); |
---|
192 | out.println("</td></tr>"); |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | %> |
---|
197 | |
---|
198 | <tr class="Title"><th colspan="2">Request Headers</th></tr> |
---|
199 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
200 | <% |
---|
201 | e = request.getHeaderNames(); |
---|
202 | String headerName; |
---|
203 | while(e.hasMoreElements()) |
---|
204 | { |
---|
205 | headerName = (String)e.nextElement(); |
---|
206 | out.print("<tr><th class=\"Section\">"); |
---|
207 | out.print(headerName); |
---|
208 | out.print("</th><td>"); |
---|
209 | s = request.getHeader(headerName); |
---|
210 | if((s != null) && (s.length() > 60)) |
---|
211 | out.print("<textarea rows='3' style='width:95%;'>" + s + "</textarea>"); |
---|
212 | else |
---|
213 | out.print(s); |
---|
214 | out.println("</td></tr>"); |
---|
215 | } |
---|
216 | %> |
---|
217 | |
---|
218 | <tr class="Title"><th colspan="2">Cookies</th></tr> |
---|
219 | <tr class="Section"><th>Name</th><th>Value</th></tr> |
---|
220 | <c:forEach var="p" items="${cookie}"> |
---|
221 | <tr><th class="Section">${p.key}</th><td class="Info">${p.value}</td></tr> |
---|
222 | </c:forEach> |
---|
223 | |
---|
224 | </table> |
---|
225 | </div> |
---|
226 | |
---|
227 | </td></tr></table></body> |
---|
228 | </html> |
---|