001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.mock; 018 019import static org.apache.juneau.internal.CollectionUtils.*; 020 021import java.net.*; 022import java.security.*; 023import java.util.*; 024import java.util.function.*; 025 026import org.apache.http.*; 027import org.apache.http.client.config.*; 028import org.apache.http.concurrent.*; 029import org.apache.http.protocol.*; 030import org.apache.juneau.httppart.*; 031import org.apache.juneau.internal.*; 032import org.apache.juneau.parser.*; 033import org.apache.juneau.rest.client.*; 034import org.apache.juneau.serializer.*; 035 036import jakarta.servlet.*; 037import jakarta.servlet.http.*; 038 039/** 040 * A subclass of {@link RestRequest} with additional features for mocked testing. 041 * 042 * <p> 043 * Instances of this class are instantiated through methods on {@link MockRestClient} such as {@link MockRestClient#post(Object,Object)} 044 * 045 * <h5 class='section'>Notes:</h5><ul> 046 * <li class='warn'>This class is not thread safe. 047 * </ul> 048 * 049 * <h5 class='section'>See Also:</h5><ul> 050 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestMockBasics">juneau-rest-mock Basics</a> 051 * </ul> 052 */ 053public class MockRestRequest extends org.apache.juneau.rest.client.RestRequest { 054 055 //------------------------------------------------------------------------------------------------------------------ 056 // Servlet request override values. 057 //------------------------------------------------------------------------------------------------------------------ 058 private Map<String,Object> attributeMap = map(); 059 private Map<String,RequestDispatcher> requestDispatcherMap = map(); 060 private String characterEncoding, protocol, scheme, serverName, remoteAddr, remoteHost, localName, localAddr, 061 pathInfo, pathTranslated, contextPath, queryString, remoteUser, requestedSessionId, requestURI, servletPath, authType; 062 private Integer serverPort, remotePort, localPort; 063 private Locale locale; 064 private ServletContext servletContext; 065 private DispatcherType dispatcherType; 066 private Cookie[] cookies; 067 private Principal userPrincipal; 068 private HttpSession httpSession; 069 private String[] roles; 070 071 /** 072 * Constructs a REST call with the specified method name. 073 * 074 * @param client The client that created this request. 075 * @param uri The target URI. 076 * @param method The HTTP method name (uppercase). 077 * @param hasBody Whether this method has a body. 078 * @throws RestCallException If an exception or non-200 response code occurred during the connection attempt. 079 */ 080 protected MockRestRequest(RestClient client, URI uri, String method, boolean hasBody) throws RestCallException { 081 super(client, uri, method, hasBody); 082 } 083 084 //------------------------------------------------------------------------------------------------------------------ 085 // MockServletRequest passthrough methods. 086 //------------------------------------------------------------------------------------------------------------------ 087 088 /** 089 * Adds an attribute to the underlying {@link HttpServletRequest} object. 090 * 091 * <p> 092 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 093 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 094 * 095 * @param name The servlet request attribute name. 096 * @param value The servlet request attribute value. 097 * @return This object. 098 */ 099 public MockRestRequest attribute(String name, Object value) { 100 this.attributeMap.put(name, value); 101 return this; 102 } 103 104 /** 105 * Replaces the attributes on the underlying {@link HttpServletRequest} object. 106 * 107 * <p> 108 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 109 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 110 * 111 * @param value The new servlet attribute values. 112 * @return This object. 113 */ 114 public MockRestRequest attributes(Map<String,Object> value) { 115 this.attributeMap.clear(); 116 this.attributeMap.putAll(value); 117 return this; 118 } 119 120 /** 121 * Returns the attributes to add to the underlying {@link HttpServletRequest} object. 122 * 123 * @return The attributes to add to the underlying {@link HttpServletRequest} object. 124 */ 125 public Map<String,Object> getAttributeMap() { 126 return attributeMap; 127 } 128 129 /** 130 * Specifies the user roles on the underlying {@link HttpServletRequest} object. 131 * 132 * <p> 133 * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}. 134 * 135 * <p> 136 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 137 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 138 * 139 * @param roles The roles to add to this request (e.g. <js>"ROLE_ADMIN"</js>). 140 * @return This object. 141 */ 142 public MockRestRequest roles(String...roles) { 143 this.roles = roles; 144 return this; 145 } 146 147 /** 148 * Returns the user roles to set on the underlying {@link HttpServletRequest} object. 149 * 150 * @return The user roles to set on the underlying {@link HttpServletRequest} object. 151 */ 152 public String[] getRoles() { 153 return roles; 154 } 155 156 /** 157 * Specifies the value for the security roles on the underlying {@link HttpServletRequest} object. 158 * 159 * <p> 160 * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}. 161 * 162 * <p> 163 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 164 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 165 * 166 * @param role The role to add to this request (e.g. <js>"ROLE_ADMIN"</js>). 167 * @return This object. 168 */ 169 public MockRestRequest role(String role) { 170 this.roles = new String[]{role}; 171 return this; 172 } 173 174 /** 175 * Overrides the character encoding value on the underlying {@link HttpServletRequest} object. 176 * 177 * <p> 178 * Affects the results of calling {@link HttpServletRequest#getCharacterEncoding()}. 179 * 180 * <p> 181 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 182 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 183 * 184 * @param value The new value for this setting. 185 * @return This object. 186 */ 187 public MockRestRequest characterEncoding(String value) { 188 this.characterEncoding = value; 189 return this; 190 } 191 192 /** 193 * Returns the value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method. 194 * 195 * @return The value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method. 196 */ 197 public String getCharacterEncoding() { 198 return characterEncoding; 199 } 200 201 /** 202 * Overrides the HTTP protocol value on the underlying {@link HttpServletRequest} object. 203 * 204 * <p> 205 * Affects the results of calling {@link HttpServletRequest#getProtocol()}. 206 * 207 * <p> 208 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 209 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 210 * 211 * @param value The new value for this setting. 212 * @return This object. 213 */ 214 public MockRestRequest protocol(String value) { 215 this.protocol = value; 216 return this; 217 } 218 219 /** 220 * Returns the HTTP protocol value to set on the underlying {@link HttpServletRequest} object. 221 * 222 * @return The HTTP protocol value to set on the underlying {@link HttpServletRequest} object. 223 */ 224 public String getProtocol() { 225 return protocol; 226 } 227 228 /** 229 * Overrides the HTTP schema value on the underlying {@link HttpServletRequest} object. 230 * 231 * <p> 232 * Affects the results of calling {@link HttpServletRequest#getScheme()}. 233 * 234 * <p> 235 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 236 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 237 * 238 * @param value The new value for this setting. 239 * @return This object. 240 */ 241 @Override 242 public MockRestRequest uriScheme(String value) { 243 super.uriScheme(value); 244 this.scheme = value; 245 return this; 246 } 247 248 /** 249 * Returns the HTTP schema value to set on the underlying {@link HttpServletRequest} object. 250 * 251 * @return The HTTP schema value to set on the underlying {@link HttpServletRequest} object. 252 */ 253 public String getScheme() { 254 return scheme; 255 } 256 257 /** 258 * Overrides the server name value on the underlying {@link HttpServletRequest} object. 259 * 260 * <p> 261 * Affects the results of calling {@link HttpServletRequest#getServerName()}. 262 * 263 * <p> 264 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 265 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 266 * 267 * @param value The new value for this setting. 268 * @return This object. 269 */ 270 public MockRestRequest serverName(String value) { 271 this.serverName = value; 272 return this; 273 } 274 275 /** 276 * Returns the server name value to set on the underlying {@link HttpServletRequest} object. 277 * 278 * @return The server name value to set on the underlying {@link HttpServletRequest} object. 279 */ 280 public String getServerName() { 281 return serverName; 282 } 283 284 /** 285 * Overrides the server port value on the underlying {@link HttpServletRequest} object. 286 * 287 * <p> 288 * Affects the results of calling {@link HttpServletRequest#getServerPort()}. 289 * 290 * <p> 291 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 292 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 293 * 294 * @param value The new value for this setting. 295 * @return This object. 296 */ 297 public MockRestRequest serverPort(int value) { 298 this.serverPort = value; 299 return this; 300 } 301 302 /** 303 * Returns the server port value to set on the underlying {@link HttpServletRequest} object. 304 * 305 * @return The server port value to set on the underlying {@link HttpServletRequest} object. 306 */ 307 public Integer getServerPort() { 308 return serverPort; 309 } 310 311 /** 312 * Overrides the remote address value on the underlying {@link HttpServletRequest} object. 313 * 314 * <p> 315 * Affects the results of calling {@link HttpServletRequest#getRemoteAddr()}. 316 * 317 * <p> 318 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 319 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 320 * 321 * @param value The new value for this setting. 322 * @return This object. 323 */ 324 public MockRestRequest remoteAddr(String value) { 325 this.remoteAddr = value; 326 return this; 327 } 328 329 /** 330 * Returns the remote address value to set on the underlying {@link HttpServletRequest} object. 331 * 332 * @return The remote address value to set on the underlying {@link HttpServletRequest} object. 333 */ 334 public String getRemoteAddr() { 335 return remoteAddr; 336 } 337 338 /** 339 * Overrides the remote host value on the underlying {@link HttpServletRequest} object. 340 * 341 * <p> 342 * Affects the results of calling {@link HttpServletRequest#getRemoteHost()}. 343 * 344 * <p> 345 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 346 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 347 * 348 * @param value The new value for this setting. 349 * @return This object. 350 */ 351 public MockRestRequest remoteHost(String value) { 352 this.remoteHost = value; 353 return this; 354 } 355 356 /** 357 * Returns the remote host value to set on the underlying {@link HttpServletRequest} object. 358 * 359 * @return The remote host value to set on the underlying {@link HttpServletRequest} object. 360 */ 361 public String getRemoteHost() { 362 return remoteHost; 363 } 364 365 /** 366 * Overrides the locale on the underlying {@link HttpServletRequest} object. 367 * 368 * <p> 369 * Affects the results of calling {@link HttpServletRequest#getLocale()}. 370 * 371 * <p> 372 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 373 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 374 * 375 * @param value The new value for this setting. 376 * @return This object. 377 */ 378 public MockRestRequest locale(Locale value) { 379 this.locale = value; 380 return this; 381 } 382 383 /** 384 * Returns the locale to set on the underlying {@link HttpServletRequest} object. 385 * 386 * @return The locale to set on the underlying {@link HttpServletRequest} object. 387 */ 388 @Override 389 public Locale getLocale() { 390 return locale; 391 } 392 393 /** 394 * Overrides the remote port value on the underlying {@link HttpServletRequest} object. 395 * 396 * <p> 397 * Affects the results of calling {@link HttpServletRequest#getRemotePort()}. 398 * 399 * <p> 400 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 401 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 402 * 403 * @param value The new value for this setting. 404 * @return This object. 405 */ 406 public MockRestRequest remotePort(int value) { 407 this.remotePort = value; 408 return this; 409 } 410 411 /** 412 * Returns the remote port value to set on the underlying {@link HttpServletRequest} object. 413 * 414 * @return The remote port value to set on the underlying {@link HttpServletRequest} object. 415 */ 416 public Integer getRemotePort() { 417 return remotePort; 418 } 419 420 /** 421 * Overrides the local name value on the underlying {@link HttpServletRequest} object. 422 * 423 * <p> 424 * Affects the results of calling {@link HttpServletRequest#getLocalName()}. 425 * 426 * <p> 427 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 428 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 429 * 430 * @param value The new value for this setting. 431 * @return This object. 432 */ 433 public MockRestRequest localName(String value) { 434 this.localName = value; 435 return this; 436 } 437 438 /** 439 * Returns the local name value to set on the underlying {@link HttpServletRequest} object. 440 * 441 * @return The local name value to set on the underlying {@link HttpServletRequest} object. 442 */ 443 public String getLocalName() { 444 return localName; 445 } 446 447 /** 448 * Overrides the local address value on the underlying {@link HttpServletRequest} object. 449 * 450 * <p> 451 * Affects the results of calling {@link HttpServletRequest#getLocalAddr()}. 452 * 453 * <p> 454 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 455 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 456 * 457 * @param value The new value for this setting. 458 * @return This object. 459 */ 460 public MockRestRequest localAddr(String value) { 461 this.localAddr = value; 462 return this; 463 } 464 465 /** 466 * Returns the local address value to set on the underlying {@link HttpServletRequest} object. 467 * 468 * @return The local address value to set on the underlying {@link HttpServletRequest} object. 469 */ 470 public String getLocalAddr() { 471 return localAddr; 472 } 473 474 /** 475 * Overrides the local port value on the underlying {@link HttpServletRequest} object. 476 * 477 * <p> 478 * Affects the results of calling {@link HttpServletRequest#getLocalPort()}. 479 * 480 * <p> 481 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 482 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 483 * 484 * @param value The new value for this setting. 485 * @return This object. 486 */ 487 public MockRestRequest localPort(int value) { 488 this.localPort = value; 489 return this; 490 } 491 492 /** 493 * Returns the local port value to set on the underlying {@link HttpServletRequest} object. 494 * 495 * @return The local port value to set on the underlying {@link HttpServletRequest} object. 496 */ 497 public Integer getLocalPort() { 498 return localPort; 499 } 500 501 /** 502 * Overrides the request dispatcher on the underlying {@link HttpServletRequest} object. 503 * 504 * <p> 505 * Affects the results of calling {@link HttpServletRequest#getRequestDispatcher(String)}. 506 * 507 * <p> 508 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 509 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 510 * 511 * @param path The path to the resource being resolved. 512 * @param value The new value for this setting. 513 * @return This object. 514 */ 515 public MockRestRequest requestDispatcher(String path, RequestDispatcher value) { 516 this.requestDispatcherMap.put(path, value); 517 return this; 518 } 519 520 /** 521 * Returns the request dispatcher to set on the underlying {@link HttpServletRequest} obhject. 522 * 523 * @return The value of the <property>requestDispatcherMap</property> property on this bean, or <jk>null</jk> if it is not set. 524 */ 525 public Map<String,RequestDispatcher> getRequestDispatcherMap() { 526 return requestDispatcherMap; 527 } 528 529 /** 530 * Overrides the servlet context on the underlying {@link HttpServletRequest} object. 531 * 532 * <p> 533 * Affects the results of calling {@link HttpServletRequest#getServletContext()}. 534 * 535 * <p> 536 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 537 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 538 * 539 * @param value The new value for this setting. 540 * @return This object. 541 */ 542 public MockRestRequest servletContext(ServletContext value) { 543 this.servletContext = value; 544 return this; 545 } 546 547 /** 548 * Returns the servlet context to set on the underlying {@link HttpServletRequest} object. 549 * 550 * @return The servlet context to set on the underlying {@link HttpServletRequest} object. 551 */ 552 public ServletContext getServletContext() { 553 return servletContext; 554 } 555 556 /** 557 * Overrides the dispatcher type value on the underlying {@link HttpServletRequest} object. 558 * 559 * <p> 560 * Affects the results of calling {@link HttpServletRequest#getDispatcherType()}. 561 * 562 * <p> 563 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 564 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 565 * 566 * @param value The new value for this setting. 567 * @return This object. 568 */ 569 public MockRestRequest dispatcherType(DispatcherType value) { 570 this.dispatcherType = value; 571 return this; 572 } 573 574 /** 575 * Returns the dispatcher type value to set on the underlying {@link HttpServletRequest} object. 576 * 577 * @return The dispatcher type value to set on the underlying {@link HttpServletRequest} object. 578 */ 579 public DispatcherType getDispatcherType() { 580 return dispatcherType; 581 } 582 583 /** 584 * Overrides the authorization type value on the underlying {@link HttpServletRequest} object. 585 * 586 * <p> 587 * Affects the results of calling {@link HttpServletRequest#getAuthType()}. 588 * 589 * <p> 590 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 591 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 592 * 593 * @param value The new value for this setting. 594 * @return This object. 595 */ 596 public MockRestRequest authType(String value) { 597 this.authType = value; 598 return this; 599 } 600 601 /** 602 * Returns the authorization type value to set on the underlying {@link HttpServletRequest} object. 603 * 604 * @return The authorization type value to set on the underlying {@link HttpServletRequest} object. 605 */ 606 public String getAuthType() { 607 return authType; 608 } 609 610 /** 611 * Overrides the cookies on the underlying {@link HttpServletRequest} object. 612 * 613 * <p> 614 * Affects the results of calling {@link HttpServletRequest#getCookies()}. 615 * 616 * <p> 617 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 618 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 619 * 620 * @param value The new value for this setting. 621 * @return This object. 622 */ 623 public MockRestRequest cookies(Cookie[] value) { 624 this.cookies = value; 625 return this; 626 } 627 628 /** 629 * Returns the cookies to set on the underlying {@link HttpServletRequest} object. 630 * 631 * @return The cookies to set on the underlying {@link HttpServletRequest} object. 632 */ 633 public Cookie[] getCookies() { 634 return cookies; 635 } 636 637 /** 638 * Overrides the path-info value on the underlying {@link HttpServletRequest} object. 639 * 640 * <p> 641 * Affects the results of calling {@link HttpServletRequest#getPathInfo()}. 642 * 643 * <p> 644 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 645 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 646 * 647 * @param value The new value for this setting. 648 * @return This object. 649 */ 650 public MockRestRequest pathInfo(String value) { 651 this.pathInfo = value; 652 return this; 653 } 654 655 /** 656 * Returns the path-info value to set on the underlying {@link HttpServletRequest} object. 657 * 658 * @return The path-info value to set on the underlying {@link HttpServletRequest} object. 659 */ 660 public String getPathInfo() { 661 return pathInfo; 662 } 663 664 /** 665 * Overrides the path-translated value on the underlying {@link HttpServletRequest} object. 666 * 667 * <p> 668 * Affects the results of calling {@link HttpServletRequest#getPathTranslated()}. 669 * 670 * <p> 671 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 672 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 673 * 674 * @param value The new value for this setting. 675 * @return This object. 676 */ 677 public MockRestRequest pathTranslated(String value) { 678 this.pathTranslated = value; 679 return this; 680 } 681 682 /** 683 * Returns the path-translated value to set on the underlying {@link HttpServletRequest} object. 684 * 685 * @return The path-translated value to set on the underlying {@link HttpServletRequest} object. 686 */ 687 public String getPathTranslated() { 688 return pathTranslated; 689 } 690 691 /** 692 * Overrides the context path on the underlying {@link HttpServletRequest} object. 693 * 694 * <p> 695 * Affects the results of calling {@link HttpServletRequest#getContextPath()}. 696 * 697 * <p> 698 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 699 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 700 * 701 * @param value The new value for this setting. 702 * @return This object. 703 */ 704 public MockRestRequest contextPath(String value) { 705 this.contextPath = value; 706 return this; 707 } 708 709 /** 710 * Returns the context path to set on the underlying {@link HttpServletRequest} object. 711 * 712 * @return The context path to set on the underlying {@link HttpServletRequest} object. 713 */ 714 public String getContextPath() { 715 return contextPath; 716 } 717 718 /** 719 * Overrides the query string on the underlying {@link HttpServletRequest} object. 720 * 721 * <p> 722 * Affects the results of calling {@link HttpServletRequest#getQueryString()}. 723 * 724 * <p> 725 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 726 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 727 * 728 * @param value The new value for this setting. 729 * @return This object. 730 */ 731 public MockRestRequest queryString(String value) { 732 this.queryString = value; 733 return this; 734 } 735 736 /** 737 * Returns the query string to set on the underlying {@link HttpServletRequest} object. 738 * 739 * @return The query string to set on the underlying {@link HttpServletRequest} object. 740 */ 741 public String getQueryString() { 742 return queryString; 743 } 744 745 /** 746 * Overrides the remote user on the underlying {@link HttpServletRequest} object. 747 * 748 * <p> 749 * Affects the results of calling {@link HttpServletRequest#getRemoteUser()}. 750 * 751 * <p> 752 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 753 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 754 * 755 * @param value The new value for this setting. 756 * @return This object. 757 */ 758 public MockRestRequest remoteUser(String value) { 759 this.remoteUser = value; 760 return this; 761 } 762 763 /** 764 * Returns the remote user to set on the underlying {@link HttpServletRequest} object. 765 * 766 * @return The remote user to set on the underlying {@link HttpServletRequest} object. 767 */ 768 public String getRemoteUser() { 769 return remoteUser; 770 } 771 772 /** 773 * Overrides the user principal on the underlying {@link HttpServletRequest} object. 774 * 775 * <p> 776 * Affects the results of calling {@link HttpServletRequest#getUserPrincipal()}. 777 * 778 * <p> 779 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 780 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 781 * 782 * @param value The new value for this setting. 783 * @return This object. 784 */ 785 public MockRestRequest userPrincipal(Principal value) { 786 this.userPrincipal = value; 787 return this; 788 } 789 790 /** 791 * Returns the user principal to set on the underlying {@link HttpServletRequest} object. 792 * 793 * @return The user principal to set on the underlying {@link HttpServletRequest} object. 794 */ 795 public Principal getUserPrincipal() { 796 return userPrincipal; 797 } 798 799 /** 800 * Overrides the requested session ID on the underlying {@link HttpServletRequest} object. 801 * 802 * <p> 803 * Affects the results of calling {@link HttpServletRequest#getRequestedSessionId()}. 804 * 805 * <p> 806 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 807 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 808 * 809 * @param value The new value for this setting. 810 * @return This object. 811 */ 812 public MockRestRequest requestedSessionId(String value) { 813 this.requestedSessionId = value; 814 return this; 815 } 816 817 /** 818 * Returns the requested session ID to set on the underlying {@link HttpServletRequest} object. 819 * 820 * @return The requested session ID to set on the underlying {@link HttpServletRequest} object. 821 */ 822 public String getRequestedSessionId() { 823 return requestedSessionId; 824 } 825 826 /** 827 * Overrides the request URI on the underlying {@link HttpServletRequest} object. 828 * 829 * <p> 830 * Affects the results of calling {@link HttpServletRequest#getRequestURI()}. 831 * 832 * <p> 833 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 834 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 835 * 836 * @param value The new value for this setting. 837 * @return This object. 838 */ 839 public MockRestRequest requestURI(String value) { 840 this.requestURI = value; 841 return this; 842 } 843 844 /** 845 * Returns the request URI to set on the underlying {@link HttpServletRequest} object. 846 * 847 * @return The request URI to set on the underlying {@link HttpServletRequest} object. 848 */ 849 public String getRequestURI() { 850 return requestURI; 851 } 852 853 /** 854 * Overrides the servlet path on the underlying {@link HttpServletRequest} object. 855 * 856 * <p> 857 * Affects the results of calling {@link HttpServletRequest#getServletPath()}. 858 * 859 * <p> 860 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 861 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 862 * 863 * @param value The new value for this setting. 864 * @return This object. 865 */ 866 public MockRestRequest servletPath(String value) { 867 this.servletPath = value; 868 return this; 869 } 870 871 /** 872 * Returns the servlet path to set on the underlying {@link HttpServletRequest} object. 873 * 874 * @return The servlet path to set on the underlying {@link HttpServletRequest} object. 875 */ 876 public String getServletPath() { 877 return servletPath; 878 } 879 880 /** 881 * Overrides the HTTP session on the underlying {@link HttpServletRequest} object. 882 * 883 * <p> 884 * Affects the results of calling {@link HttpServletRequest#getSession()}. 885 * 886 * <p> 887 * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)} 888 * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}. 889 * 890 * @param value The new value for this setting. 891 * @return This object. 892 */ 893 public MockRestRequest httpSession(HttpSession value) { 894 this.httpSession = value; 895 return this; 896 } 897 898 /** 899 * Returns the HTTP session to set on the underlying {@link HttpServletRequest} object. 900 * 901 * @return The HTTP session to set on the underlying {@link HttpServletRequest} object. 902 */ 903 public HttpSession getHttpSession() { 904 return httpSession; 905 } 906 @Override /* Overridden from RestRequest */ 907 public MockRestRequest accept(String value) throws RestCallException{ 908 super.accept(value); 909 return this; 910 } 911 912 @Override /* Overridden from RestRequest */ 913 public MockRestRequest acceptCharset(String value) throws RestCallException{ 914 super.acceptCharset(value); 915 return this; 916 } 917 918 @Override /* Overridden from RestRequest */ 919 public MockRestRequest cancellable(Cancellable cancellable) { 920 super.cancellable(cancellable); 921 return this; 922 } 923 924 @Override /* Overridden from RestRequest */ 925 public MockRestRequest config(RequestConfig value) { 926 super.config(value); 927 return this; 928 } 929 930 @Override /* Overridden from RestRequest */ 931 public MockRestRequest content(Object value) { 932 super.content(value); 933 return this; 934 } 935 936 @Override /* Overridden from RestRequest */ 937 public MockRestRequest content(Object input, HttpPartSchema schema) { 938 super.content(input, schema); 939 return this; 940 } 941 942 @Override /* Overridden from RestRequest */ 943 public MockRestRequest contentString(Object input) throws RestCallException{ 944 super.contentString(input); 945 return this; 946 } 947 948 @Override /* Overridden from RestRequest */ 949 public MockRestRequest contentType(String value) throws RestCallException{ 950 super.contentType(value); 951 return this; 952 } 953 954 @Override /* Overridden from RestRequest */ 955 public MockRestRequest context(HttpContext context) { 956 super.context(context); 957 return this; 958 } 959 960 @Override /* Overridden from RestRequest */ 961 public MockRestRequest debug() throws RestCallException{ 962 super.debug(); 963 return this; 964 } 965 966 @Override /* Overridden from RestRequest */ 967 public MockRestRequest errorCodes(Predicate<Integer> value) { 968 super.errorCodes(value); 969 return this; 970 } 971 972 @Override /* Overridden from RestRequest */ 973 public MockRestRequest formData(NameValuePair...parts) { 974 super.formData(parts); 975 return this; 976 } 977 978 @Override /* Overridden from RestRequest */ 979 public MockRestRequest formData(String name, Object value) { 980 super.formData(name, value); 981 return this; 982 } 983 984 @Override /* Overridden from RestRequest */ 985 public MockRestRequest formDataBean(Object value) { 986 super.formDataBean(value); 987 return this; 988 } 989 990 @Override /* Overridden from RestRequest */ 991 public MockRestRequest formDataCustom(Object value) { 992 super.formDataCustom(value); 993 return this; 994 } 995 996 @Override /* Overridden from RestRequest */ 997 public MockRestRequest formDataPairs(String...pairs) throws RestCallException{ 998 super.formDataPairs(pairs); 999 return this; 1000 } 1001 1002 @Override /* Overridden from RestRequest */ 1003 public MockRestRequest header(Header part) { 1004 super.header(part); 1005 return this; 1006 } 1007 1008 @Override /* Overridden from RestRequest */ 1009 public MockRestRequest header(String name, Object value) { 1010 super.header(name, value); 1011 return this; 1012 } 1013 1014 @Override /* Overridden from RestRequest */ 1015 public MockRestRequest headerPairs(String...pairs) { 1016 super.headerPairs(pairs); 1017 return this; 1018 } 1019 1020 @Override /* Overridden from RestRequest */ 1021 public MockRestRequest headers(Header...parts) { 1022 super.headers(parts); 1023 return this; 1024 } 1025 1026 @Override /* Overridden from RestRequest */ 1027 public MockRestRequest headersBean(Object value) { 1028 super.headersBean(value); 1029 return this; 1030 } 1031 1032 @Override /* Overridden from RestRequest */ 1033 public MockRestRequest html() { 1034 super.html(); 1035 return this; 1036 } 1037 1038 @Override /* Overridden from RestRequest */ 1039 public MockRestRequest htmlDoc() { 1040 super.htmlDoc(); 1041 return this; 1042 } 1043 1044 @Override /* Overridden from RestRequest */ 1045 public MockRestRequest htmlStrippedDoc() { 1046 super.htmlStrippedDoc(); 1047 return this; 1048 } 1049 1050 @Override /* Overridden from RestRequest */ 1051 public MockRestRequest ignoreErrors() { 1052 super.ignoreErrors(); 1053 return this; 1054 } 1055 1056 @Override /* Overridden from RestRequest */ 1057 public MockRestRequest interceptors(RestCallInterceptor...interceptors) throws RestCallException{ 1058 super.interceptors(interceptors); 1059 return this; 1060 } 1061 1062 @Override /* Overridden from RestRequest */ 1063 public MockRestRequest json() { 1064 super.json(); 1065 return this; 1066 } 1067 1068 @Override /* Overridden from RestRequest */ 1069 public MockRestRequest mediaType(String value) throws RestCallException{ 1070 super.mediaType(value); 1071 return this; 1072 } 1073 1074 @Override /* Overridden from RestRequest */ 1075 public MockRestRequest msgPack() { 1076 super.msgPack(); 1077 return this; 1078 } 1079 1080 @Override /* Overridden from RestRequest */ 1081 public MockRestRequest noTrace() throws RestCallException{ 1082 super.noTrace(); 1083 return this; 1084 } 1085 1086 @Override /* Overridden from RestRequest */ 1087 public MockRestRequest openApi() { 1088 super.openApi(); 1089 return this; 1090 } 1091 1092 @Override /* Overridden from RestRequest */ 1093 public MockRestRequest parser(Class<? extends org.apache.juneau.parser.Parser> parser) { 1094 super.parser(parser); 1095 return this; 1096 } 1097 1098 @Override /* Overridden from RestRequest */ 1099 public MockRestRequest parser(Parser parser) { 1100 super.parser(parser); 1101 return this; 1102 } 1103 1104 @Override /* Overridden from RestRequest */ 1105 public MockRestRequest pathData(NameValuePair...parts) { 1106 super.pathData(parts); 1107 return this; 1108 } 1109 1110 @Override /* Overridden from RestRequest */ 1111 public MockRestRequest pathData(String name, Object value) { 1112 super.pathData(name, value); 1113 return this; 1114 } 1115 1116 @Override /* Overridden from RestRequest */ 1117 public MockRestRequest pathDataBean(Object value) { 1118 super.pathDataBean(value); 1119 return this; 1120 } 1121 1122 @Override /* Overridden from RestRequest */ 1123 public MockRestRequest pathDataPairs(String...pairs) { 1124 super.pathDataPairs(pairs); 1125 return this; 1126 } 1127 1128 @Override /* Overridden from RestRequest */ 1129 public MockRestRequest plainText() { 1130 super.plainText(); 1131 return this; 1132 } 1133 1134 @Override /* Overridden from RestRequest */ 1135 public MockRestRequest protocolVersion(ProtocolVersion version) { 1136 super.protocolVersion(version); 1137 return this; 1138 } 1139 1140 @Override /* Overridden from RestRequest */ 1141 public MockRestRequest queryCustom(Object value) { 1142 super.queryCustom(value); 1143 return this; 1144 } 1145 1146 @Override /* Overridden from RestRequest */ 1147 public MockRestRequest queryData(NameValuePair...parts) { 1148 super.queryData(parts); 1149 return this; 1150 } 1151 1152 @Override /* Overridden from RestRequest */ 1153 public MockRestRequest queryData(String name, Object value) { 1154 super.queryData(name, value); 1155 return this; 1156 } 1157 1158 @Override /* Overridden from RestRequest */ 1159 public MockRestRequest queryDataBean(Object value) { 1160 super.queryDataBean(value); 1161 return this; 1162 } 1163 1164 @Override /* Overridden from RestRequest */ 1165 public MockRestRequest queryDataPairs(String...pairs) throws RestCallException{ 1166 super.queryDataPairs(pairs); 1167 return this; 1168 } 1169 1170 @Override /* Overridden from RestRequest */ 1171 public MockRestRequest rethrow(java.lang.Class<?>...values) { 1172 super.rethrow(values); 1173 return this; 1174 } 1175 1176 @Override /* Overridden from RestRequest */ 1177 public MockRestRequest serializer(Class<? extends org.apache.juneau.serializer.Serializer> serializer) { 1178 super.serializer(serializer); 1179 return this; 1180 } 1181 1182 @Override /* Overridden from RestRequest */ 1183 public MockRestRequest serializer(Serializer serializer) { 1184 super.serializer(serializer); 1185 return this; 1186 } 1187 1188 @Override /* Overridden from RestRequest */ 1189 public MockRestRequest json5() { 1190 super.json5(); 1191 return this; 1192 } 1193 1194 @Override /* Overridden from RestRequest */ 1195 public MockRestRequest suppressLogging() { 1196 super.suppressLogging(); 1197 return this; 1198 } 1199 1200 @Override /* Overridden from RestRequest */ 1201 public MockRestRequest target(HttpHost target) { 1202 super.target(target); 1203 return this; 1204 } 1205 1206 @Override /* Overridden from RestRequest */ 1207 public MockRestRequest uon() { 1208 super.uon(); 1209 return this; 1210 } 1211 1212 @Override /* Overridden from RestRequest */ 1213 public MockRestRequest uri(Object uri) throws RestCallException{ 1214 super.uri(uri); 1215 return this; 1216 } 1217 1218 @Override /* Overridden from RestRequest */ 1219 public MockRestRequest uriFragment(String fragment) { 1220 super.uriFragment(fragment); 1221 return this; 1222 } 1223 1224 @Override /* Overridden from RestRequest */ 1225 public MockRestRequest uriHost(String host) { 1226 super.uriHost(host); 1227 return this; 1228 } 1229 1230 @Override /* Overridden from RestRequest */ 1231 public MockRestRequest uriPort(int port) { 1232 super.uriPort(port); 1233 return this; 1234 } 1235 1236 @Override /* Overridden from RestRequest */ 1237 public MockRestRequest uriUserInfo(String userInfo) { 1238 super.uriUserInfo(userInfo); 1239 return this; 1240 } 1241 1242 @Override /* Overridden from RestRequest */ 1243 public MockRestRequest uriUserInfo(String username, String password) { 1244 super.uriUserInfo(username, password); 1245 return this; 1246 } 1247 1248 @Override /* Overridden from RestRequest */ 1249 public MockRestRequest urlEnc() { 1250 super.urlEnc(); 1251 return this; 1252 } 1253 1254 @Override /* Overridden from RestRequest */ 1255 public MockRestRequest xml() { 1256 super.xml(); 1257 return this; 1258 } 1259}