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