comparison src/org/eclipse/jetty/server/Request.java @ 809:09d518d313b7

remove SessionManager
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Sep 2016 16:38:30 -0600
parents 3428c60d7cfc
children 1bedcd0ec275
comparison
equal deleted inserted replaced
808:b3176fd168bf 809:09d518d313b7
125 * 125 *
126 * 126 *
127 */ 127 */
128 public class Request implements HttpServletRequest 128 public class Request implements HttpServletRequest
129 { 129 {
130 public static final String __MULTIPART_CONFIG_ELEMENT = "org.eclipse.multipartConfig"; 130 public static final String __MULTIPART_CONFIG_ELEMENT = "org.eclipse.multipartConfig";
131 public static final String __MULTIPART_INPUT_STREAM = "org.eclipse.multiPartInputStream"; 131 public static final String __MULTIPART_INPUT_STREAM = "org.eclipse.multiPartInputStream";
132 public static final String __MULTIPART_CONTEXT = "org.eclipse.multiPartContext"; 132 public static final String __MULTIPART_CONTEXT = "org.eclipse.multiPartContext";
133 private static final Logger LOG = Log.getLogger(Request.class); 133 private static final Logger LOG = Log.getLogger(Request.class);
134 134
135 private static final String __ASYNC_FWD = "org.eclipse.asyncfwd"; 135 private static final String __ASYNC_FWD = "org.eclipse.asyncfwd";
136 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); 136 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault());
137 private static final int __NONE = 0, _STREAM = 1, __READER = 2; 137 private static final int __NONE = 0, _STREAM = 1, __READER = 2;
138 138
139 public static class MultiPartCleanerListener implements ServletRequestListener 139 public static class MultiPartCleanerListener implements ServletRequestListener
140 { 140 {
141 141
142 @Override 142 @Override
143 public void requestDestroyed(ServletRequestEvent sre) 143 public void requestDestroyed(ServletRequestEvent sre)
144 { 144 {
145 //Clean up any tmp files created by MultiPartInputStream 145 //Clean up any tmp files created by MultiPartInputStream
146 MultiPartInputStream mpis = (MultiPartInputStream)sre.getServletRequest().getAttribute(__MULTIPART_INPUT_STREAM); 146 MultiPartInputStream mpis = (MultiPartInputStream)sre.getServletRequest().getAttribute(__MULTIPART_INPUT_STREAM);
147 if (mpis != null) 147 if (mpis != null)
148 { 148 {
149 ContextHandler.Context context = (ContextHandler.Context)sre.getServletRequest().getAttribute(__MULTIPART_CONTEXT); 149 ContextHandler.Context context = (ContextHandler.Context)sre.getServletRequest().getAttribute(__MULTIPART_CONTEXT);
150 150
151 //Only do the cleanup if we are exiting from the context in which a servlet parsed the multipart files 151 //Only do the cleanup if we are exiting from the context in which a servlet parsed the multipart files
152 if (context == sre.getServletContext()) 152 if (context == sre.getServletContext())
153 { 153 {
154 try 154 try
155 { 155 {
156 mpis.deleteParts(); 156 mpis.deleteParts();
157 } 157 }
158 catch (MultiException e) 158 catch (MultiException e)
159 { 159 {
160 sre.getServletContext().log("Errors deleting multipart tmp files", e); 160 sre.getServletContext().log("Errors deleting multipart tmp files", e);
161 } 161 }
162 } 162 }
163 } 163 }
164 } 164 }
165 165
166 @Override 166 @Override
167 public void requestInitialized(ServletRequestEvent sre) 167 public void requestInitialized(ServletRequestEvent sre)
168 { 168 {
169 //nothing to do, multipart config set up by ServletHolder.handle() 169 //nothing to do, multipart config set up by ServletHolder.handle()
170 } 170 }
171 171
172 } 172 }
173 173
174 174
175 /* ------------------------------------------------------------ */ 175 /* ------------------------------------------------------------ */
176 public static Request getRequest(HttpServletRequest request) 176 public static Request getRequest(HttpServletRequest request)
177 { 177 {
178 if (request instanceof Request) 178 if (request instanceof Request)
179 return (Request)request; 179 return (Request)request;
180 180
181 return AbstractHttpConnection.getCurrentConnection().getRequest(); 181 return AbstractHttpConnection.getCurrentConnection().getRequest();
182 } 182 }
183 protected final AsyncContinuation _async = new AsyncContinuation(); 183 protected final AsyncContinuation _async = new AsyncContinuation();
184 private boolean _asyncSupported = true; 184 private boolean _asyncSupported = true;
185 private volatile Attributes _attributes; 185 private volatile Attributes _attributes;
186 private Authentication _authentication; 186 private Authentication _authentication;
187 private MultiMap<String> _baseParameters; 187 private MultiMap<String> _baseParameters;
188 private String _characterEncoding; 188 private String _characterEncoding;
189 protected AbstractHttpConnection _connection; 189 protected AbstractHttpConnection _connection;
190 private ContextHandler.Context _context; 190 private ContextHandler.Context _context;
191 private boolean _newContext; 191 private boolean _newContext;
192 private String _contextPath; 192 private String _contextPath;
193 private CookieCutter _cookies; 193 private CookieCutter _cookies;
194 private boolean _cookiesExtracted = false; 194 private boolean _cookiesExtracted = false;
195 private DispatcherType _dispatcherType; 195 private DispatcherType _dispatcherType;
196 private boolean _dns = false; 196 private boolean _dns = false;
197 private EndPoint _endp; 197 private EndPoint _endp;
198 private boolean _handled = false; 198 private boolean _handled = false;
199 private int _inputState = __NONE; 199 private int _inputState = __NONE;
200 private String _method; 200 private String _method;
201 private MultiMap<String> _parameters; 201 private MultiMap<String> _parameters;
202 private boolean _paramsExtracted; 202 private boolean _paramsExtracted;
203 private String _pathInfo; 203 private String _pathInfo;
204 private int _port; 204 private int _port;
205 private String _protocol = HttpVersions.HTTP_1_1; 205 private String _protocol = HttpVersions.HTTP_1_1;
206 private String _queryEncoding; 206 private String _queryEncoding;
207 private String _queryString; 207 private String _queryString;
208 private BufferedReader _reader; 208 private BufferedReader _reader;
209 private String _readerEncoding; 209 private String _readerEncoding;
210 private String _remoteAddr; 210 private String _remoteAddr;
211 private String _remoteHost; 211 private String _remoteHost;
212 private Object _requestAttributeListeners; 212 private Object _requestAttributeListeners;
213 private String _requestedSessionId; 213 private String _requestedSessionId;
214 private boolean _requestedSessionIdFromCookie = false; 214 private boolean _requestedSessionIdFromCookie = false;
215 private String _requestURI; 215 private String _requestURI;
216 private Map<Object, HttpSession> _savedNewSessions; 216 private Map<Object, HttpSession> _savedNewSessions;
217 private String _scheme = URIUtil.HTTP; 217 private String _scheme = URIUtil.HTTP;
218 private UserIdentity.Scope _scope; 218 private UserIdentity.Scope _scope;
219 private String _serverName; 219 private String _serverName;
220 private String _servletPath; 220 private String _servletPath;
221 private HttpSession _session; 221 private HttpSession _session;
222 private SessionManager _sessionManager; 222 private long _timeStamp;
223 private long _timeStamp; 223 private long _dispatchTime;
224 private long _dispatchTime; 224
225 225 private Buffer _timeStampBuffer;
226 private Buffer _timeStampBuffer; 226 private HttpURI _uri;
227 private HttpURI _uri; 227
228 228 private MultiPartInputStream _multiPartInputStream; //if the request is a multi-part mime
229 private MultiPartInputStream _multiPartInputStream; //if the request is a multi-part mime 229
230 230 /* ------------------------------------------------------------ */
231 /* ------------------------------------------------------------ */ 231 public Request()
232 public Request() 232 {
233 { 233 }
234 } 234
235 235 /* ------------------------------------------------------------ */
236 /* ------------------------------------------------------------ */ 236 public Request(AbstractHttpConnection connection)
237 public Request(AbstractHttpConnection connection) 237 {
238 { 238 setConnection(connection);
239 setConnection(connection); 239 }
240 } 240
241 241 /* ------------------------------------------------------------ */
242 /* ------------------------------------------------------------ */ 242 public void addEventListener(final EventListener listener)
243 public void addEventListener(final EventListener listener) 243 {
244 { 244 if (listener instanceof ServletRequestAttributeListener)
245 if (listener instanceof ServletRequestAttributeListener) 245 _requestAttributeListeners = LazyList.add(_requestAttributeListeners,listener);
246 _requestAttributeListeners = LazyList.add(_requestAttributeListeners,listener); 246 if (listener instanceof ContinuationListener)
247 if (listener instanceof ContinuationListener) 247 throw new IllegalArgumentException(listener.getClass().toString());
248 throw new IllegalArgumentException(listener.getClass().toString()); 248 if (listener instanceof AsyncListener)
249 if (listener instanceof AsyncListener) 249 throw new IllegalArgumentException(listener.getClass().toString());
250 throw new IllegalArgumentException(listener.getClass().toString()); 250 }
251 } 251
252 252 /* ------------------------------------------------------------ */
253 /* ------------------------------------------------------------ */ 253 /**
254 /** 254 * Extract Parameters from query string and/or form _content.
255 * Extract Parameters from query string and/or form _content. 255 */
256 */ 256 public void extractParameters()
257 public void extractParameters() 257 {
258 { 258 if (_baseParameters == null)
259 if (_baseParameters == null) 259 _baseParameters = new MultiMap(16);
260 _baseParameters = new MultiMap(16); 260
261 261 if (_paramsExtracted)
262 if (_paramsExtracted) 262 {
263 { 263 if (_parameters == null)
264 if (_parameters == null) 264 _parameters = _baseParameters;
265 _parameters = _baseParameters; 265 return;
266 return; 266 }
267 } 267
268 268 _paramsExtracted = true;
269 _paramsExtracted = true; 269
270 270 try
271 try 271 {
272 { 272 // Handle query string
273 // Handle query string 273 if (_uri != null && _uri.hasQuery())
274 if (_uri != null && _uri.hasQuery()) 274 {
275 { 275 if (_queryEncoding == null)
276 if (_queryEncoding == null) 276 _uri.decodeQueryTo(_baseParameters);
277 _uri.decodeQueryTo(_baseParameters); 277 else
278 else 278 {
279 { 279 try
280 try 280 {
281 { 281 _uri.decodeQueryTo(_baseParameters,_queryEncoding);
282 _uri.decodeQueryTo(_baseParameters,_queryEncoding); 282 }
283 } 283 catch (UnsupportedEncodingException e)
284 catch (UnsupportedEncodingException e) 284 {
285 { 285 if (LOG.isDebugEnabled())
286 if (LOG.isDebugEnabled()) 286 LOG.warn(e);
287 LOG.warn(e); 287 else
288 else 288 LOG.warn(e.toString());
289 LOG.warn(e.toString()); 289 }
290 } 290 }
291 } 291 }
292 } 292
293 293 // handle any _content.
294 // handle any _content. 294 String encoding = getCharacterEncoding();
295 String encoding = getCharacterEncoding(); 295 String content_type = getContentType();
296 String content_type = getContentType(); 296 if (content_type != null && content_type.length() > 0)
297 if (content_type != null && content_type.length() > 0) 297 {
298 { 298 content_type = HttpFields.valueParameters(content_type,null);
299 content_type = HttpFields.valueParameters(content_type,null); 299
300 300 if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState == __NONE
301 if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState == __NONE 301 && (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod())))
302 && (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod()))) 302 {
303 { 303 int content_length = getContentLength();
304 int content_length = getContentLength(); 304 if (content_length != 0)
305 if (content_length != 0) 305 {
306 { 306 try
307 try 307 {
308 { 308 int maxFormContentSize = -1;
309 int maxFormContentSize = -1; 309 int maxFormKeys = -1;
310 int maxFormKeys = -1; 310
311 311 if (_context != null)
312 if (_context != null) 312 {
313 { 313 maxFormContentSize = _context.getContextHandler().getMaxFormContentSize();
314 maxFormContentSize = _context.getContextHandler().getMaxFormContentSize(); 314 maxFormKeys = _context.getContextHandler().getMaxFormKeys();
315 maxFormKeys = _context.getContextHandler().getMaxFormKeys(); 315 }
316 } 316
317 317 if (maxFormContentSize < 0)
318 if (maxFormContentSize < 0) 318 {
319 { 319 Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
320 Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize"); 320 if (obj == null)
321 if (obj == null) 321 maxFormContentSize = 200000;
322 maxFormContentSize = 200000; 322 else if (obj instanceof Number)
323 else if (obj instanceof Number) 323 {
324 { 324 Number size = (Number)obj;
325 Number size = (Number)obj; 325 maxFormContentSize = size.intValue();
326 maxFormContentSize = size.intValue(); 326 }
327 } 327 else if (obj instanceof String)
328 else if (obj instanceof String) 328 {
329 { 329 maxFormContentSize = Integer.valueOf((String)obj);
330 maxFormContentSize = Integer.valueOf((String)obj); 330 }
331 } 331 }
332 } 332
333 333 if (maxFormKeys < 0)
334 if (maxFormKeys < 0) 334 {
335 { 335 Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
336 Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys"); 336 if (obj == null)
337 if (obj == null) 337 maxFormKeys = 1000;
338 maxFormKeys = 1000; 338 else if (obj instanceof Number)
339 else if (obj instanceof Number) 339 {
340 { 340 Number keys = (Number)obj;
341 Number keys = (Number)obj; 341 maxFormKeys = keys.intValue();
342 maxFormKeys = keys.intValue(); 342 }
343 } 343 else if (obj instanceof String)
344 else if (obj instanceof String) 344 {
345 { 345 maxFormKeys = Integer.valueOf((String)obj);
346 maxFormKeys = Integer.valueOf((String)obj); 346 }
347 } 347 }
348 } 348
349 349 if (content_length > maxFormContentSize && maxFormContentSize > 0)
350 if (content_length > maxFormContentSize && maxFormContentSize > 0) 350 {
351 { 351 throw new IllegalStateException("Form too large " + content_length + ">" + maxFormContentSize);
352 throw new IllegalStateException("Form too large " + content_length + ">" + maxFormContentSize); 352 }
353 } 353 InputStream in = getInputStream();
354 InputStream in = getInputStream(); 354
355 355 // Add form params to query params
356 // Add form params to query params 356 UrlEncoded.decodeTo(in,_baseParameters,encoding,content_length < 0?maxFormContentSize:-1,maxFormKeys);
357 UrlEncoded.decodeTo(in,_baseParameters,encoding,content_length < 0?maxFormContentSize:-1,maxFormKeys); 357 }
358 } 358 catch (IOException e)
359 catch (IOException e) 359 {
360 { 360 if (LOG.isDebugEnabled())
361 if (LOG.isDebugEnabled()) 361 LOG.warn(e);
362 LOG.warn(e); 362 else
363 else 363 LOG.warn(e.toString());
364 LOG.warn(e.toString()); 364 }
365 } 365 }
366 } 366 }
367 } 367
368 368 }
369 } 369
370 370 if (_parameters == null)
371 if (_parameters == null) 371 _parameters = _baseParameters;
372 _parameters = _baseParameters; 372 else if (_parameters != _baseParameters)
373 else if (_parameters != _baseParameters) 373 {
374 { 374 // Merge parameters (needed if parameters extracted after a forward).
375 // Merge parameters (needed if parameters extracted after a forward). 375 Iterator iter = _baseParameters.entrySet().iterator();
376 Iterator iter = _baseParameters.entrySet().iterator(); 376 while (iter.hasNext())
377 while (iter.hasNext()) 377 {
378 { 378 Map.Entry entry = (Map.Entry)iter.next();
379 Map.Entry entry = (Map.Entry)iter.next(); 379 String name = (String)entry.getKey();
380 String name = (String)entry.getKey(); 380 Object values = entry.getValue();
381 Object values = entry.getValue(); 381 for (int i = 0; i < LazyList.size(values); i++)
382 for (int i = 0; i < LazyList.size(values); i++) 382 _parameters.add(name,LazyList.get(values,i));
383 _parameters.add(name,LazyList.get(values,i)); 383 }
384 } 384 }
385 } 385
386 386 if (content_type != null && content_type.length()>0 && content_type.startsWith("multipart/form-data") && getAttribute(__MULTIPART_CONFIG_ELEMENT)!=null)
387 if (content_type != null && content_type.length()>0 && content_type.startsWith("multipart/form-data") && getAttribute(__MULTIPART_CONFIG_ELEMENT)!=null) 387 {
388 { 388 try
389 try 389 {
390 { 390 getParts();
391 getParts(); 391 }
392 } 392 catch (IOException e)
393 catch (IOException e) 393 {
394 { 394 if (LOG.isDebugEnabled())
395 if (LOG.isDebugEnabled()) 395 LOG.warn(e);
396 LOG.warn(e); 396 else
397 else 397 LOG.warn(e.toString());
398 LOG.warn(e.toString()); 398 }
399 } 399 catch (ServletException e)
400 catch (ServletException e) 400 {
401 { 401 if (LOG.isDebugEnabled())
402 if (LOG.isDebugEnabled()) 402 LOG.warn(e);
403 LOG.warn(e); 403 else
404 else 404 LOG.warn(e.toString());
405 LOG.warn(e.toString()); 405 }
406 } 406 }
407 } 407 }
408 } 408 finally
409 finally 409 {
410 { 410 // ensure params always set (even if empty) after extraction
411 // ensure params always set (even if empty) after extraction 411 if (_parameters == null)
412 if (_parameters == null) 412 _parameters = _baseParameters;
413 _parameters = _baseParameters; 413 }
414 } 414 }
415 } 415
416 416 /* ------------------------------------------------------------ */
417 /* ------------------------------------------------------------ */ 417 public AsyncContext getAsyncContext()
418 public AsyncContext getAsyncContext() 418 {
419 { 419 if (_async.isInitial() && !_async.isAsyncStarted())
420 if (_async.isInitial() && !_async.isAsyncStarted()) 420 throw new IllegalStateException(_async.getStatusString());
421 throw new IllegalStateException(_async.getStatusString()); 421 return _async;
422 return _async; 422 }
423 } 423
424 424 /* ------------------------------------------------------------ */
425 /* ------------------------------------------------------------ */ 425 public AsyncContinuation getAsyncContinuation()
426 public AsyncContinuation getAsyncContinuation() 426 {
427 { 427 return _async;
428 return _async; 428 }
429 } 429
430 430 /* ------------------------------------------------------------ */
431 /* ------------------------------------------------------------ */ 431 /*
432 /* 432 * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
433 * @see javax.servlet.ServletRequest#getAttribute(java.lang.String) 433 */
434 */ 434 public Object getAttribute(String name)
435 public Object getAttribute(String name) 435 {
436 { 436 if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name))
437 if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name)) 437 return new Long(getConnection().getEndPoint().getMaxIdleTime());
438 return new Long(getConnection().getEndPoint().getMaxIdleTime()); 438
439 439 Object attr = (_attributes == null)?null:_attributes.getAttribute(name);
440 Object attr = (_attributes == null)?null:_attributes.getAttribute(name); 440 if (attr == null && Continuation.ATTRIBUTE.equals(name))
441 if (attr == null && Continuation.ATTRIBUTE.equals(name)) 441 return _async;
442 return _async; 442 return attr;
443 return attr; 443 }
444 } 444
445 445 /* ------------------------------------------------------------ */
446 /* ------------------------------------------------------------ */ 446 /*
447 /* 447 * @see javax.servlet.ServletRequest#getAttributeNames()
448 * @see javax.servlet.ServletRequest#getAttributeNames() 448 */
449 */ 449 public Enumeration getAttributeNames()
450 public Enumeration getAttributeNames() 450 {
451 { 451 if (_attributes == null)
452 if (_attributes == null) 452 return Collections.enumeration(Collections.EMPTY_LIST);
453 return Collections.enumeration(Collections.EMPTY_LIST); 453
454 454 return AttributesMap.getAttributeNamesCopy(_attributes);
455 return AttributesMap.getAttributeNamesCopy(_attributes); 455 }
456 } 456
457 457 /* ------------------------------------------------------------ */
458 /* ------------------------------------------------------------ */ 458 /*
459 /* 459 */
460 */ 460 public Attributes getAttributes()
461 public Attributes getAttributes() 461 {
462 { 462 if (_attributes == null)
463 if (_attributes == null) 463 _attributes = new AttributesMap();
464 _attributes = new AttributesMap(); 464 return _attributes;
465 return _attributes; 465 }
466 } 466
467 467 /* ------------------------------------------------------------ */
468 /* ------------------------------------------------------------ */ 468 /**
469 /** 469 * Get the authentication.
470 * Get the authentication. 470 *
471 * 471 * @return the authentication
472 * @return the authentication 472 */
473 */ 473 public Authentication getAuthentication()
474 public Authentication getAuthentication() 474 {
475 { 475 return _authentication;
476 return _authentication; 476 }
477 } 477
478 478 /* ------------------------------------------------------------ */
479 /* ------------------------------------------------------------ */ 479 /*
480 /* 480 * @see javax.servlet.http.HttpServletRequest#getAuthType()
481 * @see javax.servlet.http.HttpServletRequest#getAuthType() 481 */
482 */ 482 public String getAuthType()
483 public String getAuthType() 483 {
484 { 484 if (_authentication instanceof Authentication.Deferred)
485 if (_authentication instanceof Authentication.Deferred) 485 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this));
486 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this)); 486
487 487 if (_authentication instanceof Authentication.User)
488 if (_authentication instanceof Authentication.User) 488 return ((Authentication.User)_authentication).getAuthMethod();
489 return ((Authentication.User)_authentication).getAuthMethod(); 489 return null;
490 return null; 490 }
491 } 491
492 492 /* ------------------------------------------------------------ */
493 /* ------------------------------------------------------------ */ 493 /*
494 /* 494 * @see javax.servlet.ServletRequest#getCharacterEncoding()
495 * @see javax.servlet.ServletRequest#getCharacterEncoding() 495 */
496 */ 496 public String getCharacterEncoding()
497 public String getCharacterEncoding() 497 {
498 { 498 return _characterEncoding;
499 return _characterEncoding; 499 }
500 } 500
501 501 /* ------------------------------------------------------------ */
502 /* ------------------------------------------------------------ */ 502 /**
503 /** 503 * @return Returns the connection.
504 * @return Returns the connection. 504 */
505 */ 505 public AbstractHttpConnection getConnection()
506 public AbstractHttpConnection getConnection() 506 {
507 { 507 return _connection;
508 return _connection; 508 }
509 } 509
510 510 /* ------------------------------------------------------------ */
511 /* ------------------------------------------------------------ */ 511 /*
512 /* 512 * @see javax.servlet.ServletRequest#getContentLength()
513 * @see javax.servlet.ServletRequest#getContentLength() 513 */
514 */ 514 public int getContentLength()
515 public int getContentLength() 515 {
516 { 516 return (int)_connection.getRequestFields().getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER);
517 return (int)_connection.getRequestFields().getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER); 517 }
518 } 518
519 519 public long getContentRead()
520 public long getContentRead() 520 {
521 { 521 if (_connection == null || _connection.getParser() == null)
522 if (_connection == null || _connection.getParser() == null) 522 return -1;
523 return -1; 523
524 524 return ((HttpParser)_connection.getParser()).getContentRead();
525 return ((HttpParser)_connection.getParser()).getContentRead(); 525 }
526 } 526
527 527 /* ------------------------------------------------------------ */
528 /* ------------------------------------------------------------ */ 528 /*
529 /* 529 * @see javax.servlet.ServletRequest#getContentType()
530 * @see javax.servlet.ServletRequest#getContentType() 530 */
531 */ 531 public String getContentType()
532 public String getContentType() 532 {
533 { 533 return _connection.getRequestFields().getStringField(HttpHeaders.CONTENT_TYPE_BUFFER);
534 return _connection.getRequestFields().getStringField(HttpHeaders.CONTENT_TYPE_BUFFER); 534 }
535 } 535
536 536 /* ------------------------------------------------------------ */
537 /* ------------------------------------------------------------ */ 537 /**
538 /** 538 * @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet been called.
539 * @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet been called. 539 */
540 */ 540 public Context getContext()
541 public Context getContext() 541 {
542 { 542 return _context;
543 return _context; 543 }
544 } 544
545 545 /* ------------------------------------------------------------ */
546 /* ------------------------------------------------------------ */ 546 /*
547 /* 547 * @see javax.servlet.http.HttpServletRequest#getContextPath()
548 * @see javax.servlet.http.HttpServletRequest#getContextPath() 548 */
549 */ 549 public String getContextPath()
550 public String getContextPath() 550 {
551 { 551 return _contextPath;
552 return _contextPath; 552 }
553 } 553
554 554 /* ------------------------------------------------------------ */
555 /* ------------------------------------------------------------ */ 555 /*
556 /* 556 * @see javax.servlet.http.HttpServletRequest#getCookies()
557 * @see javax.servlet.http.HttpServletRequest#getCookies() 557 */
558 */ 558 public Cookie[] getCookies()
559 public Cookie[] getCookies() 559 {
560 { 560 if (_cookiesExtracted)
561 if (_cookiesExtracted) 561 return _cookies == null?null:_cookies.getCookies();
562 return _cookies == null?null:_cookies.getCookies(); 562
563 563 _cookiesExtracted = true;
564 _cookiesExtracted = true; 564
565 565 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.COOKIE_BUFFER);
566 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.COOKIE_BUFFER); 566
567 567 // Handle no cookies
568 // Handle no cookies 568 if (enm != null)
569 if (enm != null) 569 {
570 { 570 if (_cookies == null)
571 if (_cookies == null) 571 _cookies = new CookieCutter();
572 _cookies = new CookieCutter(); 572
573 573 while (enm.hasMoreElements())
574 while (enm.hasMoreElements()) 574 {
575 { 575 String c = (String)enm.nextElement();
576 String c = (String)enm.nextElement(); 576 _cookies.addCookieField(c);
577 _cookies.addCookieField(c); 577 }
578 } 578 }
579 } 579
580 580 return _cookies == null?null:_cookies.getCookies();
581 return _cookies == null?null:_cookies.getCookies(); 581 }
582 } 582
583 583 /* ------------------------------------------------------------ */
584 /* ------------------------------------------------------------ */ 584 /*
585 /* 585 * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
586 * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String) 586 */
587 */ 587 public long getDateHeader(String name)
588 public long getDateHeader(String name) 588 {
589 { 589 return _connection.getRequestFields().getDateField(name);
590 return _connection.getRequestFields().getDateField(name); 590 }
591 } 591
592 592 /* ------------------------------------------------------------ */
593 /* ------------------------------------------------------------ */ 593 public DispatcherType getDispatcherType()
594 public DispatcherType getDispatcherType() 594 {
595 { 595 return _dispatcherType;
596 return _dispatcherType; 596 }
597 } 597
598 598 /* ------------------------------------------------------------ */
599 /* ------------------------------------------------------------ */ 599 /*
600 /* 600 * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
601 * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String) 601 */
602 */ 602 public String getHeader(String name)
603 public String getHeader(String name) 603 {
604 { 604 return _connection.getRequestFields().getStringField(name);
605 return _connection.getRequestFields().getStringField(name); 605 }
606 } 606
607 607 /* ------------------------------------------------------------ */
608 /* ------------------------------------------------------------ */ 608 /*
609 /* 609 * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
610 * @see javax.servlet.http.HttpServletRequest#getHeaderNames() 610 */
611 */ 611 public Enumeration getHeaderNames()
612 public Enumeration getHeaderNames() 612 {
613 { 613 return _connection.getRequestFields().getFieldNames();
614 return _connection.getRequestFields().getFieldNames(); 614 }
615 } 615
616 616 /* ------------------------------------------------------------ */
617 /* ------------------------------------------------------------ */ 617 /*
618 /* 618 * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
619 * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) 619 */
620 */ 620 public Enumeration getHeaders(String name)
621 public Enumeration getHeaders(String name) 621 {
622 { 622 Enumeration e = _connection.getRequestFields().getValues(name);
623 Enumeration e = _connection.getRequestFields().getValues(name); 623 if (e == null)
624 if (e == null) 624 return Collections.enumeration(Collections.EMPTY_LIST);
625 return Collections.enumeration(Collections.EMPTY_LIST); 625 return e;
626 return e; 626 }
627 } 627
628 628 /* ------------------------------------------------------------ */
629 /* ------------------------------------------------------------ */ 629 /**
630 /** 630 * @return Returns the inputState.
631 * @return Returns the inputState. 631 */
632 */ 632 public int getInputState()
633 public int getInputState() 633 {
634 { 634 return _inputState;
635 return _inputState; 635 }
636 } 636
637 637 /* ------------------------------------------------------------ */
638 /* ------------------------------------------------------------ */ 638 /*
639 /* 639 * @see javax.servlet.ServletRequest#getInputStream()
640 * @see javax.servlet.ServletRequest#getInputStream() 640 */
641 */ 641 public ServletInputStream getInputStream() throws IOException
642 public ServletInputStream getInputStream() throws IOException 642 {
643 { 643 if (_inputState != __NONE && _inputState != _STREAM)
644 if (_inputState != __NONE && _inputState != _STREAM) 644 throw new IllegalStateException("READER");
645 throw new IllegalStateException("READER"); 645 _inputState = _STREAM;
646 _inputState = _STREAM; 646 return _connection.getInputStream();
647 return _connection.getInputStream(); 647 }
648 } 648
649 649 /* ------------------------------------------------------------ */
650 /* ------------------------------------------------------------ */ 650 /*
651 /* 651 * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
652 * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String) 652 */
653 */ 653 public int getIntHeader(String name)
654 public int getIntHeader(String name) 654 {
655 { 655 return (int)_connection.getRequestFields().getLongField(name);
656 return (int)_connection.getRequestFields().getLongField(name); 656 }
657 } 657
658 658 /* ------------------------------------------------------------ */
659 /* ------------------------------------------------------------ */ 659 /*
660 /* 660 * @see javax.servlet.ServletRequest#getLocalAddr()
661 * @see javax.servlet.ServletRequest#getLocalAddr() 661 */
662 */ 662 public String getLocalAddr()
663 public String getLocalAddr() 663 {
664 { 664 return _endp == null?null:_endp.getLocalAddr();
665 return _endp == null?null:_endp.getLocalAddr(); 665 }
666 } 666
667 667 /* ------------------------------------------------------------ */
668 /* ------------------------------------------------------------ */ 668 /*
669 /* 669 * @see javax.servlet.ServletRequest#getLocale()
670 * @see javax.servlet.ServletRequest#getLocale() 670 */
671 */ 671 public Locale getLocale()
672 public Locale getLocale() 672 {
673 { 673 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE,HttpFields.__separators);
674 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE,HttpFields.__separators); 674
675 675 // handle no locale
676 // handle no locale 676 if (enm == null || !enm.hasMoreElements())
677 if (enm == null || !enm.hasMoreElements()) 677 return Locale.getDefault();
678 return Locale.getDefault(); 678
679 679 // sort the list in quality order
680 // sort the list in quality order 680 List acceptLanguage = HttpFields.qualityList(enm);
681 List acceptLanguage = HttpFields.qualityList(enm); 681 if (acceptLanguage.size() == 0)
682 if (acceptLanguage.size() == 0) 682 return Locale.getDefault();
683 return Locale.getDefault(); 683
684 684 int size = acceptLanguage.size();
685 int size = acceptLanguage.size(); 685
686 686 if (size > 0)
687 if (size > 0) 687 {
688 { 688 String language = (String)acceptLanguage.get(0);
689 String language = (String)acceptLanguage.get(0); 689 language = HttpFields.valueParameters(language,null);
690 language = HttpFields.valueParameters(language,null); 690 String country = "";
691 String country = ""; 691 int dash = language.indexOf('-');
692 int dash = language.indexOf('-'); 692 if (dash > -1)
693 if (dash > -1) 693 {
694 { 694 country = language.substring(dash + 1).trim();
695 country = language.substring(dash + 1).trim(); 695 language = language.substring(0,dash).trim();
696 language = language.substring(0,dash).trim(); 696 }
697 } 697 return new Locale(language,country);
698 return new Locale(language,country); 698 }
699 } 699
700 700 return Locale.getDefault();
701 return Locale.getDefault(); 701 }
702 } 702
703 703 /* ------------------------------------------------------------ */
704 /* ------------------------------------------------------------ */ 704 /*
705 /* 705 * @see javax.servlet.ServletRequest#getLocales()
706 * @see javax.servlet.ServletRequest#getLocales() 706 */
707 */ 707 public Enumeration getLocales()
708 public Enumeration getLocales() 708 {
709 { 709
710 710 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE,HttpFields.__separators);
711 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE,HttpFields.__separators); 711
712 712 // handle no locale
713 // handle no locale 713 if (enm == null || !enm.hasMoreElements())
714 if (enm == null || !enm.hasMoreElements()) 714 return Collections.enumeration(__defaultLocale);
715 return Collections.enumeration(__defaultLocale); 715
716 716 // sort the list in quality order
717 // sort the list in quality order 717 List acceptLanguage = HttpFields.qualityList(enm);
718 List acceptLanguage = HttpFields.qualityList(enm); 718
719 719 if (acceptLanguage.size() == 0)
720 if (acceptLanguage.size() == 0) 720 return Collections.enumeration(__defaultLocale);
721 return Collections.enumeration(__defaultLocale); 721
722 722 Object langs = null;
723 Object langs = null; 723 int size = acceptLanguage.size();
724 int size = acceptLanguage.size(); 724
725 725 // convert to locals
726 // convert to locals 726 for (int i = 0; i < size; i++)
727 for (int i = 0; i < size; i++) 727 {
728 { 728 String language = (String)acceptLanguage.get(i);
729 String language = (String)acceptLanguage.get(i); 729 language = HttpFields.valueParameters(language,null);
730 language = HttpFields.valueParameters(language,null); 730 String country = "";
731 String country = ""; 731 int dash = language.indexOf('-');
732 int dash = language.indexOf('-'); 732 if (dash > -1)
733 if (dash > -1) 733 {
734 { 734 country = language.substring(dash + 1).trim();
735 country = language.substring(dash + 1).trim(); 735 language = language.substring(0,dash).trim();
736 language = language.substring(0,dash).trim(); 736 }
737 } 737 langs = LazyList.ensureSize(langs,size);
738 langs = LazyList.ensureSize(langs,size); 738 langs = LazyList.add(langs,new Locale(language,country));
739 langs = LazyList.add(langs,new Locale(language,country)); 739 }
740 } 740
741 741 if (LazyList.size(langs) == 0)
742 if (LazyList.size(langs) == 0) 742 return Collections.enumeration(__defaultLocale);
743 return Collections.enumeration(__defaultLocale); 743
744 744 return Collections.enumeration(LazyList.getList(langs));
745 return Collections.enumeration(LazyList.getList(langs)); 745 }
746 } 746
747 747 /* ------------------------------------------------------------ */
748 /* ------------------------------------------------------------ */ 748 /*
749 /* 749 * @see javax.servlet.ServletRequest#getLocalName()
750 * @see javax.servlet.ServletRequest#getLocalName() 750 */
751 */ 751 public String getLocalName()
752 public String getLocalName() 752 {
753 { 753 if (_endp == null)
754 if (_endp == null) 754 return null;
755 return null; 755 if (_dns)
756 if (_dns) 756 return _endp.getLocalHost();
757 return _endp.getLocalHost(); 757
758 758 String local = _endp.getLocalAddr();
759 String local = _endp.getLocalAddr(); 759 if (local != null && local.indexOf(':') >= 0)
760 if (local != null && local.indexOf(':') >= 0) 760 local = "[" + local + "]";
761 local = "[" + local + "]"; 761 return local;
762 return local; 762 }
763 } 763
764 764 /* ------------------------------------------------------------ */
765 /* ------------------------------------------------------------ */ 765 /*
766 /* 766 * @see javax.servlet.ServletRequest#getLocalPort()
767 * @see javax.servlet.ServletRequest#getLocalPort() 767 */
768 */ 768 public int getLocalPort()
769 public int getLocalPort() 769 {
770 { 770 return _endp == null?0:_endp.getLocalPort();
771 return _endp == null?0:_endp.getLocalPort(); 771 }
772 } 772
773 773 /* ------------------------------------------------------------ */
774 /* ------------------------------------------------------------ */ 774 /*
775 /* 775 * @see javax.servlet.http.HttpServletRequest#getMethod()
776 * @see javax.servlet.http.HttpServletRequest#getMethod() 776 */
777 */ 777 public String getMethod()
778 public String getMethod() 778 {
779 { 779 return _method;
780 return _method; 780 }
781 } 781
782 782 /* ------------------------------------------------------------ */
783 /* ------------------------------------------------------------ */ 783 /*
784 /* 784 * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
785 * @see javax.servlet.ServletRequest#getParameter(java.lang.String) 785 */
786 */ 786 public String getParameter(String name)
787 public String getParameter(String name) 787 {
788 { 788 if (!_paramsExtracted)
789 if (!_paramsExtracted) 789 extractParameters();
790 extractParameters(); 790 return (String)_parameters.getValue(name,0);
791 return (String)_parameters.getValue(name,0); 791 }
792 } 792
793 793 /* ------------------------------------------------------------ */
794 /* ------------------------------------------------------------ */ 794 /*
795 /* 795 * @see javax.servlet.ServletRequest#getParameterMap()
796 * @see javax.servlet.ServletRequest#getParameterMap() 796 */
797 */ 797 public Map getParameterMap()
798 public Map getParameterMap() 798 {
799 { 799 if (!_paramsExtracted)
800 if (!_paramsExtracted) 800 extractParameters();
801 extractParameters(); 801
802 802 return Collections.unmodifiableMap(_parameters.toStringArrayMap());
803 return Collections.unmodifiableMap(_parameters.toStringArrayMap()); 803 }
804 } 804
805 805 /* ------------------------------------------------------------ */
806 /* ------------------------------------------------------------ */ 806 /*
807 /* 807 * @see javax.servlet.ServletRequest#getParameterNames()
808 * @see javax.servlet.ServletRequest#getParameterNames() 808 */
809 */ 809 public Enumeration getParameterNames()
810 public Enumeration getParameterNames() 810 {
811 { 811 if (!_paramsExtracted)
812 if (!_paramsExtracted) 812 extractParameters();
813 extractParameters(); 813 return Collections.enumeration(_parameters.keySet());
814 return Collections.enumeration(_parameters.keySet()); 814 }
815 } 815
816 816 /* ------------------------------------------------------------ */
817 /* ------------------------------------------------------------ */ 817 /**
818 /** 818 * @return Returns the parameters.
819 * @return Returns the parameters. 819 */
820 */ 820 public MultiMap<String> getParameters()
821 public MultiMap<String> getParameters() 821 {
822 { 822 return _parameters;
823 return _parameters; 823 }
824 } 824
825 825 /* ------------------------------------------------------------ */
826 /* ------------------------------------------------------------ */ 826 /*
827 /* 827 * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
828 * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String) 828 */
829 */ 829 public String[] getParameterValues(String name)
830 public String[] getParameterValues(String name) 830 {
831 { 831 if (!_paramsExtracted)
832 if (!_paramsExtracted) 832 extractParameters();
833 extractParameters(); 833 List<Object> vals = _parameters.getValues(name);
834 List<Object> vals = _parameters.getValues(name); 834 if (vals == null)
835 if (vals == null) 835 return null;
836 return null; 836 return vals.toArray(new String[vals.size()]);
837 return vals.toArray(new String[vals.size()]); 837 }
838 } 838
839 839 /* ------------------------------------------------------------ */
840 /* ------------------------------------------------------------ */ 840 /*
841 /* 841 * @see javax.servlet.http.HttpServletRequest#getPathInfo()
842 * @see javax.servlet.http.HttpServletRequest#getPathInfo() 842 */
843 */ 843 public String getPathInfo()
844 public String getPathInfo() 844 {
845 { 845 return _pathInfo;
846 return _pathInfo; 846 }
847 } 847
848 848 /* ------------------------------------------------------------ */
849 /* ------------------------------------------------------------ */ 849 /*
850 /* 850 * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
851 * @see javax.servlet.http.HttpServletRequest#getPathTranslated() 851 */
852 */ 852 public String getPathTranslated()
853 public String getPathTranslated() 853 {
854 { 854 if (_pathInfo == null || _context == null)
855 if (_pathInfo == null || _context == null) 855 return null;
856 return null; 856 return _context.getRealPath(_pathInfo);
857 return _context.getRealPath(_pathInfo); 857 }
858 } 858
859 859 /* ------------------------------------------------------------ */
860 /* ------------------------------------------------------------ */ 860 /*
861 /* 861 * @see javax.servlet.ServletRequest#getProtocol()
862 * @see javax.servlet.ServletRequest#getProtocol() 862 */
863 */ 863 public String getProtocol()
864 public String getProtocol() 864 {
865 { 865 return _protocol;
866 return _protocol; 866 }
867 } 867
868 868 /* ------------------------------------------------------------ */
869 /* ------------------------------------------------------------ */ 869 public String getQueryEncoding()
870 public String getQueryEncoding() 870 {
871 { 871 return _queryEncoding;
872 return _queryEncoding; 872 }
873 } 873
874 874 /* ------------------------------------------------------------ */
875 /* ------------------------------------------------------------ */ 875 /*
876 /* 876 * @see javax.servlet.http.HttpServletRequest#getQueryString()
877 * @see javax.servlet.http.HttpServletRequest#getQueryString() 877 */
878 */ 878 public String getQueryString()
879 public String getQueryString() 879 {
880 { 880 if (_queryString == null && _uri != null)
881 if (_queryString == null && _uri != null) 881 {
882 { 882 if (_queryEncoding == null)
883 if (_queryEncoding == null) 883 _queryString = _uri.getQuery();
884 _queryString = _uri.getQuery(); 884 else
885 else 885 _queryString = _uri.getQuery(_queryEncoding);
886 _queryString = _uri.getQuery(_queryEncoding); 886 }
887 } 887 return _queryString;
888 return _queryString; 888 }
889 } 889
890 890 /* ------------------------------------------------------------ */
891 /* ------------------------------------------------------------ */ 891 /*
892 /* 892 * @see javax.servlet.ServletRequest#getReader()
893 * @see javax.servlet.ServletRequest#getReader() 893 */
894 */ 894 public BufferedReader getReader() throws IOException
895 public BufferedReader getReader() throws IOException 895 {
896 { 896 if (_inputState != __NONE && _inputState != __READER)
897 if (_inputState != __NONE && _inputState != __READER) 897 throw new IllegalStateException("STREAMED");
898 throw new IllegalStateException("STREAMED"); 898
899 899 if (_inputState == __READER)
900 if (_inputState == __READER) 900 return _reader;
901 return _reader; 901
902 902 String encoding = getCharacterEncoding();
903 String encoding = getCharacterEncoding(); 903 if (encoding == null)
904 if (encoding == null) 904 encoding = StringUtil.__ISO_8859_1;
905 encoding = StringUtil.__ISO_8859_1; 905
906 906 if (_reader == null || !encoding.equalsIgnoreCase(_readerEncoding))
907 if (_reader == null || !encoding.equalsIgnoreCase(_readerEncoding)) 907 {
908 { 908 final ServletInputStream in = getInputStream();
909 final ServletInputStream in = getInputStream(); 909 _readerEncoding = encoding;
910 _readerEncoding = encoding; 910 _reader = new BufferedReader(new InputStreamReader(in,encoding))
911 _reader = new BufferedReader(new InputStreamReader(in,encoding)) 911 {
912 { 912 @Override
913 @Override 913 public void close() throws IOException
914 public void close() throws IOException 914 {
915 { 915 in.close();
916 in.close(); 916 }
917 } 917 };
918 }; 918 }
919 } 919 _inputState = __READER;
920 _inputState = __READER; 920 return _reader;
921 return _reader; 921 }
922 } 922
923 923 /* ------------------------------------------------------------ */
924 /* ------------------------------------------------------------ */ 924 /*
925 /* 925 * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
926 * @see javax.servlet.ServletRequest#getRealPath(java.lang.String) 926 */
927 */ 927 public String getRealPath(String path)
928 public String getRealPath(String path) 928 {
929 { 929 if (_context == null)
930 if (_context == null) 930 return null;
931 return null; 931 return _context.getRealPath(path);
932 return _context.getRealPath(path); 932 }
933 } 933
934 934 /* ------------------------------------------------------------ */
935 /* ------------------------------------------------------------ */ 935 /*
936 /* 936 * @see javax.servlet.ServletRequest#getRemoteAddr()
937 * @see javax.servlet.ServletRequest#getRemoteAddr() 937 */
938 */ 938 public String getRemoteAddr()
939 public String getRemoteAddr() 939 {
940 { 940 if (_remoteAddr != null)
941 if (_remoteAddr != null) 941 return _remoteAddr;
942 return _remoteAddr; 942 return _endp == null?null:_endp.getRemoteAddr();
943 return _endp == null?null:_endp.getRemoteAddr(); 943 }
944 } 944
945 945 /* ------------------------------------------------------------ */
946 /* ------------------------------------------------------------ */ 946 /*
947 /* 947 * @see javax.servlet.ServletRequest#getRemoteHost()
948 * @see javax.servlet.ServletRequest#getRemoteHost() 948 */
949 */ 949 public String getRemoteHost()
950 public String getRemoteHost() 950 {
951 { 951 if (_dns)
952 if (_dns) 952 {
953 { 953 if (_remoteHost != null)
954 if (_remoteHost != null) 954 {
955 { 955 return _remoteHost;
956 return _remoteHost; 956 }
957 } 957 return _endp == null?null:_endp.getRemoteHost();
958 return _endp == null?null:_endp.getRemoteHost(); 958 }
959 } 959 return getRemoteAddr();
960 return getRemoteAddr(); 960 }
961 } 961
962 962 /* ------------------------------------------------------------ */
963 /* ------------------------------------------------------------ */ 963 /*
964 /* 964 * @see javax.servlet.ServletRequest#getRemotePort()
965 * @see javax.servlet.ServletRequest#getRemotePort() 965 */
966 */ 966 public int getRemotePort()
967 public int getRemotePort() 967 {
968 { 968 return _endp == null?0:_endp.getRemotePort();
969 return _endp == null?0:_endp.getRemotePort(); 969 }
970 } 970
971 971 /* ------------------------------------------------------------ */
972 /* ------------------------------------------------------------ */ 972 /*
973 /* 973 * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
974 * @see javax.servlet.http.HttpServletRequest#getRemoteUser() 974 */
975 */ 975 public String getRemoteUser()
976 public String getRemoteUser() 976 {
977 { 977 Principal p = getUserPrincipal();
978 Principal p = getUserPrincipal(); 978 if (p == null)
979 if (p == null) 979 return null;
980 return null; 980 return p.getName();
981 return p.getName(); 981 }
982 } 982
983 983 /* ------------------------------------------------------------ */
984 /* ------------------------------------------------------------ */ 984 /*
985 /* 985 * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
986 * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String) 986 */
987 */ 987 public RequestDispatcher getRequestDispatcher(String path)
988 public RequestDispatcher getRequestDispatcher(String path) 988 {
989 { 989 if (path == null || _context == null)
990 if (path == null || _context == null) 990 return null;
991 return null; 991
992 992 // handle relative path
993 // handle relative path 993 if (!path.startsWith("/"))
994 if (!path.startsWith("/")) 994 {
995 { 995 String relTo = URIUtil.addPaths(_servletPath,_pathInfo);
996 String relTo = URIUtil.addPaths(_servletPath,_pathInfo); 996 int slash = relTo.lastIndexOf("/");
997 int slash = relTo.lastIndexOf("/"); 997 if (slash > 1)
998 if (slash > 1) 998 relTo = relTo.substring(0,slash + 1);
999 relTo = relTo.substring(0,slash + 1); 999 else
1000 else 1000 relTo = "/";
1001 relTo = "/"; 1001 path = URIUtil.addPaths(relTo,path);
1002 path = URIUtil.addPaths(relTo,path); 1002 }
1003 } 1003
1004 1004 return _context.getRequestDispatcher(path);
1005 return _context.getRequestDispatcher(path); 1005 }
1006 } 1006
1007 1007 /* ------------------------------------------------------------ */
1008 /* ------------------------------------------------------------ */ 1008 /*
1009 /* 1009 * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
1010 * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId() 1010 */
1011 */ 1011 public String getRequestedSessionId()
1012 public String getRequestedSessionId() 1012 {
1013 { 1013 return _requestedSessionId;
1014 return _requestedSessionId; 1014 }
1015 } 1015
1016 1016 /* ------------------------------------------------------------ */
1017 /* ------------------------------------------------------------ */ 1017 /*
1018 /* 1018 * @see javax.servlet.http.HttpServletRequest#getRequestURI()
1019 * @see javax.servlet.http.HttpServletRequest#getRequestURI() 1019 */
1020 */ 1020 public String getRequestURI()
1021 public String getRequestURI() 1021 {
1022 { 1022 if (_requestURI == null && _uri != null)
1023 if (_requestURI == null && _uri != null) 1023 _requestURI = _uri.getPathAndParam();
1024 _requestURI = _uri.getPathAndParam(); 1024 return _requestURI;
1025 return _requestURI; 1025 }
1026 } 1026
1027 1027 /* ------------------------------------------------------------ */
1028 /* ------------------------------------------------------------ */ 1028 /*
1029 /* 1029 * @see javax.servlet.http.HttpServletRequest#getRequestURL()
1030 * @see javax.servlet.http.HttpServletRequest#getRequestURL() 1030 */
1031 */ 1031 public StringBuffer getRequestURL()
1032 public StringBuffer getRequestURL() 1032 {
1033 { 1033 final StringBuffer url = new StringBuffer(48);
1034 final StringBuffer url = new StringBuffer(48); 1034 synchronized (url)
1035 synchronized (url) 1035 {
1036 { 1036 String scheme = getScheme();
1037 String scheme = getScheme(); 1037 int port = getServerPort();
1038 int port = getServerPort(); 1038
1039 1039 url.append(scheme);
1040 url.append(scheme); 1040 url.append("://");
1041 url.append("://"); 1041 url.append(getServerName());
1042 url.append(getServerName()); 1042 if (_port > 0 && ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443)))
1043 if (_port > 0 && ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443))) 1043 {
1044 { 1044 url.append(':');
1045 url.append(':'); 1045 url.append(_port);
1046 url.append(_port); 1046 }
1047 } 1047
1048 1048 url.append(getRequestURI());
1049 url.append(getRequestURI()); 1049 return url;
1050 return url; 1050 }
1051 } 1051 }
1052 } 1052
1053 1053 /* ------------------------------------------------------------ */
1054 /* ------------------------------------------------------------ */ 1054 public Response getResponse()
1055 public Response getResponse() 1055 {
1056 { 1056 return _connection._response;
1057 return _connection._response; 1057 }
1058 } 1058
1059 1059 /* ------------------------------------------------------------ */
1060 /* ------------------------------------------------------------ */ 1060 /**
1061 /** 1061 * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a
1062 * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a 1062 * path.
1063 * path. 1063 * <p>
1064 * <p> 1064 * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters.
1065 * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters. 1065 *
1066 * 1066 * This method is useful for creating redirect messages and for reporting errors.
1067 * This method is useful for creating redirect messages and for reporting errors. 1067 *
1068 * 1068 * @return "scheme://host:port"
1069 * @return "scheme://host:port" 1069 */
1070 */ 1070 public StringBuilder getRootURL()
1071 public StringBuilder getRootURL() 1071 {
1072 { 1072 StringBuilder url = new StringBuilder(48);
1073 StringBuilder url = new StringBuilder(48); 1073 String scheme = getScheme();
1074 String scheme = getScheme(); 1074 int port = getServerPort();
1075 int port = getServerPort(); 1075
1076 1076 url.append(scheme);
1077 url.append(scheme); 1077 url.append("://");
1078 url.append("://"); 1078 url.append(getServerName());
1079 url.append(getServerName()); 1079
1080 1080 if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443)))
1081 if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443))) 1081 {
1082 { 1082 url.append(':');
1083 url.append(':'); 1083 url.append(port);
1084 url.append(port); 1084 }
1085 } 1085 return url;
1086 return url; 1086 }
1087 } 1087
1088 1088 /* ------------------------------------------------------------ */
1089 /* ------------------------------------------------------------ */ 1089 /*
1090 /* 1090 * @see javax.servlet.ServletRequest#getScheme()
1091 * @see javax.servlet.ServletRequest#getScheme() 1091 */
1092 */ 1092 public String getScheme()
1093 public String getScheme() 1093 {
1094 { 1094 return _scheme;
1095 return _scheme; 1095 }
1096 } 1096
1097 1097 /* ------------------------------------------------------------ */
1098 /* ------------------------------------------------------------ */ 1098 /*
1099 /* 1099 * @see javax.servlet.ServletRequest#getServerName()
1100 * @see javax.servlet.ServletRequest#getServerName() 1100 */
1101 */ 1101 public String getServerName()
1102 public String getServerName() 1102 {
1103 { 1103 // Return already determined host
1104 // Return already determined host 1104 if (_serverName != null)
1105 if (_serverName != null) 1105 return _serverName;
1106 return _serverName; 1106
1107 1107 if (_uri == null)
1108 if (_uri == null) 1108 throw new IllegalStateException("No uri");
1109 throw new IllegalStateException("No uri"); 1109
1110 1110 // Return host from absolute URI
1111 // Return host from absolute URI 1111 _serverName = _uri.getHost();
1112 _serverName = _uri.getHost(); 1112 _port = _uri.getPort();
1113 _port = _uri.getPort(); 1113 if (_serverName != null)
1114 if (_serverName != null) 1114 return _serverName;
1115 return _serverName; 1115
1116 1116 // Return host from header field
1117 // Return host from header field 1117 Buffer hostPort = _connection.getRequestFields().get(HttpHeaders.HOST_BUFFER);
1118 Buffer hostPort = _connection.getRequestFields().get(HttpHeaders.HOST_BUFFER); 1118 if (hostPort != null)
1119 if (hostPort != null) 1119 {
1120 { 1120 loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();)
1121 loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();) 1121 {
1122 { 1122 char ch = (char)(0xff & hostPort.peek(i));
1123 char ch = (char)(0xff & hostPort.peek(i)); 1123 switch (ch)
1124 switch (ch) 1124 {
1125 { 1125 case ']':
1126 case ']': 1126 break loop;
1127 break loop; 1127
1128 1128 case ':':
1129 case ':': 1129 _serverName = BufferUtil.to8859_1_String(hostPort.peek(hostPort.getIndex(),i - hostPort.getIndex()));
1130 _serverName = BufferUtil.to8859_1_String(hostPort.peek(hostPort.getIndex(),i - hostPort.getIndex())); 1130 try
1131 try 1131 {
1132 { 1132 _port = BufferUtil.toInt(hostPort.peek(i + 1,hostPort.putIndex() - i - 1));
1133 _port = BufferUtil.toInt(hostPort.peek(i + 1,hostPort.putIndex() - i - 1)); 1133 }
1134 } 1134 catch (NumberFormatException e)
1135 catch (NumberFormatException e) 1135 {
1136 { 1136 try
1137 try 1137 {
1138 { 1138 if (_connection != null)
1139 if (_connection != null) 1139 _connection._generator.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true);
1140 _connection._generator.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true); 1140 }
1141 } 1141 catch (IOException e1)
1142 catch (IOException e1) 1142 {
1143 { 1143 throw new RuntimeException(e1);
1144 throw new RuntimeException(e1); 1144 }
1145 } 1145 }
1146 } 1146 return _serverName;
1147 return _serverName; 1147 }
1148 } 1148 }
1149 } 1149 if (_serverName == null || _port < 0)
1150 if (_serverName == null || _port < 0) 1150 {
1151 { 1151 _serverName = BufferUtil.to8859_1_String(hostPort);
1152 _serverName = BufferUtil.to8859_1_String(hostPort); 1152 _port = 0;
1153 _port = 0; 1153 }
1154 } 1154
1155 1155 return _serverName;
1156 return _serverName; 1156 }
1157 } 1157
1158 1158 // Return host from connection
1159 // Return host from connection 1159 if (_connection != null)
1160 if (_connection != null) 1160 {
1161 { 1161 _serverName = getLocalName();
1162 _serverName = getLocalName(); 1162 _port = getLocalPort();
1163 _port = getLocalPort(); 1163 if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName))
1164 if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName)) 1164 return _serverName;
1165 return _serverName; 1165 }
1166 } 1166
1167 1167 // Return the local host
1168 // Return the local host 1168 try
1169 try 1169 {
1170 { 1170 _serverName = InetAddress.getLocalHost().getHostAddress();
1171 _serverName = InetAddress.getLocalHost().getHostAddress(); 1171 }
1172 } 1172 catch (java.net.UnknownHostException e)
1173 catch (java.net.UnknownHostException e) 1173 {
1174 { 1174 LOG.ignore(e);
1175 LOG.ignore(e); 1175 }
1176 } 1176 return _serverName;
1177 return _serverName; 1177 }
1178 } 1178
1179 1179 /* ------------------------------------------------------------ */
1180 /* ------------------------------------------------------------ */ 1180 /*
1181 /* 1181 * @see javax.servlet.ServletRequest#getServerPort()
1182 * @see javax.servlet.ServletRequest#getServerPort() 1182 */
1183 */ 1183 public int getServerPort()
1184 public int getServerPort() 1184 {
1185 { 1185 if (_port <= 0)
1186 if (_port <= 0) 1186 {
1187 { 1187 if (_serverName == null)
1188 if (_serverName == null) 1188 getServerName();
1189 getServerName(); 1189
1190 1190 if (_port <= 0)
1191 if (_port <= 0) 1191 {
1192 { 1192 if (_serverName != null && _uri != null)
1193 if (_serverName != null && _uri != null) 1193 _port = _uri.getPort();
1194 _port = _uri.getPort(); 1194 else
1195 else 1195 _port = _endp == null?0:_endp.getLocalPort();
1196 _port = _endp == null?0:_endp.getLocalPort(); 1196 }
1197 } 1197 }
1198 } 1198
1199 1199 if (_port <= 0)
1200 if (_port <= 0) 1200 {
1201 { 1201 if (getScheme().equalsIgnoreCase(URIUtil.HTTPS))
1202 if (getScheme().equalsIgnoreCase(URIUtil.HTTPS)) 1202 return 443;
1203 return 443; 1203 return 80;
1204 return 80; 1204 }
1205 } 1205 return _port;
1206 return _port; 1206 }
1207 } 1207
1208 1208 /* ------------------------------------------------------------ */
1209 /* ------------------------------------------------------------ */ 1209 public ServletContext getServletContext()
1210 public ServletContext getServletContext() 1210 {
1211 { 1211 return _context;
1212 return _context; 1212 }
1213 } 1213
1214 1214 /* ------------------------------------------------------------ */
1215 /* ------------------------------------------------------------ */ 1215 /*
1216 /* 1216 */
1217 */ 1217 public String getServletName()
1218 public String getServletName() 1218 {
1219 { 1219 if (_scope != null)
1220 if (_scope != null) 1220 return _scope.getName();
1221 return _scope.getName(); 1221 return null;
1222 return null; 1222 }
1223 } 1223
1224 1224 /* ------------------------------------------------------------ */
1225 /* ------------------------------------------------------------ */ 1225 /*
1226 /* 1226 * @see javax.servlet.http.HttpServletRequest#getServletPath()
1227 * @see javax.servlet.http.HttpServletRequest#getServletPath() 1227 */
1228 */ 1228 public String getServletPath()
1229 public String getServletPath() 1229 {
1230 { 1230 if (_servletPath == null)
1231 if (_servletPath == null) 1231 _servletPath = "";
1232 _servletPath = ""; 1232 return _servletPath;
1233 return _servletPath; 1233 }
1234 } 1234
1235 1235 /* ------------------------------------------------------------ */
1236 /* ------------------------------------------------------------ */ 1236 public ServletResponse getServletResponse()
1237 public ServletResponse getServletResponse() 1237 {
1238 { 1238 return _connection.getResponse();
1239 return _connection.getResponse(); 1239 }
1240 } 1240
1241 1241 /* ------------------------------------------------------------ */
1242 /* ------------------------------------------------------------ */ 1242 /*
1243 /* 1243 * @see javax.servlet.http.HttpServletRequest#getSession()
1244 * @see javax.servlet.http.HttpServletRequest#getSession() 1244 */
1245 */ 1245 public HttpSession getSession()
1246 public HttpSession getSession() 1246 {
1247 { 1247 return getSession(true);
1248 return getSession(true); 1248 }
1249 } 1249
1250 1250 /* ------------------------------------------------------------ */
1251 /* ------------------------------------------------------------ */ 1251 /*
1252 /* 1252 * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
1253 * @see javax.servlet.http.HttpServletRequest#getSession(boolean) 1253 */
1254 */ 1254 public HttpSession getSession(boolean create)
1255 public HttpSession getSession(boolean create) 1255 {
1256 { 1256 throw new UnsupportedOperationException();
1257 if (_session != null) 1257 }
1258 { 1258
1259 if (_sessionManager != null && !_sessionManager.isValid(_session)) 1259 /* ------------------------------------------------------------ */
1260 _session = null; 1260 /**
1261 else 1261 * Get Request TimeStamp
1262 return _session; 1262 *
1263 } 1263 * @return The time that the request was received.
1264 1264 */
1265 if (!create) 1265 public long getTimeStamp()
1266 return null; 1266 {
1267 1267 return _timeStamp;
1268 if (_sessionManager == null) 1268 }
1269 throw new IllegalStateException("No SessionManager"); 1269
1270 1270 /* ------------------------------------------------------------ */
1271 _session = _sessionManager.newHttpSession(this); 1271 /**
1272 HttpCookie cookie = _sessionManager.getSessionCookie(_session,getContextPath(),isSecure()); 1272 * Get Request TimeStamp
1273 if (cookie != null) 1273 *
1274 _connection.getResponse().addCookie(cookie); 1274 * @return The time that the request was received.
1275 1275 */
1276 return _session; 1276 public Buffer getTimeStampBuffer()
1277 } 1277 {
1278 1278 if (_timeStampBuffer == null && _timeStamp > 0)
1279 /* ------------------------------------------------------------ */ 1279 _timeStampBuffer = HttpFields.__dateCache.formatBuffer(_timeStamp);
1280 /** 1280 return _timeStampBuffer;
1281 * @return Returns the sessionManager. 1281 }
1282 */ 1282
1283 public SessionManager getSessionManager() 1283 /* ------------------------------------------------------------ */
1284 { 1284 /**
1285 return _sessionManager; 1285 * @return Returns the uri.
1286 } 1286 */
1287 1287 public HttpURI getUri()
1288 /* ------------------------------------------------------------ */ 1288 {
1289 /** 1289 return _uri;
1290 * Get Request TimeStamp 1290 }
1291 * 1291
1292 * @return The time that the request was received. 1292 /* ------------------------------------------------------------ */
1293 */ 1293 public UserIdentity getUserIdentity()
1294 public long getTimeStamp() 1294 {
1295 { 1295 if (_authentication instanceof Authentication.Deferred)
1296 return _timeStamp; 1296 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this));
1297 } 1297
1298 1298 if (_authentication instanceof Authentication.User)
1299 /* ------------------------------------------------------------ */ 1299 return ((Authentication.User)_authentication).getUserIdentity();
1300 /** 1300 return null;
1301 * Get Request TimeStamp 1301 }
1302 * 1302
1303 * @return The time that the request was received. 1303 /* ------------------------------------------------------------ */
1304 */ 1304 /**
1305 public Buffer getTimeStampBuffer() 1305 * @return The resolved user Identity, which may be null if the {@link Authentication} is not {@link Authentication.User} (eg.
1306 { 1306 * {@link Authentication.Deferred}).
1307 if (_timeStampBuffer == null && _timeStamp > 0) 1307 */
1308 _timeStampBuffer = HttpFields.__dateCache.formatBuffer(_timeStamp); 1308 public UserIdentity getResolvedUserIdentity()
1309 return _timeStampBuffer; 1309 {
1310 } 1310 if (_authentication instanceof Authentication.User)
1311 1311 return ((Authentication.User)_authentication).getUserIdentity();
1312 /* ------------------------------------------------------------ */ 1312 return null;
1313 /** 1313 }
1314 * @return Returns the uri. 1314
1315 */ 1315 /* ------------------------------------------------------------ */
1316 public HttpURI getUri() 1316 public UserIdentity.Scope getUserIdentityScope()
1317 { 1317 {
1318 return _uri; 1318 return _scope;
1319 } 1319 }
1320 1320
1321 /* ------------------------------------------------------------ */ 1321 /* ------------------------------------------------------------ */
1322 public UserIdentity getUserIdentity() 1322 /*
1323 { 1323 * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
1324 if (_authentication instanceof Authentication.Deferred) 1324 */
1325 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this)); 1325 public Principal getUserPrincipal()
1326 1326 {
1327 if (_authentication instanceof Authentication.User) 1327 if (_authentication instanceof Authentication.Deferred)
1328 return ((Authentication.User)_authentication).getUserIdentity(); 1328 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this));
1329 return null; 1329
1330 } 1330 if (_authentication instanceof Authentication.User)
1331 1331 {
1332 /* ------------------------------------------------------------ */ 1332 UserIdentity user = ((Authentication.User)_authentication).getUserIdentity();
1333 /** 1333 return user.getUserPrincipal();
1334 * @return The resolved user Identity, which may be null if the {@link Authentication} is not {@link Authentication.User} (eg. 1334 }
1335 * {@link Authentication.Deferred}). 1335
1336 */ 1336 return null;
1337 public UserIdentity getResolvedUserIdentity() 1337 }
1338 { 1338
1339 if (_authentication instanceof Authentication.User) 1339 /* ------------------------------------------------------------ */
1340 return ((Authentication.User)_authentication).getUserIdentity(); 1340 /**
1341 return null; 1341 * Get timestamp of the request dispatch
1342 } 1342 *
1343 1343 * @return timestamp
1344 /* ------------------------------------------------------------ */ 1344 */
1345 public UserIdentity.Scope getUserIdentityScope() 1345 public long getDispatchTime()
1346 { 1346 {
1347 return _scope; 1347 return _dispatchTime;
1348 } 1348 }
1349 1349
1350 /* ------------------------------------------------------------ */ 1350 /* ------------------------------------------------------------ */
1351 /* 1351 public boolean isHandled()
1352 * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() 1352 {
1353 */ 1353 return _handled;
1354 public Principal getUserPrincipal() 1354 }
1355 { 1355
1356 if (_authentication instanceof Authentication.Deferred) 1356 public boolean isAsyncStarted()
1357 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this)); 1357 {
1358 1358 return _async.isAsyncStarted();
1359 if (_authentication instanceof Authentication.User) 1359 }
1360 { 1360
1361 UserIdentity user = ((Authentication.User)_authentication).getUserIdentity(); 1361
1362 return user.getUserPrincipal(); 1362 /* ------------------------------------------------------------ */
1363 } 1363 public boolean isAsyncSupported()
1364 1364 {
1365 return null; 1365 return _asyncSupported;
1366 } 1366 }
1367 1367
1368 /* ------------------------------------------------------------ */ 1368 /* ------------------------------------------------------------ */
1369 /** 1369 /*
1370 * Get timestamp of the request dispatch 1370 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
1371 * 1371 */
1372 * @return timestamp 1372 public boolean isRequestedSessionIdFromCookie()
1373 */ 1373 {
1374 public long getDispatchTime() 1374 return _requestedSessionId != null && _requestedSessionIdFromCookie;
1375 { 1375 }
1376 return _dispatchTime; 1376
1377 } 1377 /* ------------------------------------------------------------ */
1378 1378 /*
1379 /* ------------------------------------------------------------ */ 1379 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
1380 public boolean isHandled() 1380 */
1381 { 1381 public boolean isRequestedSessionIdFromUrl()
1382 return _handled; 1382 {
1383 } 1383 return _requestedSessionId != null && !_requestedSessionIdFromCookie;
1384 1384 }
1385 public boolean isAsyncStarted() 1385
1386 { 1386 /* ------------------------------------------------------------ */
1387 return _async.isAsyncStarted(); 1387 /*
1388 } 1388 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
1389 1389 */
1390 1390 public boolean isRequestedSessionIdFromURL()
1391 /* ------------------------------------------------------------ */ 1391 {
1392 public boolean isAsyncSupported() 1392 return _requestedSessionId != null && !_requestedSessionIdFromCookie;
1393 { 1393 }
1394 return _asyncSupported; 1394
1395 } 1395 /* ------------------------------------------------------------ */
1396 1396 /*
1397 /* ------------------------------------------------------------ */ 1397 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
1398 /* 1398 */
1399 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() 1399 public boolean isRequestedSessionIdValid()
1400 */ 1400 {
1401 public boolean isRequestedSessionIdFromCookie() 1401 throw new UnsupportedOperationException();
1402 { 1402 }
1403 return _requestedSessionId != null && _requestedSessionIdFromCookie; 1403
1404 } 1404 /* ------------------------------------------------------------ */
1405 1405 /*
1406 /* ------------------------------------------------------------ */ 1406 * @see javax.servlet.ServletRequest#isSecure()
1407 /* 1407 */
1408 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() 1408 public boolean isSecure()
1409 */ 1409 {
1410 public boolean isRequestedSessionIdFromUrl() 1410 return _connection.isConfidential(this);
1411 { 1411 }
1412 return _requestedSessionId != null && !_requestedSessionIdFromCookie; 1412
1413 } 1413 /* ------------------------------------------------------------ */
1414 1414 /*
1415 /* ------------------------------------------------------------ */ 1415 * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
1416 /* 1416 */
1417 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() 1417 public boolean isUserInRole(String role)
1418 */ 1418 {
1419 public boolean isRequestedSessionIdFromURL() 1419 if (_authentication instanceof Authentication.Deferred)
1420 { 1420 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this));
1421 return _requestedSessionId != null && !_requestedSessionIdFromCookie; 1421
1422 } 1422 if (_authentication instanceof Authentication.User)
1423 1423 return ((Authentication.User)_authentication).isUserInRole(_scope,role);
1424 /* ------------------------------------------------------------ */ 1424 return false;
1425 /* 1425 }
1426 * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() 1426
1427 */ 1427 /* ------------------------------------------------------------ */
1428 public boolean isRequestedSessionIdValid() 1428 public HttpSession recoverNewSession(Object key)
1429 { 1429 {
1430 if (_requestedSessionId == null) 1430 if (_savedNewSessions == null)
1431 return false; 1431 return null;
1432 1432 return _savedNewSessions.get(key);
1433 HttpSession session = getSession(false); 1433 }
1434 return (session != null && _sessionManager.getSessionIdManager().getClusterId(_requestedSessionId).equals(_sessionManager.getClusterId(session))); 1434
1435 } 1435 /* ------------------------------------------------------------ */
1436 1436 protected void recycle()
1437 /* ------------------------------------------------------------ */ 1437 {
1438 /* 1438 if (_inputState == __READER)
1439 * @see javax.servlet.ServletRequest#isSecure() 1439 {
1440 */ 1440 try
1441 public boolean isSecure() 1441 {
1442 { 1442 int r = _reader.read();
1443 return _connection.isConfidential(this); 1443 while (r != -1)
1444 } 1444 r = _reader.read();
1445 1445 }
1446 /* ------------------------------------------------------------ */ 1446 catch (Exception e)
1447 /* 1447 {
1448 * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) 1448 LOG.ignore(e);
1449 */ 1449 _reader = null;
1450 public boolean isUserInRole(String role) 1450 }
1451 { 1451 }
1452 if (_authentication instanceof Authentication.Deferred) 1452
1453 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this)); 1453 setAuthentication(Authentication.NOT_CHECKED);
1454 1454 _async.recycle();
1455 if (_authentication instanceof Authentication.User) 1455 _asyncSupported = true;
1456 return ((Authentication.User)_authentication).isUserInRole(_scope,role); 1456 _handled = false;
1457 return false; 1457 if (_context != null)
1458 } 1458 throw new IllegalStateException("Request in context!");
1459 1459 if (_attributes != null)
1460 /* ------------------------------------------------------------ */ 1460 _attributes.clearAttributes();
1461 public HttpSession recoverNewSession(Object key) 1461 _characterEncoding = null;
1462 { 1462 _contextPath = null;
1463 if (_savedNewSessions == null) 1463 if (_cookies != null)
1464 return null; 1464 _cookies.reset();
1465 return _savedNewSessions.get(key); 1465 _cookiesExtracted = false;
1466 } 1466 _context = null;
1467 1467 _serverName = null;
1468 /* ------------------------------------------------------------ */ 1468 _method = null;
1469 protected void recycle() 1469 _pathInfo = null;
1470 { 1470 _port = 0;
1471 if (_inputState == __READER) 1471 _protocol = HttpVersions.HTTP_1_1;
1472 { 1472 _queryEncoding = null;
1473 try 1473 _queryString = null;
1474 { 1474 _requestedSessionId = null;
1475 int r = _reader.read(); 1475 _requestedSessionIdFromCookie = false;
1476 while (r != -1) 1476 _session = null;
1477 r = _reader.read(); 1477 _requestURI = null;
1478 } 1478 _scope = null;
1479 catch (Exception e) 1479 _scheme = URIUtil.HTTP;
1480 { 1480 _servletPath = null;
1481 LOG.ignore(e); 1481 _timeStamp = 0;
1482 _reader = null; 1482 _timeStampBuffer = null;
1483 } 1483 _uri = null;
1484 } 1484 if (_baseParameters != null)
1485 1485 _baseParameters.clear();
1486 setAuthentication(Authentication.NOT_CHECKED); 1486 _parameters = null;
1487 _async.recycle(); 1487 _paramsExtracted = false;
1488 _asyncSupported = true; 1488 _inputState = __NONE;
1489 _handled = false; 1489
1490 if (_context != null) 1490 if (_savedNewSessions != null)
1491 throw new IllegalStateException("Request in context!"); 1491 _savedNewSessions.clear();
1492 if (_attributes != null) 1492 _savedNewSessions=null;
1493 _attributes.clearAttributes(); 1493 _multiPartInputStream = null;
1494 _characterEncoding = null; 1494 }
1495 _contextPath = null; 1495
1496 if (_cookies != null) 1496 /* ------------------------------------------------------------ */
1497 _cookies.reset(); 1497 /*
1498 _cookiesExtracted = false; 1498 * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
1499 _context = null; 1499 */
1500 _serverName = null; 1500 public void removeAttribute(String name)
1501 _method = null; 1501 {
1502 _pathInfo = null; 1502 Object old_value = _attributes == null?null:_attributes.getAttribute(name);
1503 _port = 0; 1503
1504 _protocol = HttpVersions.HTTP_1_1; 1504 if (_attributes != null)
1505 _queryEncoding = null; 1505 _attributes.removeAttribute(name);
1506 _queryString = null; 1506
1507 _requestedSessionId = null; 1507 if (old_value != null)
1508 _requestedSessionIdFromCookie = false; 1508 {
1509 _session = null; 1509 if (_requestAttributeListeners != null)
1510 _sessionManager = null; 1510 {
1511 _requestURI = null; 1511 final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value);
1512 _scope = null; 1512 final int size = LazyList.size(_requestAttributeListeners);
1513 _scheme = URIUtil.HTTP; 1513 for (int i = 0; i < size; i++)
1514 _servletPath = null; 1514 {
1515 _timeStamp = 0; 1515 final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i);
1516 _timeStampBuffer = null; 1516 if (listener instanceof ServletRequestAttributeListener)
1517 _uri = null; 1517 {
1518 if (_baseParameters != null) 1518 final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener;
1519 _baseParameters.clear(); 1519 l.attributeRemoved(event);
1520 _parameters = null; 1520 }
1521 _paramsExtracted = false; 1521 }
1522 _inputState = __NONE; 1522 }
1523 1523 }
1524 if (_savedNewSessions != null) 1524 }
1525 _savedNewSessions.clear(); 1525
1526 _savedNewSessions=null; 1526 /* ------------------------------------------------------------ */
1527 _multiPartInputStream = null; 1527 public void removeEventListener(final EventListener listener)
1528 } 1528 {
1529 1529 _requestAttributeListeners = LazyList.remove(_requestAttributeListeners,listener);
1530 /* ------------------------------------------------------------ */ 1530 }
1531 /* 1531
1532 * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String) 1532 /* ------------------------------------------------------------ */
1533 */ 1533 public void saveNewSession(Object key, HttpSession session)
1534 public void removeAttribute(String name) 1534 {
1535 { 1535 if (_savedNewSessions == null)
1536 Object old_value = _attributes == null?null:_attributes.getAttribute(name); 1536 _savedNewSessions = new HashMap<Object, HttpSession>();
1537 1537 _savedNewSessions.put(key,session);
1538 if (_attributes != null) 1538 }
1539 _attributes.removeAttribute(name); 1539
1540 1540 /* ------------------------------------------------------------ */
1541 if (old_value != null) 1541 public void setAsyncSupported(boolean supported)
1542 { 1542 {
1543 if (_requestAttributeListeners != null) 1543 _asyncSupported = supported;
1544 { 1544 }
1545 final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value); 1545
1546 final int size = LazyList.size(_requestAttributeListeners); 1546 /* ------------------------------------------------------------ */
1547 for (int i = 0; i < size; i++) 1547 /*
1548 { 1548 * Set a request attribute. if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then the value is also passed in a call to
1549 final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i); 1549 * {@link #setQueryEncoding}. <p> if the attribute name is "org.eclipse.jetty.server.server.ResponseBuffer", then the response buffer is flushed with @{link
1550 if (listener instanceof ServletRequestAttributeListener) 1550 * #flushResponseBuffer} <p> if the attribute name is "org.eclipse.jetty.io.EndPoint.maxIdleTime", then the value is passed to the associated {@link
1551 { 1551 * EndPoint#setMaxIdleTime}.
1552 final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener; 1552 *
1553 l.attributeRemoved(event); 1553 * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
1554 } 1554 */
1555 } 1555 public void setAttribute(String name, Object value)
1556 } 1556 {
1557 } 1557 Object old_value = _attributes == null?null:_attributes.getAttribute(name);
1558 } 1558
1559 1559 if (name.startsWith("org.eclipse.jetty."))
1560 /* ------------------------------------------------------------ */ 1560 {
1561 public void removeEventListener(final EventListener listener) 1561 if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name))
1562 { 1562 setQueryEncoding(value == null?null:value.toString());
1563 _requestAttributeListeners = LazyList.remove(_requestAttributeListeners,listener); 1563 else if ("org.eclipse.jetty.server.sendContent".equals(name))
1564 } 1564 {
1565 1565 try
1566 /* ------------------------------------------------------------ */ 1566 {
1567 public void saveNewSession(Object key, HttpSession session) 1567 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendContent(value);
1568 { 1568 }
1569 if (_savedNewSessions == null) 1569 catch (IOException e)
1570 _savedNewSessions = new HashMap<Object, HttpSession>(); 1570 {
1571 _savedNewSessions.put(key,session); 1571 throw new RuntimeException(e);
1572 } 1572 }
1573 1573 }
1574 /* ------------------------------------------------------------ */ 1574 else if ("org.eclipse.jetty.server.ResponseBuffer".equals(name))
1575 public void setAsyncSupported(boolean supported) 1575 {
1576 { 1576 try
1577 _asyncSupported = supported; 1577 {
1578 } 1578 final ByteBuffer byteBuffer = (ByteBuffer)value;
1579 1579 synchronized (byteBuffer)
1580 /* ------------------------------------------------------------ */ 1580 {
1581 /* 1581 NIOBuffer buffer = byteBuffer.isDirect()?new DirectNIOBuffer(byteBuffer,true):new IndirectNIOBuffer(byteBuffer,true);
1582 * Set a request attribute. if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then the value is also passed in a call to 1582 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer);
1583 * {@link #setQueryEncoding}. <p> if the attribute name is "org.eclipse.jetty.server.server.ResponseBuffer", then the response buffer is flushed with @{link 1583 }
1584 * #flushResponseBuffer} <p> if the attribute name is "org.eclipse.jetty.io.EndPoint.maxIdleTime", then the value is passed to the associated {@link 1584 }
1585 * EndPoint#setMaxIdleTime}. 1585 catch (IOException e)
1586 * 1586 {
1587 * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object) 1587 throw new RuntimeException(e);
1588 */ 1588 }
1589 public void setAttribute(String name, Object value) 1589 }
1590 { 1590 else if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name))
1591 Object old_value = _attributes == null?null:_attributes.getAttribute(name); 1591 {
1592 1592 try
1593 if (name.startsWith("org.eclipse.jetty.")) 1593 {
1594 { 1594 getConnection().getEndPoint().setMaxIdleTime(Integer.valueOf(value.toString()));
1595 if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name)) 1595 }
1596 setQueryEncoding(value == null?null:value.toString()); 1596 catch (IOException e)
1597 else if ("org.eclipse.jetty.server.sendContent".equals(name)) 1597 {
1598 { 1598 throw new RuntimeException(e);
1599 try 1599 }
1600 { 1600 }
1601 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendContent(value); 1601 }
1602 } 1602
1603 catch (IOException e) 1603 if (_attributes == null)
1604 { 1604 _attributes = new AttributesMap();
1605 throw new RuntimeException(e); 1605 _attributes.setAttribute(name,value);
1606 } 1606
1607 } 1607 if (_requestAttributeListeners != null)
1608 else if ("org.eclipse.jetty.server.ResponseBuffer".equals(name)) 1608 {
1609 { 1609 final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value == null?value:old_value);
1610 try 1610 final int size = LazyList.size(_requestAttributeListeners);
1611 { 1611 for (int i = 0; i < size; i++)
1612 final ByteBuffer byteBuffer = (ByteBuffer)value; 1612 {
1613 synchronized (byteBuffer) 1613 final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i);
1614 { 1614 if (listener instanceof ServletRequestAttributeListener)
1615 NIOBuffer buffer = byteBuffer.isDirect()?new DirectNIOBuffer(byteBuffer,true):new IndirectNIOBuffer(byteBuffer,true); 1615 {
1616 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer); 1616 final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener;
1617 } 1617
1618 } 1618 if (old_value == null)
1619 catch (IOException e) 1619 l.attributeAdded(event);
1620 { 1620 else if (value == null)
1621 throw new RuntimeException(e); 1621 l.attributeRemoved(event);
1622 } 1622 else
1623 } 1623 l.attributeReplaced(event);
1624 else if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name)) 1624 }
1625 { 1625 }
1626 try 1626 }
1627 { 1627 }
1628 getConnection().getEndPoint().setMaxIdleTime(Integer.valueOf(value.toString())); 1628
1629 } 1629 /* ------------------------------------------------------------ */
1630 catch (IOException e) 1630 /*
1631 { 1631 */
1632 throw new RuntimeException(e); 1632 public void setAttributes(Attributes attributes)
1633 } 1633 {
1634 } 1634 _attributes = attributes;
1635 } 1635 }
1636 1636
1637 if (_attributes == null) 1637 /* ------------------------------------------------------------ */
1638 _attributes = new AttributesMap(); 1638
1639 _attributes.setAttribute(name,value); 1639 /* ------------------------------------------------------------ */
1640 1640 /**
1641 if (_requestAttributeListeners != null) 1641 * Set the authentication.
1642 { 1642 *
1643 final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value == null?value:old_value); 1643 * @param authentication
1644 final int size = LazyList.size(_requestAttributeListeners); 1644 * the authentication to set
1645 for (int i = 0; i < size; i++) 1645 */
1646 { 1646 public void setAuthentication(Authentication authentication)
1647 final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i); 1647 {
1648 if (listener instanceof ServletRequestAttributeListener) 1648 _authentication = authentication;
1649 { 1649 }
1650 final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener; 1650
1651 1651 /* ------------------------------------------------------------ */
1652 if (old_value == null) 1652 /*
1653 l.attributeAdded(event); 1653 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
1654 else if (value == null) 1654 */
1655 l.attributeRemoved(event); 1655 public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
1656 else 1656 {
1657 l.attributeReplaced(event); 1657 if (_inputState != __NONE)
1658 } 1658 return;
1659 } 1659
1660 } 1660 _characterEncoding = encoding;
1661 } 1661
1662 1662 // check encoding is supported
1663 /* ------------------------------------------------------------ */ 1663 if (!StringUtil.isUTF8(encoding))
1664 /* 1664 // noinspection ResultOfMethodCallIgnored
1665 */ 1665 "".getBytes(encoding);
1666 public void setAttributes(Attributes attributes) 1666 }
1667 { 1667
1668 _attributes = attributes; 1668 /* ------------------------------------------------------------ */
1669 } 1669 /*
1670 1670 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
1671 /* ------------------------------------------------------------ */ 1671 */
1672 1672 public void setCharacterEncodingUnchecked(String encoding)
1673 /* ------------------------------------------------------------ */ 1673 {
1674 /** 1674 _characterEncoding = encoding;
1675 * Set the authentication. 1675 }
1676 * 1676
1677 * @param authentication 1677 /* ------------------------------------------------------------ */
1678 * the authentication to set 1678 // final so we can safely call this from constructor
1679 */ 1679 protected final void setConnection(AbstractHttpConnection connection)
1680 public void setAuthentication(Authentication authentication) 1680 {
1681 { 1681 _connection = connection;
1682 _authentication = authentication; 1682 _async.setConnection(connection);
1683 } 1683 _endp = connection.getEndPoint();
1684 1684 _dns = connection.getResolveNames();
1685 /* ------------------------------------------------------------ */ 1685 }
1686 /* 1686
1687 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) 1687 /* ------------------------------------------------------------ */
1688 */ 1688 /*
1689 public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException 1689 * @see javax.servlet.ServletRequest#getContentType()
1690 { 1690 */
1691 if (_inputState != __NONE) 1691 public void setContentType(String contentType)
1692 return; 1692 {
1693 1693 _connection.getRequestFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType);
1694 _characterEncoding = encoding; 1694
1695 1695 }
1696 // check encoding is supported 1696
1697 if (!StringUtil.isUTF8(encoding)) 1697 /* ------------------------------------------------------------ */
1698 // noinspection ResultOfMethodCallIgnored 1698 /**
1699 "".getBytes(encoding); 1699 * Set request context
1700 } 1700 *
1701 1701 * @param context
1702 /* ------------------------------------------------------------ */ 1702 * context object
1703 /* 1703 */
1704 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) 1704 public void setContext(Context context)
1705 */ 1705 {
1706 public void setCharacterEncodingUnchecked(String encoding) 1706 _newContext = _context != context;
1707 { 1707 _context = context;
1708 _characterEncoding = encoding; 1708 }
1709 } 1709
1710 1710 /* ------------------------------------------------------------ */
1711 /* ------------------------------------------------------------ */ 1711 /**
1712 // final so we can safely call this from constructor 1712 * @return True if this is the first call of {@link #takeNewContext()} since the last
1713 protected final void setConnection(AbstractHttpConnection connection) 1713 * {@link #setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)} call.
1714 { 1714 */
1715 _connection = connection; 1715 public boolean takeNewContext()
1716 _async.setConnection(connection); 1716 {
1717 _endp = connection.getEndPoint(); 1717 boolean nc = _newContext;
1718 _dns = connection.getResolveNames(); 1718 _newContext = false;
1719 } 1719 return nc;
1720 1720 }
1721 /* ------------------------------------------------------------ */ 1721
1722 /* 1722 /* ------------------------------------------------------------ */
1723 * @see javax.servlet.ServletRequest#getContentType() 1723 /**
1724 */ 1724 * Sets the "context path" for this request
1725 public void setContentType(String contentType) 1725 *
1726 { 1726 * @see HttpServletRequest#getContextPath()
1727 _connection.getRequestFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType); 1727 */
1728 1728 public void setContextPath(String contextPath)
1729 } 1729 {
1730 1730 _contextPath = contextPath;
1731 /* ------------------------------------------------------------ */ 1731 }
1732 /** 1732
1733 * Set request context 1733 /* ------------------------------------------------------------ */
1734 * 1734 /**
1735 * @param context 1735 * @param cookies
1736 * context object 1736 * The cookies to set.
1737 */ 1737 */
1738 public void setContext(Context context) 1738 public void setCookies(Cookie[] cookies)
1739 { 1739 {
1740 _newContext = _context != context; 1740 if (_cookies == null)
1741 _context = context; 1741 _cookies = new CookieCutter();
1742 } 1742 _cookies.setCookies(cookies);
1743 1743 }
1744 /* ------------------------------------------------------------ */ 1744
1745 /** 1745 /* ------------------------------------------------------------ */
1746 * @return True if this is the first call of {@link #takeNewContext()} since the last 1746 public void setDispatcherType(DispatcherType type)
1747 * {@link #setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)} call. 1747 {
1748 */ 1748 _dispatcherType = type;
1749 public boolean takeNewContext() 1749 }
1750 { 1750
1751 boolean nc = _newContext; 1751 /* ------------------------------------------------------------ */
1752 _newContext = false; 1752 public void setHandled(boolean h)
1753 return nc; 1753 {
1754 } 1754 _handled = h;
1755 1755 }
1756 /* ------------------------------------------------------------ */ 1756
1757 /** 1757 /* ------------------------------------------------------------ */
1758 * Sets the "context path" for this request 1758 /**
1759 * 1759 * @param method
1760 * @see HttpServletRequest#getContextPath() 1760 * The method to set.
1761 */ 1761 */
1762 public void setContextPath(String contextPath) 1762 public void setMethod(String method)
1763 { 1763 {
1764 _contextPath = contextPath; 1764 _method = method;
1765 } 1765 }
1766 1766
1767 /* ------------------------------------------------------------ */ 1767 /* ------------------------------------------------------------ */
1768 /** 1768 /**
1769 * @param cookies 1769 * @param parameters
1770 * The cookies to set. 1770 * The parameters to set.
1771 */ 1771 */
1772 public void setCookies(Cookie[] cookies) 1772 public void setParameters(MultiMap<String> parameters)
1773 { 1773 {
1774 if (_cookies == null) 1774 _parameters = (parameters == null)?_baseParameters:parameters;
1775 _cookies = new CookieCutter(); 1775 if (_paramsExtracted && _parameters == null)
1776 _cookies.setCookies(cookies); 1776 throw new IllegalStateException();
1777 } 1777 }
1778 1778
1779 /* ------------------------------------------------------------ */ 1779 /* ------------------------------------------------------------ */
1780 public void setDispatcherType(DispatcherType type) 1780 /**
1781 { 1781 * @param pathInfo
1782 _dispatcherType = type; 1782 * The pathInfo to set.
1783 } 1783 */
1784 1784 public void setPathInfo(String pathInfo)
1785 /* ------------------------------------------------------------ */ 1785 {
1786 public void setHandled(boolean h) 1786 _pathInfo = pathInfo;
1787 { 1787 }
1788 _handled = h; 1788
1789 } 1789 /* ------------------------------------------------------------ */
1790 1790 /**
1791 /* ------------------------------------------------------------ */ 1791 * @param protocol
1792 /** 1792 * The protocol to set.
1793 * @param method 1793 */
1794 * The method to set. 1794 public void setProtocol(String protocol)
1795 */ 1795 {
1796 public void setMethod(String method) 1796 _protocol = protocol;
1797 { 1797 }
1798 _method = method; 1798
1799 } 1799 /* ------------------------------------------------------------ */
1800 1800 /**
1801 /* ------------------------------------------------------------ */ 1801 * Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any
1802 /** 1802 * geParameter methods.
1803 * @param parameters 1803 *
1804 * The parameters to set. 1804 * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
1805 */ 1805 *
1806 public void setParameters(MultiMap<String> parameters) 1806 * @param queryEncoding
1807 { 1807 */
1808 _parameters = (parameters == null)?_baseParameters:parameters; 1808 public void setQueryEncoding(String queryEncoding)
1809 if (_paramsExtracted && _parameters == null) 1809 {
1810 throw new IllegalStateException(); 1810 _queryEncoding = queryEncoding;
1811 } 1811 _queryString = null;
1812 1812 }
1813 /* ------------------------------------------------------------ */ 1813
1814 /** 1814 /* ------------------------------------------------------------ */
1815 * @param pathInfo 1815 /**
1816 * The pathInfo to set. 1816 * @param queryString
1817 */ 1817 * The queryString to set.
1818 public void setPathInfo(String pathInfo) 1818 */
1819 { 1819 public void setQueryString(String queryString)
1820 _pathInfo = pathInfo; 1820 {
1821 } 1821 _queryString = queryString;
1822 1822 _queryEncoding = null; //assume utf-8
1823 /* ------------------------------------------------------------ */ 1823 }
1824 /** 1824
1825 * @param protocol 1825 /* ------------------------------------------------------------ */
1826 * The protocol to set. 1826 /**
1827 */ 1827 * @param addr
1828 public void setProtocol(String protocol) 1828 * The address to set.
1829 { 1829 */
1830 _protocol = protocol; 1830 public void setRemoteAddr(String addr)
1831 } 1831 {
1832 1832 _remoteAddr = addr;
1833 /* ------------------------------------------------------------ */ 1833 }
1834 /** 1834
1835 * Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any 1835 /* ------------------------------------------------------------ */
1836 * geParameter methods. 1836 /**
1837 * 1837 * @param host
1838 * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding. 1838 * The host to set.
1839 * 1839 */
1840 * @param queryEncoding 1840 public void setRemoteHost(String host)
1841 */ 1841 {
1842 public void setQueryEncoding(String queryEncoding) 1842 _remoteHost = host;
1843 { 1843 }
1844 _queryEncoding = queryEncoding; 1844
1845 _queryString = null; 1845 /* ------------------------------------------------------------ */
1846 } 1846 /**
1847 1847 * @param requestedSessionId
1848 /* ------------------------------------------------------------ */ 1848 * The requestedSessionId to set.
1849 /** 1849 */
1850 * @param queryString 1850 public void setRequestedSessionId(String requestedSessionId)
1851 * The queryString to set. 1851 {
1852 */ 1852 _requestedSessionId = requestedSessionId;
1853 public void setQueryString(String queryString) 1853 }
1854 { 1854
1855 _queryString = queryString; 1855 /* ------------------------------------------------------------ */
1856 _queryEncoding = null; //assume utf-8 1856 /**
1857 } 1857 * @param requestedSessionIdCookie
1858 1858 * The requestedSessionIdCookie to set.
1859 /* ------------------------------------------------------------ */ 1859 */
1860 /** 1860 public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
1861 * @param addr 1861 {
1862 * The address to set. 1862 _requestedSessionIdFromCookie = requestedSessionIdCookie;
1863 */ 1863 }
1864 public void setRemoteAddr(String addr) 1864
1865 { 1865 /* ------------------------------------------------------------ */
1866 _remoteAddr = addr; 1866 /**
1867 } 1867 * @param requestURI
1868 1868 * The requestURI to set.
1869 /* ------------------------------------------------------------ */ 1869 */
1870 /** 1870 public void setRequestURI(String requestURI)
1871 * @param host 1871 {
1872 * The host to set. 1872 _requestURI = requestURI;
1873 */ 1873 }
1874 public void setRemoteHost(String host) 1874
1875 { 1875 /* ------------------------------------------------------------ */
1876 _remoteHost = host; 1876 /**
1877 } 1877 * @param scheme
1878 1878 * The scheme to set.
1879 /* ------------------------------------------------------------ */ 1879 */
1880 /** 1880 public void setScheme(String scheme)
1881 * @param requestedSessionId 1881 {
1882 * The requestedSessionId to set. 1882 _scheme = scheme;
1883 */ 1883 }
1884 public void setRequestedSessionId(String requestedSessionId) 1884
1885 { 1885 /* ------------------------------------------------------------ */
1886 _requestedSessionId = requestedSessionId; 1886 /**
1887 } 1887 * @param host
1888 1888 * The host to set.
1889 /* ------------------------------------------------------------ */ 1889 */
1890 /** 1890 public void setServerName(String host)
1891 * @param requestedSessionIdCookie 1891 {
1892 * The requestedSessionIdCookie to set. 1892 _serverName = host;
1893 */ 1893 }
1894 public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie) 1894
1895 { 1895 /* ------------------------------------------------------------ */
1896 _requestedSessionIdFromCookie = requestedSessionIdCookie; 1896 /**
1897 } 1897 * @param port
1898 1898 * The port to set.
1899 /* ------------------------------------------------------------ */ 1899 */
1900 /** 1900 public void setServerPort(int port)
1901 * @param requestURI 1901 {
1902 * The requestURI to set. 1902 _port = port;
1903 */ 1903 }
1904 public void setRequestURI(String requestURI) 1904
1905 { 1905 /* ------------------------------------------------------------ */
1906 _requestURI = requestURI; 1906 /**
1907 } 1907 * @param servletPath
1908 1908 * The servletPath to set.
1909 /* ------------------------------------------------------------ */ 1909 */
1910 /** 1910 public void setServletPath(String servletPath)
1911 * @param scheme 1911 {
1912 * The scheme to set. 1912 _servletPath = servletPath;
1913 */ 1913 }
1914 public void setScheme(String scheme) 1914
1915 { 1915 /* ------------------------------------------------------------ */
1916 _scheme = scheme; 1916 /**
1917 } 1917 * @param session
1918 1918 * The session to set.
1919 /* ------------------------------------------------------------ */ 1919 */
1920 /** 1920 public void setSession(HttpSession session)
1921 * @param host 1921 {
1922 * The host to set. 1922 _session = session;
1923 */ 1923 }
1924 public void setServerName(String host) 1924
1925 { 1925 /* ------------------------------------------------------------ */
1926 _serverName = host; 1926 public void setTimeStamp(long ts)
1927 } 1927 {
1928 1928 _timeStamp = ts;
1929 /* ------------------------------------------------------------ */ 1929 }
1930 /** 1930
1931 * @param port 1931 /* ------------------------------------------------------------ */
1932 * The port to set. 1932 /**
1933 */ 1933 * @param uri
1934 public void setServerPort(int port) 1934 * The uri to set.
1935 { 1935 */
1936 _port = port; 1936 public void setUri(HttpURI uri)
1937 } 1937 {
1938 1938 _uri = uri;
1939 /* ------------------------------------------------------------ */ 1939 }
1940 /** 1940
1941 * @param servletPath 1941 /* ------------------------------------------------------------ */
1942 * The servletPath to set. 1942 public void setUserIdentityScope(UserIdentity.Scope scope)
1943 */ 1943 {
1944 public void setServletPath(String servletPath) 1944 _scope = scope;
1945 { 1945 }
1946 _servletPath = servletPath; 1946
1947 } 1947 /* ------------------------------------------------------------ */
1948 1948 /**
1949 /* ------------------------------------------------------------ */ 1949 * Set timetstamp of request dispatch
1950 /** 1950 *
1951 * @param session 1951 * @param value
1952 * The session to set. 1952 * timestamp
1953 */ 1953 */
1954 public void setSession(HttpSession session) 1954 public void setDispatchTime(long value)
1955 { 1955 {
1956 _session = session; 1956 _dispatchTime = value;
1957 } 1957 }
1958 1958
1959 /* ------------------------------------------------------------ */ 1959 /* ------------------------------------------------------------ */
1960 /** 1960 public AsyncContext startAsync() throws IllegalStateException
1961 * @param sessionManager 1961 {
1962 * The sessionManager to set. 1962 if (!_asyncSupported)
1963 */ 1963 throw new IllegalStateException("!asyncSupported");
1964 public void setSessionManager(SessionManager sessionManager) 1964 _async.startAsync();
1965 { 1965 return _async;
1966 _sessionManager = sessionManager; 1966 }
1967 } 1967
1968 1968 /* ------------------------------------------------------------ */
1969 /* ------------------------------------------------------------ */ 1969 public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
1970 public void setTimeStamp(long ts) 1970 {
1971 { 1971 if (!_asyncSupported)
1972 _timeStamp = ts; 1972 throw new IllegalStateException("!asyncSupported");
1973 } 1973 _async.startAsync(_context,servletRequest,servletResponse);
1974 1974 return _async;
1975 /* ------------------------------------------------------------ */ 1975 }
1976 /** 1976
1977 * @param uri 1977 /* ------------------------------------------------------------ */
1978 * The uri to set. 1978 @Override
1979 */ 1979 public String toString()
1980 public void setUri(HttpURI uri) 1980 {
1981 { 1981 return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString();
1982 _uri = uri; 1982 }
1983 } 1983
1984 1984 /* ------------------------------------------------------------ */
1985 /* ------------------------------------------------------------ */ 1985 public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
1986 public void setUserIdentityScope(UserIdentity.Scope scope) 1986 {
1987 { 1987 if (_authentication instanceof Authentication.Deferred)
1988 _scope = scope; 1988 {
1989 } 1989 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this,response));
1990 1990 return !(_authentication instanceof Authentication.ResponseSent);
1991 /* ------------------------------------------------------------ */ 1991 }
1992 /** 1992 response.sendError(HttpStatus.UNAUTHORIZED_401);
1993 * Set timetstamp of request dispatch 1993 return false;
1994 * 1994 }
1995 * @param value 1995
1996 * timestamp 1996 /* ------------------------------------------------------------ */
1997 */ 1997 public Part getPart(String name) throws IOException, ServletException
1998 public void setDispatchTime(long value) 1998 {
1999 { 1999 getParts();
2000 _dispatchTime = value; 2000 return _multiPartInputStream.getPart(name);
2001 } 2001 }
2002 2002
2003 /* ------------------------------------------------------------ */ 2003 /* ------------------------------------------------------------ */
2004 public AsyncContext startAsync() throws IllegalStateException 2004 public Collection<Part> getParts() throws IOException, ServletException
2005 { 2005 {
2006 if (!_asyncSupported) 2006 if (getContentType() == null || !getContentType().startsWith("multipart/form-data"))
2007 throw new IllegalStateException("!asyncSupported"); 2007 throw new ServletException("Content-Type != multipart/form-data");
2008 _async.startAsync(); 2008
2009 return _async; 2009 if (_multiPartInputStream == null)
2010 } 2010 _multiPartInputStream = (MultiPartInputStream)getAttribute(__MULTIPART_INPUT_STREAM);
2011 2011
2012 /* ------------------------------------------------------------ */ 2012 if (_multiPartInputStream == null)
2013 public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException 2013 {
2014 { 2014 MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT);
2015 if (!_asyncSupported) 2015
2016 throw new IllegalStateException("!asyncSupported"); 2016 if (config == null)
2017 _async.startAsync(_context,servletRequest,servletResponse); 2017 throw new IllegalStateException("No multipart config for servlet");
2018 return _async; 2018
2019 } 2019 _multiPartInputStream = new MultiPartInputStream(getInputStream(),
2020 2020 getContentType(), config,
2021 /* ------------------------------------------------------------ */ 2021 (_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null));
2022 @Override 2022
2023 public String toString() 2023 setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
2024 { 2024 setAttribute(__MULTIPART_CONTEXT, _context);
2025 return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString(); 2025 Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
2026 } 2026 for (Part p:parts)
2027 2027 {
2028 /* ------------------------------------------------------------ */ 2028 MultiPartInputStream.MultiPart mp = (MultiPartInputStream.MultiPart)p;
2029 public boolean authenticate(HttpServletResponse response) throws IOException, ServletException 2029 if (mp.getContentDispositionFilename() == null)
2030 { 2030 {
2031 if (_authentication instanceof Authentication.Deferred) 2031 //Servlet Spec 3.0 pg 23, parts without filenames must be put into init params
2032 { 2032 String charset = null;
2033 setAuthentication(((Authentication.Deferred)_authentication).authenticate(this,response)); 2033 if (mp.getContentType() != null)
2034 return !(_authentication instanceof Authentication.ResponseSent); 2034 charset = MimeTypes.getCharsetFromContentType(new ByteArrayBuffer(mp.getContentType()));
2035 } 2035
2036 response.sendError(HttpStatus.UNAUTHORIZED_401); 2036 ByteArrayOutputStream os = null;
2037 return false; 2037 InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file
2038 } 2038 try
2039 2039 {
2040 /* ------------------------------------------------------------ */ 2040 os = new ByteArrayOutputStream();
2041 public Part getPart(String name) throws IOException, ServletException 2041 IO.copy(is, os);
2042 { 2042 String content=new String(os.toByteArray(),charset==null?StringUtil.__UTF8:charset);
2043 getParts(); 2043 getParameter(""); //cause params to be evaluated
2044 return _multiPartInputStream.getPart(name); 2044 getParameters().add(mp.getName(), content);
2045 } 2045 }
2046 2046 finally
2047 /* ------------------------------------------------------------ */ 2047 {
2048 public Collection<Part> getParts() throws IOException, ServletException 2048 IO.close(os);
2049 { 2049 IO.close(is);
2050 if (getContentType() == null || !getContentType().startsWith("multipart/form-data")) 2050 }
2051 throw new ServletException("Content-Type != multipart/form-data"); 2051 }
2052 2052 }
2053 if (_multiPartInputStream == null) 2053 }
2054 _multiPartInputStream = (MultiPartInputStream)getAttribute(__MULTIPART_INPUT_STREAM); 2054
2055 2055 return _multiPartInputStream.getParts();
2056 if (_multiPartInputStream == null) 2056 }
2057 { 2057
2058 MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT); 2058 /* ------------------------------------------------------------ */
2059 2059 public void login(String username, String password) throws ServletException
2060 if (config == null) 2060 {
2061 throw new IllegalStateException("No multipart config for servlet"); 2061 if (_authentication instanceof Authentication.Deferred)
2062 2062 {
2063 _multiPartInputStream = new MultiPartInputStream(getInputStream(), 2063 _authentication=((Authentication.Deferred)_authentication).login(username,password,this);
2064 getContentType(), config, 2064 if (_authentication == null)
2065 (_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null)); 2065 throw new ServletException();
2066 2066 }
2067 setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream); 2067 else
2068 setAttribute(__MULTIPART_CONTEXT, _context); 2068 {
2069 Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing 2069 throw new ServletException("Authenticated as "+_authentication);
2070 for (Part p:parts) 2070 }
2071 { 2071 }
2072 MultiPartInputStream.MultiPart mp = (MultiPartInputStream.MultiPart)p; 2072
2073 if (mp.getContentDispositionFilename() == null) 2073 /* ------------------------------------------------------------ */
2074 { 2074 public void logout() throws ServletException
2075 //Servlet Spec 3.0 pg 23, parts without filenames must be put into init params 2075 {
2076 String charset = null; 2076 if (_authentication instanceof Authentication.User)
2077 if (mp.getContentType() != null) 2077 ((Authentication.User)_authentication).logout();
2078 charset = MimeTypes.getCharsetFromContentType(new ByteArrayBuffer(mp.getContentType())); 2078 _authentication=Authentication.UNAUTHENTICATED;
2079 2079 }
2080 ByteArrayOutputStream os = null; 2080
2081 InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file 2081 /* ------------------------------------------------------------ */
2082 try 2082 /**
2083 { 2083 * Merge in a new query string. The query string is merged with the existing parameters and {@link #setParameters(MultiMap)} and
2084 os = new ByteArrayOutputStream(); 2084 * {@link #setQueryString(String)} are called with the result. The merge is according to the rules of the servlet dispatch forward method.
2085 IO.copy(is, os); 2085 *
2086 String content=new String(os.toByteArray(),charset==null?StringUtil.__UTF8:charset); 2086 * @param query
2087 getParameter(""); //cause params to be evaluated 2087 * The query string to merge into the request.
2088 getParameters().add(mp.getName(), content); 2088 */
2089 } 2089 public void mergeQueryString(String query)
2090 finally 2090 {
2091 { 2091 // extract parameters from dispatch query
2092 IO.close(os); 2092 MultiMap<String> parameters = new MultiMap<String>();
2093 IO.close(is); 2093 UrlEncoded.decodeTo(query,parameters, StringUtil.__UTF8); //have to assume UTF-8 because we can't know otherwise
2094 } 2094
2095 } 2095 boolean merge_old_query = false;
2096 } 2096
2097 } 2097 // Have we evaluated parameters
2098 2098 if (!_paramsExtracted)
2099 return _multiPartInputStream.getParts(); 2099 extractParameters();
2100 } 2100
2101 2101 // Are there any existing parameters?
2102 /* ------------------------------------------------------------ */ 2102 if (_parameters != null && _parameters.size() > 0)
2103 public void login(String username, String password) throws ServletException 2103 {
2104 { 2104 // Merge parameters; new parameters of the same name take precedence.
2105 if (_authentication instanceof Authentication.Deferred) 2105 Iterator<Entry<String, Object>> iter = _parameters.entrySet().iterator();
2106 { 2106 while (iter.hasNext())
2107 _authentication=((Authentication.Deferred)_authentication).login(username,password,this); 2107 {
2108 if (_authentication == null) 2108 Map.Entry<String, Object> entry = iter.next();
2109 throw new ServletException(); 2109 String name = entry.getKey();
2110 } 2110
2111 else 2111 // If the names match, we will need to remake the query string
2112 { 2112 if (parameters.containsKey(name))
2113 throw new ServletException("Authenticated as "+_authentication); 2113 merge_old_query = true;
2114 } 2114
2115 } 2115 // Add the old values to the new parameter map
2116 2116 Object values = entry.getValue();
2117 /* ------------------------------------------------------------ */ 2117 for (int i = 0; i < LazyList.size(values); i++)
2118 public void logout() throws ServletException 2118 parameters.add(name,LazyList.get(values,i));
2119 { 2119 }
2120 if (_authentication instanceof Authentication.User) 2120 }
2121 ((Authentication.User)_authentication).logout(); 2121
2122 _authentication=Authentication.UNAUTHENTICATED; 2122 if (_queryString != null && _queryString.length() > 0)
2123 } 2123 {
2124 2124 if (merge_old_query)
2125 /* ------------------------------------------------------------ */ 2125 {
2126 /** 2126 StringBuilder overridden_query_string = new StringBuilder();
2127 * Merge in a new query string. The query string is merged with the existing parameters and {@link #setParameters(MultiMap)} and 2127 MultiMap<String> overridden_old_query = new MultiMap<String>();
2128 * {@link #setQueryString(String)} are called with the result. The merge is according to the rules of the servlet dispatch forward method. 2128 UrlEncoded.decodeTo(_queryString,overridden_old_query,getQueryEncoding());//decode using any queryencoding set for the request
2129 * 2129
2130 * @param query 2130
2131 * The query string to merge into the request. 2131 MultiMap<String> overridden_new_query = new MultiMap<String>();
2132 */ 2132 UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8); //have to assume utf8 as we cannot know otherwise
2133 public void mergeQueryString(String query) 2133
2134 { 2134 Iterator<Entry<String, Object>> iter = overridden_old_query.entrySet().iterator();
2135 // extract parameters from dispatch query 2135 while (iter.hasNext())
2136 MultiMap<String> parameters = new MultiMap<String>(); 2136 {
2137 UrlEncoded.decodeTo(query,parameters, StringUtil.__UTF8); //have to assume UTF-8 because we can't know otherwise 2137 Map.Entry<String, Object> entry = iter.next();
2138 2138 String name = entry.getKey();
2139 boolean merge_old_query = false; 2139 if (!overridden_new_query.containsKey(name))
2140 2140 {
2141 // Have we evaluated parameters 2141 Object values = entry.getValue();
2142 if (!_paramsExtracted) 2142 for (int i = 0; i < LazyList.size(values); i++)
2143 extractParameters(); 2143 {
2144 2144 overridden_query_string.append("&").append(name).append("=").append((Object)LazyList.get(values,i));
2145 // Are there any existing parameters? 2145 }
2146 if (_parameters != null && _parameters.size() > 0) 2146 }
2147 { 2147 }
2148 // Merge parameters; new parameters of the same name take precedence. 2148
2149 Iterator<Entry<String, Object>> iter = _parameters.entrySet().iterator(); 2149 query = query + overridden_query_string;
2150 while (iter.hasNext()) 2150 }
2151 { 2151 else
2152 Map.Entry<String, Object> entry = iter.next(); 2152 {
2153 String name = entry.getKey(); 2153 query = query + "&" + _queryString;
2154 2154 }
2155 // If the names match, we will need to remake the query string 2155 }
2156 if (parameters.containsKey(name)) 2156
2157 merge_old_query = true; 2157 setParameters(parameters);
2158 2158 setQueryString(query);
2159 // Add the old values to the new parameter map 2159 }
2160 Object values = entry.getValue();
2161 for (int i = 0; i < LazyList.size(values); i++)
2162 parameters.add(name,LazyList.get(values,i));
2163 }
2164 }
2165
2166 if (_queryString != null && _queryString.length() > 0)
2167 {
2168 if (merge_old_query)
2169 {
2170 StringBuilder overridden_query_string = new StringBuilder();
2171 MultiMap<String> overridden_old_query = new MultiMap<String>();
2172 UrlEncoded.decodeTo(_queryString,overridden_old_query,getQueryEncoding());//decode using any queryencoding set for the request
2173
2174
2175 MultiMap<String> overridden_new_query = new MultiMap<String>();
2176 UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8); //have to assume utf8 as we cannot know otherwise
2177
2178 Iterator<Entry<String, Object>> iter = overridden_old_query.entrySet().iterator();
2179 while (iter.hasNext())
2180 {
2181 Map.Entry<String, Object> entry = iter.next();
2182 String name = entry.getKey();
2183 if (!overridden_new_query.containsKey(name))
2184 {
2185 Object values = entry.getValue();
2186 for (int i = 0; i < LazyList.size(values); i++)
2187 {
2188 overridden_query_string.append("&").append(name).append("=").append((Object)LazyList.get(values,i));
2189 }
2190 }
2191 }
2192
2193 query = query + overridden_query_string;
2194 }
2195 else
2196 {
2197 query = query + "&" + _queryString;
2198 }
2199 }
2200
2201 setParameters(parameters);
2202 setQueryString(query);
2203 }
2204 } 2160 }