| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<!-- |
| 5 |
|
| 6 |
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 7 |
|
| 8 |
Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. |
| 9 |
|
| 10 |
The contents of this file are subject to the terms of either the GNU |
| 11 |
General Public License Version 2 only ("GPL") or the Common Development |
| 12 |
and Distribution License("CDDL") (collectively, the "License"). You |
| 13 |
may not use this file except in compliance with the License. You can |
| 14 |
obtain a copy of the License at |
| 15 |
http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 16 |
or packager/legal/LICENSE.txt. See the License for the specific |
| 17 |
language governing permissions and limitations under the License. |
| 18 |
|
| 19 |
When distributing the software, include this License Header Notice in each |
| 20 |
file and include the License file at packager/legal/LICENSE.txt. |
| 21 |
|
| 22 |
GPL Classpath Exception: |
| 23 |
Oracle designates this particular file as subject to the "Classpath" |
| 24 |
exception as provided by Oracle in the GPL Version 2 section of the License |
| 25 |
file that accompanied this code. |
| 26 |
|
| 27 |
Modifications: |
| 28 |
If applicable, add the following below the License Header, with the fields |
| 29 |
enclosed by brackets [] replaced by your own identifying information: |
| 30 |
"Portions Copyright [year] [name of copyright owner]" |
| 31 |
|
| 32 |
Contributor(s): |
| 33 |
If you wish your version of this file to be governed by only the CDDL or |
| 34 |
only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 35 |
elects to include this software in this distribution under the [CDDL or GPL |
| 36 |
Version 2] license." If you don't indicate a single choice of license, a |
| 37 |
recipient has the option to distribute your version of this file under |
| 38 |
either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 39 |
its licensees as provided above. However, if you add GPL Version 2 code |
| 40 |
and therefore, elected the GPL Version 2 license, then the option applies |
| 41 |
only if the new code is made subject to such option by the copyright |
| 42 |
holder. |
| 43 |
|
| 44 |
--> |
| 45 |
|
| 46 |
<title></title> |
| 47 |
<script language="Javascript"> |
| 48 |
|
| 49 |
var baseURL = "/SimpleServlet/resources" |
| 50 |
|
| 51 |
function xmlhttpGet(strURL, mimeType) { |
| 52 |
log('xmlhttpGet'); |
| 53 |
var xmlHttpReq; |
| 54 |
if (window.XMLHttpRequest) { // Mozilla, Safari, ... |
| 55 |
xmlHttpReq = new XMLHttpRequest(); |
| 56 |
} else if (window.ActiveXObject) { // IE |
| 57 |
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); |
| 58 |
} |
| 59 |
log(xmlHttpReq); |
| 60 |
updatepage('request', strURL); |
| 61 |
xmlHttpReq.open('GET', strURL, true); |
| 62 |
log("open"); |
| 63 |
if (mimeType != null) |
| 64 |
xmlHttpReq.setRequestHeader('Accept', mimeType); |
| 65 |
xmlHttpReq.onreadystatechange = function() { updateState(xmlHttpReq); }; |
| 66 |
xmlHttpReq.send(null); |
| 67 |
} |
| 68 |
|
| 69 |
function updateState(xmlHttpReq) { |
| 70 |
try { |
| 71 |
if (xmlHttpReq.readyState == 4) { |
| 72 |
updatepage('result', "<html><body>"+xmlHttpReq.responseText+"</body></html>"); |
| 73 |
updatepage('resultheaders', xmlHttpReq.getAllResponseHeaders()); |
| 74 |
} else |
| 75 |
log("state: "+xmlHttpReq.readyState); |
| 76 |
} catch( e ) { |
| 77 |
alert('Caught Exception1: ' + e.description); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
function getRep() { |
| 82 |
var resource = document.getElementById('mimeType'); |
| 83 |
log("selector "+resource.name); |
| 84 |
return resource.selectedIndex; |
| 85 |
} |
| 86 |
|
| 87 |
function getSelMethod() { |
| 88 |
for (counter = 0; counter < form1.selMethod.length; counter++) { |
| 89 |
// If a radio button has been selected it will return true |
| 90 |
// (If not it will return false) |
| 91 |
if (form1.selMethod[counter].checked) |
| 92 |
return form1.selMethod[counter].value; |
| 93 |
} |
| 94 |
return null; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
function getParam1() { |
| 99 |
var value = form1.param1.value; |
| 100 |
if (value == undefined || value == "") |
| 101 |
value = null; |
| 102 |
return value |
| 103 |
} |
| 104 |
|
| 105 |
function getParam2() { |
| 106 |
var value = form1.param2.value; |
| 107 |
if (value == undefined || value == "") |
| 108 |
value = null; |
| 109 |
return value |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
function getquerystring() { |
| 114 |
log('getquerystring'); |
| 115 |
var wordvalue = getRep(); |
| 116 |
if (wordvalue == undefined || wordvalue == "") |
| 117 |
qstr = null; |
| 118 |
else |
| 119 |
qstr = 'rep=' + escape(wordvalue); // NOTE: no '?' before querystring |
| 120 |
return qstr; |
| 121 |
} |
| 122 |
|
| 123 |
function updatepage(id, str){ |
| 124 |
log('updatepage: '+id+" str: "+str); |
| 125 |
document.getElementById(id).innerHTML = str; |
| 126 |
} |
| 127 |
function hideall() { |
| 128 |
setvisibility('test3', 'hidden'); |
| 129 |
} |
| 130 |
|
| 131 |
function setvisibility(id,state) { |
| 132 |
try { |
| 133 |
document.getElementById(id).style.visibility = state; |
| 134 |
} catch(e) {} |
| 135 |
} |
| 136 |
|
| 137 |
function clearAll() { |
| 138 |
updatepage('request', ''); |
| 139 |
updatepage('result', ''); |
| 140 |
updatepage('resource', ''); |
| 141 |
} |
| 142 |
|
| 143 |
function getSelectorValue(selectorId) { |
| 144 |
var resource = document.getElementById(selectorId); |
| 145 |
log("selector "+resource.name); |
| 146 |
var myIndex = resource.selectedIndex; |
| 147 |
log("index: " +myIndex); |
| 148 |
log(resource.options); |
| 149 |
log(resource.options[myIndex].value); |
| 150 |
return resource.options[myIndex].value |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
function testResource() { |
| 155 |
clearAll(); |
| 156 |
log('testResource'); |
| 157 |
var selectedValue = getSelectorValue('resourceId'); |
| 158 |
setvisibility('result', 'inherit'); |
| 159 |
updatepage('resource', "Resource "+selectedValue); |
| 160 |
var req = ''; |
| 161 |
if (selectedValue == 1) { |
| 162 |
setvisibility('test3', 'hidden'); |
| 163 |
req = baseURL+"/resource1"; |
| 164 |
updatepage('request', req); |
| 165 |
xmlhttpGet(req, null); |
| 166 |
} else if (selectedValue == 2) { |
| 167 |
setvisibility('test3', 'hidden'); |
| 168 |
req = baseURL+"/resource2"; |
| 169 |
updatepage('request', req); |
| 170 |
xmlhttpGet(req, null); |
| 171 |
} else if (selectedValue == 3) { |
| 172 |
setvisibility('test3', 'inherit'); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
function testResource3() { |
| 178 |
var selMethod = getSelMethod(); |
| 179 |
var rep = getRep(); |
| 180 |
var mimetype = getSelectorValue('mimeType'); |
| 181 |
var req = baseURL+"/resource3/"+getParam1()+"/"+getParam2(); |
| 182 |
if (selMethod == 'QueryParam') { |
| 183 |
req = req+"?rep="+rep; |
| 184 |
mimetype = null; |
| 185 |
} |
| 186 |
updatepage('request', req); |
| 187 |
updatepage('amimetype', mimetype); |
| 188 |
if (rep == 3) { |
| 189 |
if (mimetype == null) |
| 190 |
updatepage('result', "<html><body><img src='"+req+"'/></body></html>"); |
| 191 |
else { |
| 192 |
alert('The image/jpg MimeType currently does not work with the MimeType selection method.\nInstead of seeing the image, you will see the image data'); |
| 193 |
xmlhttpGet(req, mimetype); |
| 194 |
} |
| 195 |
} else |
| 196 |
xmlhttpGet(req, mimetype); |
| 197 |
} |
| 198 |
|
| 199 |
function onProgress(e) { |
| 200 |
var percentComplete = (e.position / e.totalSize)*100; |
| 201 |
status("percentComplete: "+percentComplete); |
| 202 |
} |
| 203 |
|
| 204 |
function initResource3() { |
| 205 |
form1.word.value = 1; |
| 206 |
} |
| 207 |
|
| 208 |
function onError(e) { |
| 209 |
status("Error " + e.target.status + " occurred while receiving the document."); |
| 210 |
} |
| 211 |
|
| 212 |
function onLoad(e) { |
| 213 |
} |
| 214 |
|
| 215 |
function log(msg) { |
| 216 |
document.getElementById('log').innerHTML = msg; |
| 217 |
} |
| 218 |
|
| 219 |
function status(msg) { |
| 220 |
} |
| 221 |
|
| 222 |
function changeMime() { |
| 223 |
var mimeType = docuemt.getElementById('mimeType'); |
| 224 |
mimeType.selectedIndex = 0; |
| 225 |
} |
| 226 |
|
| 227 |
</script> |
| 228 |
|
| 229 |
|
| 230 |
</head> |
| 231 |
<body onload="hideall()"> |
| 232 |
<form action="" name="base"> |
| 233 |
<b>Select Resource to test:</b> <br><br> |
| 234 |
<select name="ressel" id="resourceId"> |
| 235 |
<option value=1 selected>Resource 1</option> |
| 236 |
<option value=2>Resource 2</option> |
| 237 |
<option value=3>Resource 3</option> |
| 238 |
</select><br><br> |
| 239 |
<input value="Test Resource" type="button" onclick='testResource()'></p> |
| 240 |
</form> |
| 241 |
<div id="test3"> |
| 242 |
<hr> |
| 243 |
<b>Resource 3 Inputs:</b><br><br> |
| 244 |
<form action="" method=GET name="form1"> |
| 245 |
<b>Param1:</b> |
| 246 |
<input name="param1" type="text" value="fred"><br><br> |
| 247 |
<b>Param2:</b> |
| 248 |
<input name="param2" type="text" value="barney"><br><br> |
| 249 |
<b>Selection method:</b> |
| 250 |
<input name="selMethod" type="radio" value="QueryParam" checked="true">Query Parameter |
| 251 |
<input name="selMethod" type="radio" value="MimeType">MimeType |
| 252 |
<br><br> |
| 253 |
<b>MimeType:</b> |
| 254 |
<select name=rep id="mimeType"> |
| 255 |
<option selected value="">none specified</option> |
| 256 |
<option value="text/plain">text/plain</option> |
| 257 |
<option value="application/x-www-form-urlencoded">application/x-www-form-urlencoded</option> |
| 258 |
<option value="image/jpg">image/jpg</option> |
| 259 |
</select><BR> |
| 260 |
<input value="Test Resource 3" type="button" onclick='testResource3()')'> |
| 261 |
</form> |
| 262 |
</div> |
| 263 |
<hr> |
| 264 |
<!--------------------------------------------------> |
| 265 |
<div id="details"> |
| 266 |
<b>Test Details:</b><br><br> |
| 267 |
<b>Resource:</b><div id="resource"></div><br> |
| 268 |
<b>Request:</b> <div id="request"></div><br> |
| 269 |
<b>Query:</b> <div id="query"></div><br> |
| 270 |
<b>Accept MimeType:</b> <div id="amimetype"></div><br> |
| 271 |
<b>Result Headers:</b> <div id="resultheaders"></div> |
| 272 |
<b>Result:</b> <div id="result"></div> |
| 273 |
</div> |
| 274 |
<hr> |
| 275 |
<b>Debug Log:</b><div id="log"></div> |
| 276 |
</body> |
| 277 |
</html> |
| 278 |
|