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; 014 015import static org.apache.juneau.internal.ClassUtils.*; 016import static org.apache.juneau.internal.StringUtils.*; 017import static org.apache.juneau.parser.Parser.*; 018import static org.apache.juneau.rest.RestContext.*; 019import static org.apache.juneau.serializer.Serializer.*; 020 021import java.nio.charset.*; 022import java.util.*; 023 024import javax.servlet.*; 025 026import org.apache.juneau.*; 027import org.apache.juneau.config.*; 028import org.apache.juneau.config.vars.*; 029import org.apache.juneau.encoders.*; 030import org.apache.juneau.html.*; 031import org.apache.juneau.http.*; 032import org.apache.juneau.httppart.*; 033import org.apache.juneau.oapi.*; 034import org.apache.juneau.parser.*; 035import org.apache.juneau.reflect.*; 036import org.apache.juneau.rest.annotation.*; 037import org.apache.juneau.rest.reshandlers.*; 038import org.apache.juneau.rest.util.RestUtils; 039import org.apache.juneau.rest.vars.*; 040import org.apache.juneau.rest.widget.*; 041import org.apache.juneau.serializer.*; 042import org.apache.juneau.svl.*; 043import org.apache.juneau.svl.vars.*; 044import org.apache.juneau.utils.*; 045 046/** 047 * Defines the initial configuration of a <c>RestServlet</c> or <c>@RestResource</c> annotated object. 048 * 049 * <p> 050 * An extension of the {@link ServletConfig} object used during servlet initialization. 051 * 052 * <p> 053 * Provides access to the following initialized resources: 054 * <ul> 055 * <li>{@link #getConfig()} - The external configuration for this resource. 056 * <li>{@link #getProperties()} - The modifiable configuration properties for this resource. 057 * <li>{@link #getVarResolverBuilder()} - The variable resolver for this resource. 058 * </ul> 059 * 060 * <p> 061 * Methods are provided for overriding or augmenting the information provided by the <ja>@RestResource</ja> annotation. 062 * In general, most information provided in the <ja>@RestResource</ja> annotation can be specified programmatically 063 * through calls on this object. 064 * 065 * <p> 066 * To interact with this object, simply pass it in as a constructor argument or in an INIT hook. 067 * <p class='bcode w800'> 068 * <jc>// Option #1 - Pass in through constructor.</jc> 069 * <jk>public</jk> MyResource(RestContextBuilder builder) { 070 * builder 071 * .pojoSwaps(TemporalCalendarSwap.IsoLocalDateTime.<jk>class</jk>) 072 * .set(<jsf>PARSER_debug</jsf>, <jk>true</jk>); 073 * } 074 * 075 * <jc>// Option #2 - Use an INIT hook.</jc> 076 * <ja>@RestHook</ja>(<jsf>INIT</jsf>) 077 * <jk>public void</jk> init(RestContextBuilder builder) <jk>throws</jk> Exception { 078 * builder 079 * .pojoSwaps(TemporalCalendarSwap.IsoLocalDateTime.<jk>class</jk>) 080 * .set(<jsf>PARSER_debug</jsf>, <jk>true</jk>); 081 * } 082 * </p> 083 * 084 * <ul class='seealso'> 085 * <li class='link'>{@doc juneau-rest-server.RestContext} 086 * </ul> 087 */ 088public class RestContextBuilder extends BeanContextBuilder implements ServletConfig { 089 090 final ServletConfig inner; 091 092 Class<?> resourceClass; 093 Object resource; 094 ServletContext servletContext; 095 RestContext parentContext; 096 097 //----------------------------------------------------------------------------------------------------------------- 098 // The following fields are meant to be modifiable. 099 // They should not be declared final. 100 // Read-only snapshots of these will be made in RestServletContext. 101 //----------------------------------------------------------------------------------------------------------------- 102 103 RestContextProperties properties; 104 Config config; 105 VarResolverBuilder varResolverBuilder; 106 107 @SuppressWarnings("deprecation") 108 RestContextBuilder(ServletConfig servletConfig, Class<?> resourceClass, RestContext parentContext) throws ServletException { 109 this.inner = servletConfig; 110 this.resourceClass = resourceClass; 111 this.parentContext = parentContext; 112 this.properties = new RestContextProperties(); 113 114 ClassInfo rci = getClassInfo(resourceClass); 115 116 // Default values. 117 logger(BasicRestLogger.class); 118 partSerializer(OpenApiSerializer.class); 119 partParser(OpenApiParser.class); 120 staticFileResponseHeader("Cache-Control", "max-age=86400, public"); 121 encoders(IdentityEncoder.INSTANCE); 122 responseHandlers( 123 ReaderHandler.class, 124 InputStreamHandler.class, 125 DefaultHandler.class 126 ); 127 128 try { 129 130 varResolverBuilder = new VarResolverBuilder() 131 .defaultVars() 132 .vars(ConfigVar.class) 133 .vars(FileVar.class) 134 .contextObject("crm", new ClasspathResourceManager(resourceClass)); 135 136 VarResolver vr = varResolverBuilder.build(); 137 138 List<AnnotationInfo<RestResource>> restResourceAnnotationsParentFirst = rci.getAnnotationInfosParentFirst(RestResource.class); 139 140 // Find our config file. It's the last non-empty @RestResource(config). 141 String configPath = ""; 142 for (AnnotationInfo<RestResource> r : restResourceAnnotationsParentFirst) 143 if (! r.getAnnotation().config().isEmpty()) 144 configPath = r.getAnnotation().config(); 145 String cf = vr.resolve(configPath); 146 147 if ("SYSTEM_DEFAULT".equals(cf)) 148 this.config = Config.getSystemDefault(); 149 150 if (this.config == null) { 151 ConfigBuilder cb = Config.create().varResolver(vr); 152 if (! cf.isEmpty()) 153 cb.name(cf); 154 this.config = cb.build(); 155 } 156 157 // Add our config file to the variable resolver. 158 varResolverBuilder.contextObject(ConfigVar.SESSION_config, config); 159 vr = varResolverBuilder.build(); 160 161 // Add the servlet init parameters to our properties. 162 if (servletConfig != null) { 163 for (Enumeration<String> ep = servletConfig.getInitParameterNames(); ep.hasMoreElements();) { 164 String p = ep.nextElement(); 165 String initParam = servletConfig.getInitParameter(p); 166 set(vr.resolve(p), vr.resolve(initParam)); 167 } 168 } 169 170 applyAnnotations(rci.getAnnotationListParentFirst(ConfigAnnotationFilter.INSTANCE), vr.createSession()); 171 172 // Load stuff from parent-to-child order. 173 // This allows child settings to overwrite parent settings. 174 for (AnnotationInfo<RestResource> e : restResourceAnnotationsParentFirst) { 175 176 RestResource r = e.getAnnotation(); 177 for (Property p : r.properties()) 178 set(vr.resolve(p.name()), vr.resolve(p.value())); 179 for (String p : r.flags()) 180 set(p, true); 181 } 182 183 } catch (Exception e) { 184 throw new ServletException(e); 185 } 186 } 187 188 @Override /* BeanContextBuilder */ 189 public RestContext build() { 190 try { 191 return new RestContext(this); 192 } catch (RestException e) { 193 throw e; 194 } catch (Exception e) { 195 throw new RuntimeException(e); 196 } 197 } 198 199 /* 200 * Calls all @RestHook(INIT) methods on the specified resource object. 201 */ 202 RestContextBuilder init(Object resource) throws ServletException { 203 this.resource = resource; 204 ClassInfo rci = getClassInfo(resourceClass); 205 206 Map<String,MethodInfo> map = new LinkedHashMap<>(); 207 for (MethodInfo m : rci.getAllMethodsParentFirst()) { 208 if (m.hasAnnotation(RestHook.class) && m.getAnnotation(RestHook.class).value() == HookEvent.INIT) { 209 m.setAccessible(); 210 String sig = m.getSignature(); 211 if (! map.containsKey(sig)) 212 map.put(sig, m); 213 } 214 } 215 for (MethodInfo m : map.values()) { 216 assertArgsOnlyOfType(m, RestContextBuilder.class, ServletConfig.class); 217 Class<?>[] pt = m.getRawParamTypes(); 218 Object[] args = new Object[pt.length]; 219 for (int i = 0; i < args.length; i++) { 220 if (pt[i] == RestContextBuilder.class) 221 args[i] = this; 222 else 223 args[i] = this.inner; 224 } 225 try { 226 m.invoke(resource, args); 227 } catch (Exception e) { 228 throw new RestServletException("Exception thrown from @RestHook(INIT) method {0}.", m).initCause(e); 229 } 230 } 231 return this; 232 } 233 234 private static void assertArgsOnlyOfType(MethodInfo m, Class<?>...args) { 235 if (! m.argsOnlyOfType(args)) 236 throw new FormattedIllegalArgumentException("Invalid arguments passed to method {0}. Only arguments of type {1} are allowed.", m, args); 237 } 238 239 RestContextBuilder servletContext(ServletContext servletContext) { 240 this.servletContext = servletContext; 241 return this; 242 } 243 244 /** 245 * Adds the specified {@link Var} classes to this config. 246 * 247 * <p> 248 * These variables affect the variable resolver returned by {@link RestRequest#getVarResolverSession()} which is 249 * used to resolve string variables of the form <js>"$X{...}"</js>. 250 * 251 * <p> 252 * See {@link RestContext#getVarResolver()} for a list of predefined variables. 253 * 254 * @param vars The {@link Var} classes to add to this config. 255 * @return This object (for method chaining). 256 */ 257 public RestContextBuilder vars(Class<?>...vars) { 258 this.varResolverBuilder.vars(vars); 259 return this; 260 } 261 262 /** 263 * Adds a var context object to this config. 264 * 265 * <p> 266 * Var context objects are read-only objects associated with the variable resolver for vars that require external 267 * information. 268 * 269 * <p> 270 * For example, the {@link ConfigVar} needs access to this resource's {@link Config} through the 271 * {@link ConfigVar#SESSION_config} object that can be specified as either a session object (temporary) or 272 * context object (permanent). 273 * In this case, we call the following code to add it to the context map: 274 * <p class='bcode w800'> 275 * config.addVarContextObject(<jsf>SESSION_config</jsf>, configFile); 276 * </p> 277 * 278 * @param name The context object key (i.e. the name that the Var class looks for). 279 * @param object The context object. 280 * @return This object (for method chaining). 281 */ 282 public RestContextBuilder varContextObject(String name, Object object) { 283 this.varResolverBuilder.contextObject(name, object); 284 return this; 285 } 286 287 /** 288 * Overwrites the default config file with a custom config file. 289 * 290 * <p> 291 * By default, the config file is determined using the {@link RestResource#config() @RestResource(config)} 292 * annotation. 293 * This method allows you to programmatically override it with your own custom config file. 294 * 295 * @param config The new config file. 296 * @return This object (for method chaining). 297 */ 298 public RestContextBuilder config(Config config) { 299 this.config = config; 300 return this; 301 } 302 303 /** 304 * Creates a new {@link PropertyStore} object initialized with the properties defined in this config. 305 * 306 * @return A new property store. 307 */ 308 protected PropertyStoreBuilder createPropertyStore() { 309 return PropertyStore.create().add(properties); 310 } 311 312 313 //---------------------------------------------------------------------------------------------------- 314 // Methods that give access to the config file, var resolver, and properties. 315 //---------------------------------------------------------------------------------------------------- 316 317 /** 318 * Returns the external configuration file for this resource. 319 * 320 * <p> 321 * The configuration file location is determined via the {@link RestResource#config() @RestResource(config)} 322 * annotation on the resource. 323 * 324 * <p> 325 * The config file can be programmatically overridden by adding the following method to your resource: 326 * <p class='bcode w800'> 327 * <jk>public</jk> Config createConfig(ServletConfig servletConfig) <jk>throws</jk> ServletException; 328 * </p> 329 * 330 * <p> 331 * If a config file is not set up, then an empty config file will be returned that is not backed by any file. 332 * 333 * @return The external config file for this resource. Never <jk>null</jk>. 334 */ 335 public Config getConfig() { 336 return config; 337 } 338 339 /** 340 * Returns the configuration properties for this resource. 341 * 342 * <p> 343 * The configuration properties are determined via the {@link RestResource#properties() @RestResource(properties)} annotation on the resource. 344 * 345 * <p> 346 * The configuration properties can be augmented programmatically by adding the following method to your resource: 347 * <p class='bcode w800'> 348 * <jk>public</jk> RestContextProperties createProperties(ServletConfig servletConfig) <jk>throws</jk> ServletException; 349 * </p> 350 * 351 * <p> 352 * These properties can be modified during servlet initialization. 353 * However, any modifications made after {@link RestServlet#init(ServletConfig)} has been called will have no effect. 354 * 355 * @return The configuration properties for this resource. Never <jk>null</jk>. 356 */ 357 public RestContextProperties getProperties() { 358 return properties; 359 } 360 361 /** 362 * Creates the variable resolver for this resource. 363 * 364 * <p> 365 * The variable resolver returned by this method can resolve the following variables: 366 * <ul> 367 * <li>{@link SystemPropertiesVar} 368 * <li>{@link EnvVariablesVar} 369 * <li>{@link ConfigVar} 370 * <li>{@link IfVar} 371 * <li>{@link SwitchVar} 372 * </ul> 373 * 374 * <p> 375 * Note that the variables supported here are only a subset of those returned by 376 * {@link RestRequest#getVarResolverSession()}. 377 * 378 * @return The variable resolver for this resource. Never <jk>null</jk>. 379 */ 380 public VarResolverBuilder getVarResolverBuilder() { 381 return varResolverBuilder; 382 } 383 384 /** 385 * Returns the REST path defined on this builder. 386 * 387 * @return The REST path defined on this builder. 388 */ 389 public String getPath() { 390 Object p = peek(REST_path); 391 return p == null ? "_" : p.toString(); 392 } 393 394 //---------------------------------------------------------------------------------------------------- 395 // Properties 396 //---------------------------------------------------------------------------------------------------- 397 398 /** 399 * Configuration property: Allow body URL parameter. 400 * 401 * <p> 402 * When enabled, the HTTP body content on PUT and POST requests can be passed in as text using the <js>"body"</js> 403 * URL parameter. 404 * <br> 405 * For example: 406 * <p class='bcode w800'> 407 * ?body=(name='John%20Smith',age=45) 408 * </p> 409 * 410 * <ul class='seealso'> 411 * <li class='jf'>{@link RestContext#REST_allowBodyParam} 412 * </ul> 413 * 414 * @param value 415 * The new value for this setting. 416 * <br>The default is <jk>true</jk>. 417 * @return This object (for method chaining). 418 */ 419 public RestContextBuilder allowBodyParam(boolean value) { 420 return set(REST_allowBodyParam, value); 421 } 422 423 /** 424 * Configuration property: Allowed header URL parameters. 425 * 426 * <p> 427 * When specified, allows headers such as <js>"Accept"</js> and <js>"Content-Type"</js> to be passed in as URL query 428 * parameters. 429 * <br> 430 * For example: 431 * <p class='bcode w800'> 432 * ?Accept=text/json&Content-Type=text/json 433 * </p> 434 * 435 * <ul class='seealso'> 436 * <li class='jf'>{@link RestContext#REST_allowedHeaderParams} 437 * </ul> 438 * 439 * @param value 440 * The new value for this setting. 441 * <br>The default is <jk>true</jk>. 442 * @return This object (for method chaining). 443 */ 444 public RestContextBuilder allowedHeaderParams(String value) { 445 return set(REST_allowedHeaderParams, value); 446 } 447 448 /** 449 * Configuration property: Allowed method headers. 450 * 451 * <p> 452 * A comma-delimited list of HTTP method names that are allowed to be passed as values in an <c>X-Method</c> HTTP header 453 * to override the real HTTP method name. 454 * <p> 455 * Allows you to override the actual HTTP method with a simulated method. 456 * <br>For example, if an HTTP Client API doesn't support <c>PATCH</c> but does support <c>POST</c> (because 457 * <c>PATCH</c> is not part of the original HTTP spec), you can add a <c>X-Method: PATCH</c> header on a normal 458 * <c>HTTP POST /foo</c> request call which will make the HTTP call look like a <c>PATCH</c> request in any of the REST APIs. 459 * 460 * <ul class='seealso'> 461 * <li class='jf'>{@link RestContext#REST_allowedMethodHeaders} 462 * </ul> 463 * 464 * @param value 465 * The new value for this setting. 466 * <br>The default is <jk>true</jk>. 467 * @return This object (for method chaining). 468 */ 469 public RestContextBuilder allowedMethodHeaders(String value) { 470 return set(REST_allowedMethodHeaders, value); 471 } 472 473 /** 474 * Configuration property: Allowed method parameters. 475 * 476 * <p> 477 * When specified, the HTTP method can be overridden by passing in a <js>"method"</js> URL parameter on a regular 478 * GET request. 479 * <br> 480 * For example: 481 * <p class='bcode w800'> 482 * ?method=OPTIONS 483 * </p> 484 * 485 * <ul class='seealso'> 486 * <li class='jf'>{@link RestContext#REST_allowedMethodParams} 487 * </ul> 488 * 489 * @param value 490 * The new value for this setting. 491 * <br>The default is <code>[<js>"HEAD"</js>,<js>"OPTIONS"</js>]</code>. 492 * <br>Individual values can also be comma-delimited lists. 493 * @return This object (for method chaining). 494 */ 495 public RestContextBuilder allowedMethodParams(String value) { 496 return set(REST_allowedMethodParams, value); 497 } 498 499 /** 500 * Configuration property: Allow header URL parameters. 501 * 502 * <p> 503 * When enabled, headers such as <js>"Accept"</js> and <js>"Content-Type"</js> to be passed in as URL query 504 * parameters. 505 * <br> 506 * For example: 507 * <p class='bcode w800'> 508 * ?Accept=text/json&Content-Type=text/json 509 * </p> 510 * 511 * <ul class='seealso'> 512 * <li class='jf'>{@link RestContext#REST_allowHeaderParams} 513 * </ul> 514 * 515 * @param value 516 * The new value for this setting. 517 * <br>The default is <jk>true</jk>. 518 * @return This object (for method chaining). 519 * @deprecated Use {@link #allowedHeaderParams(String)} 520 */ 521 @Deprecated 522 public RestContextBuilder allowHeaderParams(boolean value) { 523 return set(REST_allowedHeaderParams, value ? "*" : null); 524 } 525 526 /** 527 * Configuration property: REST call handler. 528 * 529 * <p> 530 * This class handles the basic lifecycle of an HTTP REST call. 531 * <br>Subclasses can be used to customize how these HTTP calls are handled. 532 * 533 * <ul class='seealso'> 534 * <li class='jf'>{@link RestContext#REST_callHandler} 535 * </ul> 536 * 537 * @param value 538 * The new value for this setting. 539 * <br>The default is {@link BasicRestCallHandler}. 540 * @return This object (for method chaining). 541 */ 542 public RestContextBuilder callHandler(Class<? extends RestCallHandler> value) { 543 return set(REST_callHandler, value); 544 } 545 546 /** 547 * Configuration property: REST call handler. 548 * 549 * <p> 550 * Same as {@link #callHandler(Class)} except input is a pre-constructed instance. 551 * 552 * <ul class='seealso'> 553 * <li class='jf'>{@link RestContext#REST_callHandler} 554 * </ul> 555 * 556 * @param value 557 * The new value for this setting. 558 * <br>The default is {@link BasicRestCallHandler}. 559 * @return This object (for method chaining). 560 */ 561 public RestContextBuilder callHandler(RestCallHandler value) { 562 return set(REST_callHandler, value); 563 } 564 565 /** 566 * Configuration property: REST call logger. 567 * 568 * <p> 569 * Specifies the logger to use for logging of HTTP requests and responses. 570 * 571 * <ul class='seealso'> 572 * <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging} 573 * <li class='jf'>{@link RestContext#REST_callLogger} 574 * </ul> 575 * 576 * @param value 577 * The new value for this setting. 578 * <br>The default is {@link BasicRestCallLogger}. 579 * @return This object (for method chaining). 580 */ 581 public RestContextBuilder callLogger(Class<? extends RestCallLogger> value) { 582 return set(REST_callLogger, value); 583 } 584 585 /** 586 * Configuration property: REST call logger. 587 * 588 * <p> 589 * Specifies the logger to use for logging of HTTP requests and responses. 590 * 591 * <ul class='seealso'> 592 * <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging} 593 * <li class='jf'>{@link RestContext#REST_callLogger} 594 * </ul> 595 * 596 * @param value 597 * The new value for this setting. 598 * <br>The default is {@link BasicRestCallLogger}. 599 * @return This object (for method chaining). 600 */ 601 public RestContextBuilder callLogger(RestCallLogger value) { 602 return set(REST_callLogger, value); 603 } 604 605 /** 606 * Configuration property: REST call logging rules. 607 * 608 * <p> 609 * Specifies rules on how to handle logging of HTTP requests/responses. 610 * 611 * <ul class='seealso'> 612 * <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging} 613 * <li class='jf'>{@link RestContext#REST_callLoggerConfig} 614 * </ul> 615 * 616 * @param value 617 * The new value for this setting. 618 * <br>The default is {@link RestCallLoggerConfig#DEFAULT}. 619 * @return This object (for method chaining). 620 */ 621 public RestContextBuilder callLoggerConfig(RestCallLoggerConfig value) { 622 return set(REST_callLoggerConfig, value); 623 } 624 625 /** 626 * Configuration property: Children. 627 * 628 * <p> 629 * Defines children of this resource. 630 * 631 * <p> 632 * A REST child resource is simply another servlet that is initialized as part of the parent resource and has a 633 * servlet path directly under the parent servlet path. 634 * 635 * <ul class='seealso'> 636 * <li class='jf'>{@link RestContext#REST_children} 637 * </ul> 638 * 639 * @param values The values to add to this setting. 640 * @return This object (for method chaining). 641 */ 642 public RestContextBuilder children(Class<?>...values) { 643 return addTo(REST_children, values); 644 } 645 646 /** 647 * Configuration property: Children. 648 * 649 * <p> 650 * Same as {@link #children(Class...)} except input is pre-constructed instances. 651 * 652 * <ul class='seealso'> 653 * <li class='jf'>{@link RestContext#REST_children} 654 * </ul> 655 * 656 * @param values The values to add to this setting. 657 * @return This object (for method chaining). 658 */ 659 public RestContextBuilder children(Object...values) { 660 return addTo(REST_children, values); 661 } 662 663 /** 664 * Configuration property: Children. 665 * 666 * <p> 667 * Shortcut for adding a single child to this resource. 668 * 669 * <p> 670 * This can be used for resources that don't have a {@link RestResource#path() @RestResource(path)} annotation. 671 * 672 * <ul class='seealso'> 673 * <li class='jf'>{@link RestContext#REST_children} 674 * </ul> 675 * 676 * @param path The child path relative to the parent resource URI. 677 * @param child The child to add to this resource. 678 * @return This object (for method chaining). 679 */ 680 public RestContextBuilder child(String path, Object child) { 681 return addTo(REST_children, new RestChild(path, child)); 682 } 683 684 /** 685 * Configuration property: Classpath resource finder. 686 * 687 * <p> 688 * Used to retrieve localized files from the classpath. 689 * 690 * <ul class='seealso'> 691 * <li class='jf'>{@link RestContext#REST_classpathResourceFinder} 692 * </ul> 693 * 694 * @param value 695 * The new value for this setting. 696 * <br>The default is {@link ClasspathResourceFinderBasic}. 697 * @return This object (for method chaining). 698 */ 699 public RestContextBuilder classpathResourceFinder(Class<? extends ClasspathResourceFinder> value) { 700 return set(REST_classpathResourceFinder, value); 701 } 702 703 /** 704 * Configuration property: Classpath resource finder. 705 * 706 * <p> 707 * Same as {@link #classpathResourceFinder(ClasspathResourceFinder)} except input is a pre-constructed instance. 708 * 709 * <ul class='seealso'> 710 * <li class='jf'>{@link RestContext#REST_classpathResourceFinder} 711 * </ul> 712 * 713 * @param value 714 * The new value for this setting. 715 * <br>The default is {@link ClasspathResourceFinderBasic}. 716 * @return This object (for method chaining). 717 */ 718 public RestContextBuilder classpathResourceFinder(ClasspathResourceFinder value) { 719 return set(REST_classpathResourceFinder, value); 720 } 721 722 /** 723 * Configuration property: Client version header. 724 * 725 * <p> 726 * Specifies the name of the header used to denote the client version on HTTP requests. 727 * 728 * <p> 729 * The client version is used to support backwards compatibility for breaking REST interface changes. 730 * <br>Used in conjunction with {@link RestMethod#clientVersion() @RestMethod(clientVersion)} annotation. 731 * 732 * <ul class='seealso'> 733 * <li class='jf'>{@link RestContext#REST_clientVersionHeader} 734 * </ul> 735 * 736 * @param value 737 * The new value for this setting. 738 * <br>The default is <js>"X-Client-Version"</js>. 739 * @return This object (for method chaining). 740 */ 741 public RestContextBuilder clientVersionHeader(String value) { 742 return set(REST_clientVersionHeader, value); 743 } 744 745 /** 746 * Configuration property: Class-level response converters. 747 * 748 * <p> 749 * Associates one or more {@link RestConverter converters} with a resource class. 750 * 751 * <ul class='seealso'> 752 * <li class='jf'>{@link RestContext#REST_converters} 753 * </ul> 754 * 755 * @param values The values to add to this setting. 756 * @return This object (for method chaining). 757 */ 758 public RestContextBuilder converters(Class<?>...values) { 759 return addTo(REST_converters, values); 760 } 761 762 /** 763 * Configuration property: Response converters. 764 * 765 * <p> 766 * Same as {@link #converters(Class...)} except input is pre-constructed instances. 767 * 768 * <ul class='seealso'> 769 * <li class='jf'>{@link RestContext#REST_converters} 770 * </ul> 771 * 772 * @param values The values to add to this setting. 773 * @return This object (for method chaining). 774 */ 775 public RestContextBuilder converters(RestConverter...values) { 776 return addTo(REST_converters, values); 777 } 778 779 /** 780 * Configuration property: Debug mode. 781 * 782 * Enables the following: 783 * <ul class='spaced-list'> 784 * <li> 785 * HTTP request/response bodies are cached in memory for logging purposes. 786 * <li> 787 * Request/response messages are automatically logged. 788 * </ul> 789 * 790 * <ul class='seealso'> 791 * <li class='jf'>{@link RestContext#REST_debug} 792 * <li class='jf'>{@link BeanContext#BEAN_debug} 793 * </ul> 794 * 795 * @param value The new value for this setting. 796 * @return This object (for method chaining). 797 */ 798 @Override 799 public RestContextBuilder debug(boolean value) { 800 super.debug(value); 801 return debug(Enablement.TRUE); 802 } 803 804 /** 805 * Configuration property: Debug mode. 806 * 807 * <p> 808 * Enables the following: 809 * <ul class='spaced-list'> 810 * <li> 811 * HTTP request/response bodies are cached in memory for logging purposes. 812 * </ul> 813 * 814 * @param value The new value for this setting. 815 * @return This object (for method chaining). 816 */ 817 public RestContextBuilder debug(Enablement value) { 818 return set(REST_debug, value); 819 } 820 821 /** 822 * Configuration property: Default character encoding. 823 * 824 * <p> 825 * The default character encoding for the request and response if not specified on the request. 826 * 827 * <ul class='seealso'> 828 * <li class='jf'>{@link RestContext#REST_defaultCharset} 829 * </ul> 830 * 831 * @param value 832 * The new value for this setting. 833 * <br>The default is <js>"utf-8"</js>. 834 * @return This object (for method chaining). 835 */ 836 public RestContextBuilder defaultCharset(String value) { 837 return set(REST_defaultCharset, value); 838 } 839 840 /** 841 * Configuration property: Default character encoding. 842 * 843 * <p> 844 * Same as {@link #defaultCharset(Charset)} but takes in an instance of {@link Charset}. 845 * 846 * <ul class='seealso'> 847 * <li class='jf'>{@link RestContext#REST_defaultCharset} 848 * </ul> 849 * 850 * @param value 851 * The new value for this setting. 852 * <br>The default is <js>"utf-8"</js>. 853 * @return This object (for method chaining). 854 */ 855 public RestContextBuilder defaultCharset(Charset value) { 856 return set(REST_defaultCharset, value); 857 } 858 859 /** 860 * Configuration property: Default request attributes. 861 * 862 * <p> 863 * Specifies default values for request attributes if they're not already set on the request. 864 * 865 * <ul class='seealso'> 866 * <li class='jf'>{@link RestContext#REST_attrs} 867 * </ul> 868 * 869 * @param values The attributes in the format <js>"Name: value"</js>. 870 * @return This object (for method chaining). 871 * @throws RestServletException If malformed header is found. 872 */ 873 public RestContextBuilder attrs(String...values) throws RestServletException { 874 for (String v : values) { 875 String[] p = RestUtils.parseKeyValuePair(v); 876 if (p == null) 877 throw new RestServletException("Invalid default request attribute specified: ''{0}''. Must be in the format: ''Name: value''", v); 878 defaultRequestHeader(p[0], p[1]); 879 } 880 return this; 881 } 882 883 /** 884 * Configuration property: Default request headers. 885 * 886 * <p> 887 * Specifies default values for request headers if they're not passed in through the request. 888 * 889 * <ul class='seealso'> 890 * <li class='jf'>{@link RestContext#REST_defaultRequestHeaders} 891 * </ul> 892 * 893 * @param headers The headers in the format <js>"Header-Name: header-value"</js>. 894 * @return This object (for method chaining). 895 * @throws RestServletException If malformed header is found. 896 */ 897 public RestContextBuilder defaultRequestHeaders(String...headers) throws RestServletException { 898 for (String header : headers) { 899 String[] h = RestUtils.parseHeader(header); 900 if (h == null) 901 throw new RestServletException("Invalid default request header specified: ''{0}''. Must be in the format: ''Header-Name: header-value''", header); 902 defaultRequestHeader(h[0], h[1]); 903 } 904 return this; 905 } 906 907 /** 908 * Specifies a default <c>Accept</c> header value if not specified on a request. 909 * 910 * @param value 911 * The default value of the <c>Accept</c> header. 912 * <br>Ignored if <jk>null</jk> or empty. 913 * @return This object (for method chaining). 914 */ 915 public RestContextBuilder defaultAccept(String value) { 916 if (isNotEmpty(value)) 917 defaultRequestHeader("Accept", value); 918 return this; 919 } 920 921 /** 922 * Specifies a default <c>Content-Type</c> header value if not specified on a request. 923 * 924 * @param value 925 * The default value of the <c>Content-Type</c> header. 926 * <br>Ignored if <jk>null</jk> or empty. 927 * @return This object (for method chaining). 928 */ 929 public RestContextBuilder defaultContentType(String value) { 930 if (isNotEmpty(value)) 931 defaultRequestHeader("Content-Type", value); 932 return this; 933 } 934 935 /** 936 * Configuration property: Default request attribute. 937 * 938 * <p> 939 * Same as {@link #attrs(String...)} but adds a single attribute name/value pair. 940 * 941 * <ul class='seealso'> 942 * <li class='jf'>{@link RestContext#REST_attrs} 943 * </ul> 944 * 945 * @param name The HTTP header name. 946 * @param value The HTTP header value. 947 * @return This object (for method chaining). 948 */ 949 public RestContextBuilder attr(String name, Object value) { 950 return addTo(REST_attrs, name, value); 951 } 952 953 /** 954 * Configuration property: Default request headers. 955 * 956 * <p> 957 * Same as {@link #defaultRequestHeaders(String...)} but adds a single header name/value pair. 958 * 959 * <ul class='seealso'> 960 * <li class='jf'>{@link RestContext#REST_defaultRequestHeaders} 961 * </ul> 962 * 963 * @param name The HTTP header name. 964 * @param value The HTTP header value. 965 * @return This object (for method chaining). 966 */ 967 public RestContextBuilder defaultRequestHeader(String name, Object value) { 968 return addTo(REST_defaultRequestHeaders, name, value); 969 } 970 971 /** 972 * Configuration property: Default response headers. 973 * 974 * <p> 975 * Specifies default values for response headers if they're not set after the Java REST method is called. 976 * 977 * <ul class='seealso'> 978 * <li class='jf'>{@link RestContext#REST_defaultResponseHeaders} 979 * </ul> 980 * 981 * @param headers The headers in the format <js>"Header-Name: header-value"</js>. 982 * @return This object (for method chaining). 983 * @throws RestServletException If malformed header is found. 984 */ 985 public RestContextBuilder defaultResponseHeaders(String...headers) throws RestServletException { 986 for (String header : headers) { 987 String[] h = RestUtils.parseHeader(header); 988 if (h == null) 989 throw new RestServletException("Invalid default response header specified: ''{0}''. Must be in the format: ''Header-Name: header-value''", header); 990 defaultResponseHeader(h[0], h[1]); 991 } 992 return this; 993 } 994 995 /** 996 * Configuration property: Default response headers. 997 * 998 * <p> 999 * Same as {@link #defaultResponseHeaders(String...)} but adds a single header name/value pair. 1000 * 1001 * <ul class='seealso'> 1002 * <li class='jf'>{@link RestContext#REST_defaultResponseHeaders} 1003 * </ul> 1004 * 1005 * @param name The HTTP header name. 1006 * @param value The HTTP header value. 1007 * @return This object (for method chaining). 1008 */ 1009 public RestContextBuilder defaultResponseHeader(String name, Object value) { 1010 return addTo(REST_defaultResponseHeaders, name, value); 1011 } 1012 1013 /** 1014 * Configuration property: Compression encoders. 1015 * 1016 * <p> 1017 * These can be used to enable various kinds of compression (e.g. <js>"gzip"</js>) on requests and responses. 1018 * 1019 * <ul class='seealso'> 1020 * <li class='jf'>{@link RestContext#REST_encoders} 1021 * </ul> 1022 * 1023 * @param values The values to add to this setting. 1024 * @return This object (for method chaining). 1025 */ 1026 public RestContextBuilder encoders(Class<?>...values) { 1027 return addTo(REST_encoders, values); 1028 } 1029 1030 /** 1031 * Configuration property: Compression encoders. 1032 * 1033 * <p> 1034 * Same as {@link #encoders(Class...)} except input a pre-constructed instances. 1035 * 1036 * <ul class='seealso'> 1037 * <li class='jf'>{@link RestContext#REST_encoders} 1038 * </ul> 1039 * 1040 * @param values The values to add to this setting. 1041 * @return This object (for method chaining). 1042 */ 1043 public RestContextBuilder encoders(Encoder...values) { 1044 return addTo(REST_encoders, values); 1045 } 1046 1047 /** 1048 * Configuration property: Class-level guards. 1049 * 1050 * <p> 1051 * Associates one or more {@link RestGuard RestGuards} with all REST methods defined in this class. 1052 * 1053 * <ul class='seealso'> 1054 * <li class='jf'>{@link RestContext#REST_guards} 1055 * </ul> 1056 * 1057 * @param values The values to add to this setting. 1058 * @return This object (for method chaining). 1059 */ 1060 public RestContextBuilder guards(Class<?>...values) { 1061 return addTo(REST_guards, values); 1062 } 1063 1064 /** 1065 * Configuration property: Class-level guards. 1066 * 1067 * <p> 1068 * Same as {@link #guards(Class...)} except input is pre-constructed instances. 1069 * 1070 * <ul class='seealso'> 1071 * <li class='jf'>{@link RestContext#REST_guards} 1072 * </ul> 1073 * 1074 * @param values The values to add to this setting. 1075 * @return This object (for method chaining). 1076 */ 1077 public RestContextBuilder guards(RestGuard...values) { 1078 return addTo(REST_guards, values); 1079 } 1080 1081 /** 1082 * Configuration property: REST info provider. 1083 * 1084 * <p> 1085 * Class used to retrieve title/description/swagger information about a resource. 1086 * 1087 * <ul class='seealso'> 1088 * <li class='jf'>{@link RestContext#REST_infoProvider} 1089 * </ul> 1090 * 1091 * @param value 1092 * The new value for this setting. 1093 * <br>The default is {@link BasicRestInfoProvider}. 1094 * @return This object (for method chaining). 1095 */ 1096 public RestContextBuilder infoProvider(Class<? extends RestInfoProvider> value) { 1097 return set(REST_infoProvider, value); 1098 } 1099 1100 /** 1101 * Configuration property: REST info provider. 1102 * 1103 * <p> 1104 * Same as {@link #infoProvider(Class)} except input is a pre-constructed instance. 1105 * 1106 * <ul class='seealso'> 1107 * <li class='jf'>{@link RestContext#REST_infoProvider} 1108 * </ul> 1109 * 1110 * @param value 1111 * The new value for this setting. 1112 * <br>The default is {@link BasicRestInfoProvider}. 1113 * @return This object (for method chaining). 1114 */ 1115 public RestContextBuilder infoProvider(RestInfoProvider value) { 1116 return set(REST_infoProvider, value); 1117 } 1118 1119 /** 1120 * Configuration property: REST logger. 1121 * 1122 * <p> 1123 * Specifies the logger to use for logging. 1124 * 1125 * <ul class='seealso'> 1126 * <li class='jf'>{@link RestContext#REST_logger} 1127 * </ul> 1128 * 1129 * @param value 1130 * The new value for this setting. 1131 * <br>The default is {@link BasicRestCallLogger}. 1132 * <br>Can be <jk>null</jk> to disable logging. 1133 * @return This object (for method chaining). 1134 * @deprecated Use {@link #callLogger(Class)} 1135 */ 1136 @Deprecated 1137 public RestContextBuilder logger(Class<? extends RestLogger> value) { 1138 return set(REST_logger, value); 1139 } 1140 1141 /** 1142 * Configuration property: REST logger. 1143 * 1144 * <p> 1145 * Same as {@link #logger(Class)} except input is a pre-constructed instance. 1146 * 1147 * <ul class='seealso'> 1148 * <li class='jf'>{@link RestContext#REST_logger} 1149 * </ul> 1150 * 1151 * @param value 1152 * The new value for this setting. 1153 * <br>The default is {@link BasicRestLogger}. 1154 * <br>Can be <jk>null</jk> to disable logging. 1155 * @return This object (for method chaining). 1156 * @deprecated Use {@link #callLogger(RestCallLogger)} 1157 */ 1158 @Deprecated 1159 public RestContextBuilder logger(RestLogger value) { 1160 return set(REST_logger, value); 1161 } 1162 1163 /** 1164 * Configuration property: The maximum allowed input size (in bytes) on HTTP requests. 1165 * 1166 * <p> 1167 * Useful for alleviating DoS attacks by throwing an exception when too much input is received instead of resulting 1168 * in out-of-memory errors which could affect system stability. 1169 * 1170 * <ul class='seealso'> 1171 * <li class='jf'>{@link RestContext#REST_maxInput} 1172 * </ul> 1173 * 1174 * @param value 1175 * The new value for this setting. 1176 * <br>The default is <js>"100M"</js>. 1177 * @return This object (for method chaining). 1178 */ 1179 public RestContextBuilder maxInput(String value) { 1180 return set(REST_maxInput, value); 1181 } 1182 1183 /** 1184 * Configuration property: Messages. 1185 * 1186 * <p> 1187 * Identifies the location of the resource bundle for this class. 1188 * 1189 * <ul class='seealso'> 1190 * <li class='jf'>{@link RestContext#REST_messages} 1191 * </ul> 1192 * 1193 * @param values The values to add to this setting. 1194 * @return This object (for method chaining). 1195 */ 1196 public RestContextBuilder messages(MessageBundleLocation...values) { 1197 return addTo(REST_messages, values); 1198 } 1199 1200 /** 1201 * Configuration property: Messages. 1202 * 1203 * <p> 1204 * Same as {@link #messages(MessageBundleLocation...)} except allows you to pass in the base class and bundle 1205 * path separately. 1206 * 1207 * <ul class='seealso'> 1208 * <li class='jf'>{@link RestContext#REST_messages} 1209 * </ul> 1210 * 1211 * @param baseClass 1212 * The base class that the bundle path is relative to. 1213 * <br>If <jk>null</jk>, assumed to be the resource class itself. 1214 * @param bundlePath The bundle path relative to the base class. 1215 * @return This object (for method chaining). 1216 */ 1217 public RestContextBuilder messages(Class<?> baseClass, String bundlePath) { 1218 return addTo(REST_messages, new MessageBundleLocation(baseClass, bundlePath)); 1219 } 1220 1221 /** 1222 * Configuration property: Messages. 1223 * 1224 * <p> 1225 * Same as {@link #messages(Class,String)} except assumes the base class is the resource class itself. 1226 * 1227 * <ul class='seealso'> 1228 * <li class='jf'>{@link RestContext#REST_messages} 1229 * </ul> 1230 * 1231 * @param bundlePath The bundle path relative to the base class. 1232 * @return This object (for method chaining). 1233 */ 1234 public RestContextBuilder messages(String bundlePath) { 1235 return addTo(REST_messages, new MessageBundleLocation(null, bundlePath)); 1236 } 1237 1238 /** 1239 * Configuration property: MIME types. 1240 * 1241 * <p> 1242 * Defines MIME-type file type mappings. 1243 * 1244 * <ul class='seealso'> 1245 * <li class='jf'>{@link RestContext#REST_mimeTypes} 1246 * </ul> 1247 * 1248 * @param values The values to add to this setting. 1249 * @return This object (for method chaining). 1250 */ 1251 public RestContextBuilder mimeTypes(String...values) { 1252 return addTo(REST_mimeTypes, values); 1253 } 1254 1255 /** 1256 * Configuration property: Java method parameter resolvers. 1257 * 1258 * <p> 1259 * By default, the Juneau framework will automatically Java method parameters of various types (e.g. 1260 * <c>RestRequest</c>, <c>Accept</c>, <c>Reader</c>). 1261 * This annotation allows you to provide your own resolvers for your own class types that you want resolved. 1262 * 1263 * <ul class='seealso'> 1264 * <li class='jf'>{@link RestContext#REST_paramResolvers} 1265 * </ul> 1266 * 1267 * @param values The values to add to this setting. 1268 * @return This object (for method chaining). 1269 */ 1270 @SuppressWarnings("unchecked") 1271 public RestContextBuilder paramResolvers(Class<? extends RestMethodParam>...values) { 1272 return addTo(REST_paramResolvers, values); 1273 } 1274 1275 /** 1276 * Configuration property: Java method parameter resolvers. 1277 * 1278 * <p> 1279 * Same as {@link #paramResolvers(Class...)} except input is pre-constructed instances. 1280 * 1281 * <ul class='seealso'> 1282 * <li class='jf'>{@link RestContext#REST_paramResolvers} 1283 * </ul> 1284 * 1285 * @param values The values to add to this setting. 1286 * @return This object (for method chaining). 1287 */ 1288 public RestContextBuilder paramResolvers(RestMethodParam...values) { 1289 return addTo(REST_paramResolvers, values); 1290 } 1291 1292 /** 1293 * Configuration property: Parser listener. 1294 * 1295 * <p> 1296 * Specifies the parser listener class to use for listening to non-fatal parsing errors. 1297 * 1298 * <ul class='seealso'> 1299 * <li class='jf'>{@link Parser#PARSER_listener} 1300 * </ul> 1301 * 1302 * @param value The new value for this setting. 1303 * @return This object (for method chaining). 1304 */ 1305 public RestContextBuilder parserListener(Class<? extends ParserListener> value) { 1306 if (value != ParserListener.Null.class) 1307 set(PARSER_listener, value); 1308 return this; 1309 } 1310 1311 /** 1312 * Configuration property: Parsers. 1313 * 1314 * <p> 1315 * Adds class-level parsers to this resource. 1316 * 1317 * <ul class='seealso'> 1318 * <li class='jf'>{@link RestContext#REST_parsers} 1319 * </ul> 1320 * 1321 * @param values The values to add to this setting. 1322 * @return This object (for method chaining). 1323 */ 1324 public RestContextBuilder parsers(Class<?>...values) { 1325 return addTo(REST_parsers, values); 1326 } 1327 1328 /** 1329 * Configuration property: Parsers. 1330 * 1331 * <p> 1332 * Same as {@link #parsers(Class...)} except input is pre-constructed instances. 1333 * 1334 * <p> 1335 * Parser instances are considered set-in-stone and do NOT inherit properties and transforms defined on the 1336 * resource class or method. 1337 * 1338 * <ul class='seealso'> 1339 * <li class='jf'>{@link RestContext#REST_parsers} 1340 * </ul> 1341 * 1342 * @param values The values to add to this setting. 1343 * @return This object (for method chaining). 1344 */ 1345 public RestContextBuilder parsers(Object...values) { 1346 return addTo(REST_parsers, values); 1347 } 1348 1349 /** 1350 * Configuration property: Parsers. 1351 * 1352 * <p> 1353 * Same as {@link #parsers(Class...)} except allows you to overwrite the previous value. 1354 * 1355 * <ul class='seealso'> 1356 * <li class='jf'>{@link RestContext#REST_parsers} 1357 * </ul> 1358 * 1359 * @param values The values to add to this setting. 1360 * @return This object (for method chaining). 1361 */ 1362 public RestContextBuilder parsersReplace(Object...values) { 1363 return set(REST_parsers, values); 1364 } 1365 1366 /** 1367 * Configuration property: HTTP part parser. 1368 * 1369 * <p> 1370 * Specifies the {@link HttpPartParser} to use for parsing headers, query/form parameters, and URI parts. 1371 * 1372 * <ul class='seealso'> 1373 * <li class='jf'>{@link RestContext#REST_partParser} 1374 * </ul> 1375 * 1376 * @param value 1377 * The new value for this setting. 1378 * <br>The default is {@link OpenApiParser}. 1379 * @return This object (for method chaining). 1380 */ 1381 public RestContextBuilder partParser(Class<? extends HttpPartParser> value) { 1382 if (value != HttpPartParser.Null.class) 1383 set(REST_partParser, value); 1384 return this; 1385 } 1386 1387 /** 1388 * Configuration property: HTTP part parser. 1389 * 1390 * <p> 1391 * Same as {@link #partParser(Class)} except input is a pre-constructed instance. 1392 * 1393 * <ul class='seealso'> 1394 * <li class='jf'>{@link RestContext#REST_partParser} 1395 * </ul> 1396 * 1397 * @param value 1398 * The new value for this setting. 1399 * <br>The default is {@link OpenApiParser}. 1400 * @return This object (for method chaining). 1401 */ 1402 public RestContextBuilder partParser(HttpPartParser value) { 1403 return set(REST_partParser, value); 1404 } 1405 1406 /** 1407 * Configuration property: HTTP part serializer. 1408 * 1409 * <p> 1410 * Specifies the {@link HttpPartSerializer} to use for serializing headers, query/form parameters, and URI parts. 1411 * 1412 * <ul class='seealso'> 1413 * <li class='jf'>{@link RestContext#REST_partSerializer} 1414 * </ul> 1415 * 1416 * @param value 1417 * The new value for this setting. 1418 * <br>The default is {@link OpenApiSerializer}. 1419 * @return This object (for method chaining). 1420 */ 1421 public RestContextBuilder partSerializer(Class<? extends HttpPartSerializer> value) { 1422 if (value != HttpPartSerializer.Null.class) 1423 set(REST_partSerializer, value); 1424 return this; 1425 } 1426 1427 /** 1428 * Configuration property: HTTP part serializer. 1429 * 1430 * <p> 1431 * Same as {@link #partSerializer(Class)} except input is a pre-constructed instance. 1432 * 1433 * <ul class='seealso'> 1434 * <li class='jf'>{@link RestContext#REST_partSerializer} 1435 * </ul> 1436 * 1437 * @param value 1438 * The new value for this setting. 1439 * <br>The default is {@link OpenApiSerializer}. 1440 * @return This object (for method chaining). 1441 */ 1442 public RestContextBuilder partSerializer(HttpPartSerializer value) { 1443 return set(REST_partSerializer, value); 1444 } 1445 1446 /** 1447 * Configuration property: Resource path. 1448 * 1449 * <p> 1450 * Identifies the URL subpath relative to the parent resource. 1451 * 1452 * <ul class='seealso'> 1453 * <li class='jf'>{@link RestContext#REST_path} 1454 * </ul> 1455 * 1456 * @param value The new value for this setting. 1457 * @return This object (for method chaining). 1458 */ 1459 public RestContextBuilder path(String value) { 1460 if (startsWith(value, '/')) 1461 value = value.substring(1); 1462 set(REST_path, value); 1463 return this; 1464 } 1465 1466 /** 1467 * Configuration property: Render response stack traces in responses. 1468 * 1469 * <p> 1470 * Render stack traces in HTTP response bodies when errors occur. 1471 * 1472 * <ul class='seealso'> 1473 * <li class='jf'>{@link RestContext#REST_renderResponseStackTraces} 1474 * </ul> 1475 * 1476 * @param value 1477 * The new value for this setting. 1478 * <br>The default is <jk>false</jk>. 1479 * @return This object (for method chaining). 1480 */ 1481 public RestContextBuilder renderResponseStackTraces(boolean value) { 1482 return set(REST_renderResponseStackTraces, value); 1483 } 1484 1485 /** 1486 * Configuration property: Render response stack traces in responses. 1487 * 1488 * <p> 1489 * Shortcut for calling <code>renderResponseStackTraces(<jk>true</jk>)</code>. 1490 * 1491 * <ul class='seealso'> 1492 * <li class='jf'>{@link RestContext#REST_renderResponseStackTraces} 1493 * </ul> 1494 * 1495 * @return This object (for method chaining). 1496 */ 1497 public RestContextBuilder renderResponseStackTraces() { 1498 return set(REST_renderResponseStackTraces, true); 1499 } 1500 1501 /** 1502 * REST resource resolver. 1503 * 1504 * <p> 1505 * The resolver used for resolving child resources. 1506 * 1507 * <p> 1508 * Can be used to provide customized resolution of REST resource class instances (e.g. resources retrieve from Spring). 1509 * 1510 * <ul class='seealso'> 1511 * <li class='jf'>{@link RestContext#REST_resourceResolver} 1512 * </ul> 1513 * 1514 * @param value 1515 * The new value for this setting. 1516 * <br>The default is {@link BasicRestResourceResolver}. 1517 * @return This object (for method chaining). 1518 */ 1519 public RestContextBuilder resourceResolver(Class<? extends RestResourceResolver> value) { 1520 return set(REST_resourceResolver, value); 1521 } 1522 1523 /** 1524 * REST resource resolver. 1525 * 1526 * <p> 1527 * Same as {@link #resourceResolver(Class)} except input is a pre-constructed instance. 1528 * 1529 * <ul class='seealso'> 1530 * <li class='jf'>{@link RestContext#REST_resourceResolver} 1531 * </ul> 1532 * 1533 * @param value 1534 * The new value for this setting. 1535 * <br>The default is {@link BasicRestResourceResolver}. 1536 * @return This object (for method chaining). 1537 */ 1538 public RestContextBuilder resourceResolver(RestResourceResolver value) { 1539 return set(REST_resourceResolver, value); 1540 } 1541 1542 /** 1543 * Configuration property: Response handlers. 1544 * 1545 * <p> 1546 * Specifies a list of {@link ResponseHandler} classes that know how to convert POJOs returned by REST methods or 1547 * set via {@link RestResponse#setOutput(Object)} into appropriate HTTP responses. 1548 * 1549 * <ul class='seealso'> 1550 * <li class='jf'>{@link RestContext#REST_responseHandlers} 1551 * </ul> 1552 * 1553 * @param values The values to add to this setting. 1554 * @return This object (for method chaining). 1555 */ 1556 public RestContextBuilder responseHandlers(Class<?>...values) { 1557 return addTo(REST_responseHandlers, values); 1558 } 1559 1560 /** 1561 * Configuration property: Response handlers. 1562 * 1563 * <p> 1564 * Same as {@link #responseHandlers(Class...)} except input is pre-constructed instances. 1565 * 1566 * <ul class='seealso'> 1567 * <li class='jf'>{@link RestContext#REST_responseHandlers} 1568 * </ul> 1569 * 1570 * @param values The values to add to this setting. 1571 * @return This object (for method chaining). 1572 */ 1573 public RestContextBuilder responseHandlers(ResponseHandler...values) { 1574 return addTo(REST_responseHandlers, values); 1575 } 1576 1577 /** 1578 * Configuration property: Declared roles. 1579 * 1580 * <p> 1581 * A comma-delimited list of all possible user roles. 1582 * 1583 * <p> 1584 * Used in conjunction with {@link RestContextBuilder#roleGuard(String)} is used with patterns. 1585 * 1586 * <h5 class='section'>Example:</h5> 1587 * <p class='bcode w800'> 1588 * <ja>@RestResource</ja>( 1589 * rolesDeclared=<js>"ROLE_ADMIN,ROLE_READ_WRITE,ROLE_READ_ONLY,ROLE_SPECIAL"</js>, 1590 * roleGuard=<js>"ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)"</js> 1591 * ) 1592 * <jk>public class</jk> MyResource <jk>extends</jk> RestServlet { 1593 * ... 1594 * } 1595 * </p> 1596 * 1597 * <ul class='seealso'> 1598 * <li class='jf'>{@link RestContext#REST_rolesDeclared} 1599 * </ul> 1600 * @param values The values to add to this setting. 1601 * @return This object (for method chaining). 1602 */ 1603 public RestContextBuilder rolesDeclared(String...values) { 1604 return addTo(REST_rolesDeclared, values); 1605 } 1606 1607 /** 1608 * Configuration property: Role guard. 1609 * 1610 * <p> 1611 * An expression defining if a user with the specified roles are allowed to access methods on this class. 1612 * 1613 * <h5 class='section'>Example:</h5> 1614 * <p class='bcode w800'> 1615 * <ja>@RestResource</ja>( 1616 * path=<js>"/foo"</js>, 1617 * roleGuard=<js>"ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)"</js> 1618 * ) 1619 * <jk>public class</jk> MyResource <jk>extends</jk> RestServlet { 1620 * ... 1621 * } 1622 * </p> 1623 * 1624 * <ul class='notes'> 1625 * <li> 1626 * Supports any of the following expression constructs: 1627 * <ul> 1628 * <li><js>"foo"</js> - Single arguments. 1629 * <li><js>"foo,bar,baz"</js> - Multiple OR'ed arguments. 1630 * <li><js>"foo | bar | bqz"</js> - Multiple OR'ed arguments, pipe syntax. 1631 * <li><js>"foo || bar || bqz"</js> - Multiple OR'ed arguments, Java-OR syntax. 1632 * <li><js>"fo*"</js> - Patterns including <js>'*'</js> and <js>'?'</js>. 1633 * <li><js>"fo* & *oo"</js> - Multiple AND'ed arguments, ampersand syntax. 1634 * <li><js>"fo* && *oo"</js> - Multiple AND'ed arguments, Java-AND syntax. 1635 * <li><js>"fo* || (*oo || bar)"</js> - Parenthesis. 1636 * </ul> 1637 * <li> 1638 * AND operations take precedence over OR operations (as expected). 1639 * <li> 1640 * Whitespace is ignored. 1641 * <li> 1642 * <jk>null</jk> or empty expressions always match as <jk>false</jk>. 1643 * <li> 1644 * If patterns are used, you must specify the list of declared roles using {@link RestResource#rolesDeclared()} or {@link RestContext#REST_rolesDeclared}. 1645 * <li> 1646 * Supports {@doc DefaultRestSvlVariables} 1647 * (e.g. <js>"$L{my.localized.variable}"</js>). 1648 * </ul> 1649 * 1650 * @param value The values to add to this setting. 1651 * @return This object (for method chaining). 1652 */ 1653 public RestContextBuilder roleGuard(String value) { 1654 return addTo(REST_roleGuard, value); 1655 } 1656 1657 /** 1658 * Configuration property: Serializer listener. 1659 * 1660 * <p> 1661 * Specifies the serializer listener class to use for listening to non-fatal serialization errors. 1662 * 1663 * <ul class='seealso'> 1664 * <li class='jf'>{@link Serializer#SERIALIZER_listener} 1665 * </ul> 1666 * 1667 * @param value The new value for this setting. 1668 * @return This object (for method chaining). 1669 */ 1670 public RestContextBuilder serializerListener(Class<? extends SerializerListener> value) { 1671 if (value != SerializerListener.Null.class) 1672 set(SERIALIZER_listener, value); 1673 return this; 1674 } 1675 1676 /** 1677 * Configuration property: Serializers. 1678 * 1679 * <p> 1680 * Adds class-level serializers to this resource. 1681 * 1682 * <ul class='seealso'> 1683 * <li class='jf'>{@link RestContext#REST_serializers} 1684 * </ul> 1685 * 1686 * @param values The values to add to this setting. 1687 * @return This object (for method chaining). 1688 */ 1689 public RestContextBuilder serializers(Class<?>...values) { 1690 return addTo(REST_serializers, values); 1691 } 1692 1693 /** 1694 * Configuration property: Serializers. 1695 * 1696 * <p> 1697 * Same as {@link #serializers(Class[])} but replaces any existing values. 1698 * 1699 * <ul class='seealso'> 1700 * <li class='jf'>{@link RestContext#REST_serializers} 1701 * </ul> 1702 * 1703 * @param values The values to set on this setting. 1704 * @return This object (for method chaining). 1705 */ 1706 public RestContextBuilder serializersReplace(Class<?>...values) { 1707 return set(REST_serializers, values); 1708 } 1709 1710 /** 1711 * Configuration property: Serializers. 1712 * 1713 * <p> 1714 * Same as {@link #serializers(Class...)} except input is pre-constructed instances. 1715 * 1716 * <p> 1717 * Serializer instances are considered set-in-stone and do NOT inherit properties and transforms defined on the 1718 * resource class or method. 1719 * 1720 * <ul class='seealso'> 1721 * <li class='jf'>{@link RestContext#REST_serializers} 1722 * </ul> 1723 * 1724 * @param values The values to add to this setting. 1725 * @return This object (for method chaining). 1726 */ 1727 public RestContextBuilder serializers(Object...values) { 1728 return addTo(REST_serializers, values); 1729 } 1730 1731 /** 1732 * Configuration property: Serializers. 1733 * 1734 * <p> 1735 * Same as {@link #serializers(Class...)} except allows you to overwrite the previous value. 1736 * 1737 * <ul class='seealso'> 1738 * <li class='jf'>{@link RestContext#REST_serializers} 1739 * </ul> 1740 * 1741 * @param values The values to add to this setting. 1742 * @return This object (for method chaining). 1743 */ 1744 public RestContextBuilder serializersReplace(Object...values) { 1745 return set(REST_serializers, values); 1746 } 1747 1748 /** 1749 * Configuration property: Static file response headers. 1750 * 1751 * <p> 1752 * Used to customize the headers on responses returned for statically-served files. 1753 * 1754 * <ul class='seealso'> 1755 * <li class='jf'>{@link RestContext#REST_staticFileResponseHeaders} 1756 * </ul> 1757 * 1758 * @param headers 1759 * The headers to add to this list. 1760 * <br>The default is <code>{<js>'Cache-Control'</js>: <js>'max-age=86400, public</js>}</code>. 1761 * @return This object (for method chaining). 1762 */ 1763 public RestContextBuilder staticFileResponseHeaders(Map<String,String> headers) { 1764 return addTo(REST_staticFileResponseHeaders, headers); 1765 } 1766 1767 /** 1768 * Configuration property: Static file response headers. 1769 * 1770 * <p> 1771 * Same as {@link #staticFileResponseHeaders(Map)} but replaces any previous values. 1772 * 1773 * <ul class='seealso'> 1774 * <li class='jf'>{@link RestContext#REST_staticFileResponseHeaders} 1775 * </ul> 1776 * 1777 * @param headers 1778 * The headers to set on this list. 1779 * <br>The default is <code>{<js>'Cache-Control'</js>: <js>'max-age=86400, public</js>}</code>. 1780 * @return This object (for method chaining). 1781 */ 1782 public RestContextBuilder staticFileResponseHeadersReplace(Map<String,String> headers) { 1783 return set(REST_staticFileResponseHeaders, headers); 1784 } 1785 1786 /** 1787 * Configuration property: Static file response headers. 1788 * 1789 * <p> 1790 * Same as {@link #staticFileResponseHeaders(Map)} with append=<jk>true</jk> except headers are strings 1791 * composed of key/value pairs. 1792 * 1793 * <ul class='seealso'> 1794 * <li class='jf'>{@link RestContext#REST_staticFileResponseHeaders} 1795 * </ul> 1796 * 1797 * @param headers The headers in the format <js>"Header-Name: header-value"</js>. 1798 * @return This object (for method chaining). 1799 * @throws RestServletException If malformed header is found. 1800 */ 1801 public RestContextBuilder staticFileResponseHeaders(String...headers) throws RestServletException { 1802 for (String header : headers) { 1803 String[] h = RestUtils.parseHeader(header); 1804 if (h == null) 1805 throw new RestServletException("Invalid static file response header specified: ''{0}''. Must be in the format: ''Header-Name: header-value''", header); 1806 staticFileResponseHeader(h[0], h[1]); 1807 } 1808 return this; 1809 } 1810 1811 /** 1812 * Configuration property: Static file response headers. 1813 * 1814 * <p> 1815 * Same as {@link #staticFileResponseHeaders(String...)} except header is broken into name/value pair. 1816 * 1817 * <ul class='seealso'> 1818 * <li class='jf'>{@link RestContext#REST_staticFileResponseHeaders} 1819 * </ul> 1820 * 1821 * @param name The HTTP header name. 1822 * @param value The HTTP header value. 1823 * @return This object (for method chaining). 1824 */ 1825 public RestContextBuilder staticFileResponseHeader(String name, String value) { 1826 return addTo(REST_staticFileResponseHeaders, name, value); 1827 } 1828 1829 /** 1830 * Configuration property: Static file mappings. 1831 * 1832 * <p> 1833 * Used to define paths and locations of statically-served files such as images or HTML documents. 1834 * 1835 * <ul class='seealso'> 1836 * <li class='jf'>{@link RestContext#REST_staticFiles} 1837 * </ul> 1838 * 1839 * @param values The values to append to this setting. 1840 * @return This object (for method chaining). 1841 */ 1842 public RestContextBuilder staticFiles(StaticFileMapping...values) { 1843 return addTo(REST_staticFiles, values); 1844 } 1845 1846 /** 1847 * Configuration property: Static file mappings. 1848 * 1849 * <p> 1850 * Same as {@link #staticFiles(StaticFileMapping...)} except input is in the form of a mapping string. 1851 * 1852 * <p> 1853 * Mapping string must be one of these formats: 1854 * <ul> 1855 * <li><js>"path:location"</js> (e.g. <js>"foodocs:docs/foo"</js>) 1856 * <li><js>"path:location:headers-json"</js> (e.g. <js>"foodocs:docs/foo:{'Cache-Control':'max-age=86400, public'}"</js>) 1857 * </ul> 1858 * 1859 * <ul class='seealso'> 1860 * <li class='jf'>{@link RestContext#REST_staticFiles} 1861 * </ul> 1862 * 1863 * @param mappingString The static file mapping string. 1864 * @return This object (for method chaining). 1865 */ 1866 public RestContextBuilder staticFiles(String mappingString) { 1867 return staticFiles(new StaticFileMapping(resourceClass, mappingString)); 1868 } 1869 1870 /** 1871 * Configuration property: Static file mappings. 1872 * 1873 * <p> 1874 * Same as {@link #staticFiles(String)} except overrides the base class for retrieving the resource. 1875 * 1876 * <p> 1877 * Mapping string must be one of these formats: 1878 * <ul> 1879 * <li><js>"path:location"</js> (e.g. <js>"foodocs:docs/foo"</js>) 1880 * <li><js>"path:location:headers-json"</js> (e.g. <js>"foodocs:docs/foo:{'Cache-Control':'max-age=86400, public'}"</js>) 1881 * </ul> 1882 * 1883 * <ul class='seealso'> 1884 * <li class='jf'>{@link RestContext#REST_staticFiles} 1885 * </ul> 1886 * 1887 * @param baseClass 1888 * Overrides the default class to use for retrieving the classpath resource. 1889 * <br>If <jk>null<jk>, uses the REST resource class. 1890 * @param mappingString The static file mapping string. 1891 * @return This object (for method chaining). 1892 */ 1893 public RestContextBuilder staticFiles(Class<?> baseClass, String mappingString) { 1894 if (isNotEmpty(mappingString)) 1895 staticFiles(new StaticFileMapping(baseClass, mappingString)); 1896 return this; 1897 } 1898 1899 /** 1900 * Configuration property: Static file mappings. 1901 * 1902 * <p> 1903 * Same as {@link #staticFiles(String)} except path and location are already split values. 1904 * 1905 * <ul class='seealso'> 1906 * <li class='jf'>{@link RestContext#REST_staticFiles} 1907 * </ul> 1908 * 1909 * @param path 1910 * The mapped URI path. 1911 * <br>Leading and trailing slashes are trimmed. 1912 * @param location 1913 * The location relative to the resource class. 1914 * <br>Leading and trailing slashes are trimmed. 1915 * @return This object (for method chaining). 1916 */ 1917 public RestContextBuilder staticFiles(String path, String location) { 1918 return staticFiles(new StaticFileMapping(null, path, location, null)); 1919 } 1920 1921 /** 1922 * Configuration property: Static file mappings. 1923 * 1924 * <p> 1925 * Same as {@link #staticFiles(String,String)} except overrides the base class for retrieving the resource. 1926 * 1927 * <ul class='seealso'> 1928 * <li class='jf'>{@link RestContext#REST_staticFiles} 1929 * </ul> 1930 * 1931 * @param baseClass 1932 * Overrides the default class to use for retrieving the classpath resource. 1933 * <br>If <jk>null<jk>, uses the REST resource class. 1934 * @param path 1935 * The mapped URI path. 1936 * <br>Leading and trailing slashes are trimmed. 1937 * @param location 1938 * The location relative to the resource class. 1939 * <br>Leading and trailing slashes are trimmed. 1940 * @return This object (for method chaining). 1941 */ 1942 public RestContextBuilder staticFiles(Class<?> baseClass, String path, String location) { 1943 return staticFiles(new StaticFileMapping(baseClass, path, location, null)); 1944 } 1945 1946 /** 1947 * Configuration property: Supported accept media types. 1948 * 1949 * <p> 1950 * Overrides the media types inferred from the serializers that identify what media types can be produced by the resource. 1951 * 1952 * <ul class='seealso'> 1953 * <li class='jf'>{@link RestContext#REST_produces} 1954 * </ul> 1955 * 1956 * @param values The values to add to this setting. 1957 * @return This object (for method chaining). 1958 */ 1959 public RestContextBuilder produces(String...values) { 1960 return addTo(REST_produces, values); 1961 } 1962 1963 /** 1964 * Configuration property: Supported accept media types. 1965 * 1966 * <p> 1967 * Same as {@link #produces(String...)} but replaces any previous values. 1968 * 1969 * <ul class='seealso'> 1970 * <li class='jf'>{@link RestContext#REST_produces} 1971 * </ul> 1972 * 1973 * @param values The values to set on this setting. 1974 * @return This object (for method chaining). 1975 */ 1976 public RestContextBuilder producesReplace(String...values) { 1977 return set(REST_produces, values); 1978 } 1979 1980 /** 1981 * Configuration property: Supported accept media types. 1982 * 1983 * <p> 1984 * Same as {@link #produces(String...)} except input is {@link MediaType} instances. 1985 * 1986 * <ul class='seealso'> 1987 * <li class='jf'>{@link RestContext#REST_produces} 1988 * </ul> 1989 * 1990 * @param values The values to add to this setting. 1991 * @return This object (for method chaining). 1992 */ 1993 public RestContextBuilder produces(MediaType...values) { 1994 return addTo(REST_produces, values); 1995 } 1996 1997 /** 1998 * Configuration property: Supported accept media types. 1999 * 2000 * <p> 2001 * Same as {@link #produces(MediaType...)} but replaces any previous values. 2002 * 2003 * <ul class='seealso'> 2004 * <li class='jf'>{@link RestContext#REST_produces} 2005 * </ul> 2006 * 2007 * @param values The values to set on this setting. 2008 * @return This object (for method chaining). 2009 */ 2010 public RestContextBuilder producesReplace(MediaType...values) { 2011 return set(REST_produces, values); 2012 } 2013 2014 /** 2015 * Configuration property: Supported content media types. 2016 * 2017 * <p> 2018 * Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource. 2019 * 2020 * <ul class='seealso'> 2021 * <li class='jf'>{@link RestContext#REST_consumes} 2022 * </ul> 2023 * 2024 * @param values The values to add to this setting. 2025 * @return This object (for method chaining). 2026 */ 2027 public RestContextBuilder consumes(String...values) { 2028 return addTo(REST_consumes, values); 2029 } 2030 2031 /** 2032 * Configuration property: Supported content media types. 2033 * 2034 * <p> 2035 * Same as {@link #consumes(String...)} but replaces any existing values. 2036 * 2037 * <ul class='seealso'> 2038 * <li class='jf'>{@link RestContext#REST_consumes} 2039 * </ul> 2040 * 2041 * @param values The values to set on this setting. 2042 * @return This object (for method chaining). 2043 */ 2044 public RestContextBuilder consumesReplace(String...values) { 2045 return set(REST_consumes, values); 2046 } 2047 2048 /** 2049 * Configuration property: Supported content media types. 2050 * 2051 * <p> 2052 * Same as {@link #consumes(String...)} except input is {@link MediaType} instances. 2053 * 2054 * <ul class='seealso'> 2055 * <li class='jf'>{@link RestContext#REST_consumes} 2056 * </ul> 2057 * 2058 * @param values The values to add to this setting. 2059 * @return This object (for method chaining). 2060 */ 2061 public RestContextBuilder consumes(MediaType...values) { 2062 return addTo(REST_consumes, values); 2063 } 2064 2065 /** 2066 * Configuration property: Supported content media types. 2067 * 2068 * <p> 2069 * Same as {@link #consumes(MediaType...)} except replaces any existing values. 2070 * 2071 * <ul class='seealso'> 2072 * <li class='jf'>{@link RestContext#REST_consumes} 2073 * </ul> 2074 * 2075 * @param values The values to set on this setting. 2076 * @return This object (for method chaining). 2077 */ 2078 public RestContextBuilder consumesReplace(MediaType...values) { 2079 return set(REST_consumes, values); 2080 } 2081 2082 /** 2083 * Configuration property: Properties. 2084 * 2085 * <p> 2086 * Shortcut to add properties to the bean contexts of all serializers and parsers on all methods in the class. 2087 * 2088 * <p> 2089 * Any of the properties defined on {@link RestContext} or any of the serializers and parsers can be specified. 2090 * 2091 * <p> 2092 * Property values will be converted to the appropriate type. 2093 * 2094 * <ul class='seealso'> 2095 * <li class='jm'>{@link RestContext#REST_properties} 2096 * </ul> 2097 * 2098 * @param values The values to set on this setting. 2099 * @return This object (for method chaining). 2100 */ 2101 public RestContextBuilder properties(Map<String,Object> values) { 2102 return addTo(REST_properties, values); 2103 } 2104 2105 /** 2106 * Configuration property: Properties. 2107 * 2108 * <p> 2109 * Shortcut to add properties to the bean contexts of all serializers and parsers on all methods in the class. 2110 * 2111 * <p> 2112 * Any of the properties defined on {@link RestContext} or any of the serializers and parsers can be specified. 2113 * 2114 * <p> 2115 * Property values will be converted to the appropriate type. 2116 * 2117 * <ul class='seealso'> 2118 * <li class='jm'>{@link RestContext#REST_properties} 2119 * </ul> 2120 * 2121 * @param name The key to add to the properties. 2122 * @param value The value to add to the properties. 2123 * @return This object (for method chaining). 2124 */ 2125 public RestContextBuilder property(String name, Object value) { 2126 return addTo(REST_properties, name, value); 2127 } 2128 2129 /** 2130 * Configuration property: Resource authority path. 2131 * 2132 * <p> 2133 * Overrides the authority path value for this resource and any child resources. 2134 * 2135 * <p> 2136 * This setting is useful if you want to resolve relative URIs to absolute paths and want to explicitly specify the hostname/port. 2137 * 2138 * <ul class='seealso'> 2139 * <li class='jf'>{@link RestContext#REST_uriAuthority} 2140 * </ul> 2141 * 2142 * @param value The new value for this setting. 2143 * @return This object (for method chaining). 2144 */ 2145 public RestContextBuilder uriAuthority(String value) { 2146 if (! value.isEmpty()) 2147 set(REST_uriAuthority, value); 2148 return this; 2149 } 2150 2151 /** 2152 * Configuration property: Resource context path. 2153 * 2154 * <p> 2155 * Overrides the context path value for this resource and any child resources. 2156 * 2157 * <p> 2158 * This setting is useful if you want to use <js>"context:/child/path"</js> URLs in child resource POJOs but 2159 * the context path is not actually specified on the servlet container. 2160 * 2161 * <ul class='seealso'> 2162 * <li class='jf'>{@link RestContext#REST_uriContext} 2163 * </ul> 2164 * 2165 * @param value The new value for this setting. 2166 * @return This object (for method chaining). 2167 */ 2168 public RestContextBuilder uriContext(String value) { 2169 if (! value.isEmpty()) 2170 set(REST_uriContext, value); 2171 return this; 2172 } 2173 2174 /** 2175 * Configuration property: URI resolution relativity. 2176 * 2177 * <p> 2178 * Specifies how relative URIs should be interpreted by serializers. 2179 * 2180 * <p> 2181 * See {@link UriResolution} for possible values. 2182 * 2183 * <ul class='seealso'> 2184 * <li class='jf'>{@link RestContext#REST_uriRelativity} 2185 * </ul> 2186 * 2187 * @param value The new value for this setting. 2188 * @return This object (for method chaining). 2189 */ 2190 public RestContextBuilder uriRelativity(String value) { 2191 if (! value.isEmpty()) 2192 set(REST_uriRelativity, value); 2193 return this; 2194 } 2195 2196 /** 2197 * Configuration property: URI resolution. 2198 * 2199 * <p> 2200 * Specifies how relative URIs should be interpreted by serializers. 2201 * 2202 * <p> 2203 * See {@link UriResolution} for possible values. 2204 * 2205 * <ul class='seealso'> 2206 * <li class='jf'>{@link RestContext#REST_uriResolution} 2207 * </ul> 2208 * 2209 * @param value The new value for this setting. 2210 * @return This object (for method chaining). 2211 */ 2212 public RestContextBuilder uriResolution(String value) { 2213 if (! value.isEmpty()) 2214 set(REST_uriResolution, value); 2215 return this; 2216 } 2217 2218 /** 2219 * Configuration property: Use classpath resource caching. 2220 * 2221 * <p> 2222 * When enabled, resources retrieved via {@link RestContext#getClasspathResource(String, Locale)} (and related 2223 * methods) will be cached in memory to speed subsequent lookups. 2224 * 2225 * <ul class='seealso'> 2226 * <li class='jf'>{@link RestContext#REST_useClasspathResourceCaching} 2227 * </ul> 2228 * 2229 * @param value 2230 * The new value for this setting. 2231 * <br>The default is <jk>true</jk>. 2232 * @return This object (for method chaining). 2233 */ 2234 public RestContextBuilder useClasspathResourceCaching(boolean value) { 2235 return set(REST_useClasspathResourceCaching, value); 2236 } 2237 2238 /** 2239 * Configuration property: Use stack trace hashes. 2240 * 2241 * <p> 2242 * When enabled, the number of times an exception has occurred will be determined based on stack trace hashsums, 2243 * made available through the {@link RestException#getOccurrence()} method. 2244 * 2245 * <ul class='seealso'> 2246 * <li class='jf'>{@link RestContext#REST_useStackTraceHashes} 2247 * </ul> 2248 * 2249 * @param value 2250 * The new value for this setting. 2251 * <br>The default is <jk>true</jk>. 2252 * @return This object (for method chaining). 2253 * @deprecated Use {@link #callLoggerConfig(RestCallLoggerConfig)} 2254 */ 2255 @Deprecated 2256 public RestContextBuilder useStackTraceHashes(boolean value) { 2257 return set(REST_useStackTraceHashes, value); 2258 } 2259 2260 /** 2261 * Configuration property: HTML Widgets. 2262 * 2263 * <p> 2264 * Defines widgets that can be used in conjunction with string variables of the form <js>"$W{name}"</js>to quickly 2265 * generate arbitrary replacement text. 2266 * 2267 * <ul class='seealso'> 2268 * <li class='jf'>{@link RestContext#REST_widgets} 2269 * </ul> 2270 * 2271 * @param values The values to add to this setting. 2272 * @return This object (for method chaining). 2273 * 2274 * @deprecated Use {@link HtmlDocSerializerBuilder#widgets(Class[])} 2275 */ 2276 @SuppressWarnings("unchecked") 2277 @Deprecated 2278 public RestContextBuilder widgets(Class<? extends Widget>...values) { 2279 return addTo(REST_widgets, values); 2280 } 2281 2282 /** 2283 * Configuration property: HTML Widgets. 2284 * 2285 * <p> 2286 * Same as {@link #widgets(Class...)} but replaces any previous values. 2287 * 2288 * <ul class='seealso'> 2289 * <li class='jf'>{@link RestContext#REST_widgets} 2290 * </ul> 2291 * 2292 * @param values The values to set on this setting. 2293 * @return This object (for method chaining). 2294 * 2295 * @deprecated Use {@link HtmlDocSerializerBuilder#widgetsReplace(Class[])} 2296 */ 2297 @SuppressWarnings("unchecked") 2298 @Deprecated 2299 public RestContextBuilder widgetsReplace(Class<? extends Widget>...values) { 2300 return set(REST_widgets, values); 2301 } 2302 2303 /** 2304 * Configuration property: HTML Widgets. 2305 * 2306 * <p> 2307 * Same as {@link #widgets(Class...)} except input is pre-constructed instances. 2308 * 2309 * <ul class='seealso'> 2310 * <li class='jf'>{@link RestContext#REST_widgets} 2311 * </ul> 2312 * 2313 * @param values The values to add to this setting. 2314 * @return This object (for method chaining). 2315 * 2316 * @deprecated Use {@link HtmlDocSerializerBuilder#widgets(HtmlWidget[])} 2317 */ 2318 @Deprecated 2319 public RestContextBuilder widgets(Widget...values) { 2320 return addTo(REST_widgets, values); 2321 } 2322 2323 /** 2324 * Configuration property: HTML Widgets. 2325 * 2326 * <p> 2327 * Same as {@link #widgets(Widget...)} except allows you to overwrite the previous value. 2328 * 2329 * <ul class='seealso'> 2330 * <li class='jf'>{@link RestContext#REST_widgets} 2331 * </ul> 2332 * 2333 * @param values The values to add to this setting. 2334 * @return This object (for method chaining). 2335 * 2336 * @deprecated Use {@link HtmlDocSerializerBuilder#widgetsReplace(HtmlWidget[])} 2337 */ 2338 @Deprecated 2339 public RestContextBuilder widgetsReplace(Widget...values) { 2340 return set(REST_widgets, values); 2341 } 2342 2343 @Override /* BeanContextBuilder */ 2344 public RestContextBuilder beanClassVisibility(Visibility value) { 2345 super.beanClassVisibility(value); 2346 return this; 2347 } 2348 2349 @Override /* BeanContextBuilder */ 2350 public RestContextBuilder beanConstructorVisibility(Visibility value) { 2351 super.beanConstructorVisibility(value); 2352 return this; 2353 } 2354 2355 @Override /* BeanContextBuilder */ 2356 public RestContextBuilder beanDictionary(Class<?>...values) { 2357 super.beanDictionary(values); 2358 return this; 2359 } 2360 2361 @Override /* BeanContextBuilder */ 2362 public RestContextBuilder beanDictionary(Object...values) { 2363 super.beanDictionary(values); 2364 return this; 2365 } 2366 2367 @Override /* BeanContextBuilder */ 2368 public RestContextBuilder beanDictionaryReplace(Class<?>...values) { 2369 super.beanDictionaryReplace(values); 2370 return this; 2371 } 2372 2373 @Override /* BeanContextBuilder */ 2374 public RestContextBuilder beanDictionaryReplace(Object...values) { 2375 super.beanDictionaryReplace(values); 2376 return this; 2377 } 2378 2379 @Override /* BeanContextBuilder */ 2380 public RestContextBuilder beanDictionaryRemove(Class<?>...values) { 2381 super.beanDictionaryRemove(values); 2382 return this; 2383 } 2384 2385 @Override /* BeanContextBuilder */ 2386 public RestContextBuilder beanDictionaryRemove(Object...values) { 2387 super.beanDictionaryRemove(values); 2388 return this; 2389 } 2390 2391 @Override /* BeanContextBuilder */ 2392 public RestContextBuilder beanFieldVisibility(Visibility value) { 2393 super.beanFieldVisibility(value); 2394 return this; 2395 } 2396 2397 @Override /* BeanContextBuilder */ 2398 public RestContextBuilder beanFilters(Class<?>...values) { 2399 super.beanFilters(values); 2400 return this; 2401 } 2402 2403 @Override /* BeanContextBuilder */ 2404 public RestContextBuilder beanFilters(Object...values) { 2405 super.beanFilters(values); 2406 return this; 2407 } 2408 2409 @Override /* BeanContextBuilder */ 2410 public RestContextBuilder beanFiltersReplace(Class<?>...values) { 2411 super.beanFiltersReplace(values); 2412 return this; 2413 } 2414 2415 @Override /* BeanContextBuilder */ 2416 public RestContextBuilder beanFiltersReplace(Object...values) { 2417 super.beanFiltersReplace(values); 2418 return this; 2419 } 2420 2421 @Override /* BeanContextBuilder */ 2422 public RestContextBuilder beanFiltersRemove(Class<?>...values) { 2423 super.beanFiltersRemove(values); 2424 return this; 2425 } 2426 2427 @Override /* BeanContextBuilder */ 2428 public RestContextBuilder beanFiltersRemove(Object...values) { 2429 super.beanFiltersRemove(values); 2430 return this; 2431 } 2432 2433 @Override /* BeanContextBuilder */ 2434 public RestContextBuilder beanMapPutReturnsOldValue(boolean value) { 2435 super.beanMapPutReturnsOldValue(value); 2436 return this; 2437 } 2438 2439 @Override /* BeanContextBuilder */ 2440 public RestContextBuilder beanMapPutReturnsOldValue() { 2441 super.beanMapPutReturnsOldValue(); 2442 return this; 2443 } 2444 2445 @Override /* BeanContextBuilder */ 2446 public RestContextBuilder beanMethodVisibility(Visibility value) { 2447 super.beanMethodVisibility(value); 2448 return this; 2449 } 2450 2451 @Override /* BeanContextBuilder */ 2452 public RestContextBuilder beansRequireDefaultConstructor(boolean value) { 2453 super.beansRequireDefaultConstructor(value); 2454 return this; 2455 } 2456 2457 @Override /* BeanContextBuilder */ 2458 public RestContextBuilder beansRequireDefaultConstructor() { 2459 super.beansRequireDefaultConstructor(); 2460 return this; 2461 } 2462 2463 @Override /* BeanContextBuilder */ 2464 public RestContextBuilder beansRequireSerializable(boolean value) { 2465 super.beansRequireSerializable(value); 2466 return this; 2467 } 2468 2469 @Override /* BeanContextBuilder */ 2470 public RestContextBuilder beansRequireSerializable() { 2471 super.beansRequireSerializable(); 2472 return this; 2473 } 2474 2475 @Override /* BeanContextBuilder */ 2476 public RestContextBuilder beansRequireSettersForGetters(boolean value) { 2477 super.beansRequireSettersForGetters(value); 2478 return this; 2479 } 2480 2481 @Override /* BeanContextBuilder */ 2482 public RestContextBuilder beansRequireSettersForGetters() { 2483 super.beansRequireSettersForGetters(); 2484 return this; 2485 } 2486 2487 @Override /* BeanContextBuilder */ 2488 public RestContextBuilder beansRequireSomeProperties(boolean value) { 2489 super.beansRequireSomeProperties(value); 2490 return this; 2491 } 2492 2493 @Override /* BeanContextBuilder */ 2494 public RestContextBuilder beanTypePropertyName(String value) { 2495 super.beanTypePropertyName(value); 2496 return this; 2497 } 2498 2499 @Override /* BeanContextBuilder */ 2500 public RestContextBuilder debug() { 2501 debug(Enablement.TRUE); 2502 super.debug(); 2503 return this; 2504 } 2505 2506 @Override /* BeanContextBuilder */ 2507 public <T> RestContextBuilder example(Class<T> c, T o) { 2508 super.example(c, o); 2509 return this; 2510 } 2511 2512 @Override /* BeanContextBuilder */ 2513 public <T> RestContextBuilder exampleJson(Class<T> c, String value) { 2514 super.exampleJson(c, value); 2515 return this; 2516 } 2517 2518 @Override /* BeanContextBuilder */ 2519 public RestContextBuilder ignoreInvocationExceptionsOnGetters(boolean value) { 2520 super.ignoreInvocationExceptionsOnGetters(value); 2521 return this; 2522 } 2523 2524 @Override /* BeanContextBuilder */ 2525 public RestContextBuilder ignoreInvocationExceptionsOnGetters() { 2526 super.ignoreInvocationExceptionsOnGetters(); 2527 return this; 2528 } 2529 2530 @Override /* BeanContextBuilder */ 2531 public RestContextBuilder ignoreInvocationExceptionsOnSetters(boolean value) { 2532 super.ignoreInvocationExceptionsOnSetters(value); 2533 return this; 2534 } 2535 2536 @Override /* BeanContextBuilder */ 2537 public RestContextBuilder ignoreInvocationExceptionsOnSetters() { 2538 super.ignoreInvocationExceptionsOnSetters(); 2539 return this; 2540 } 2541 2542 @Override /* BeanContextBuilder */ 2543 public RestContextBuilder ignorePropertiesWithoutSetters(boolean value) { 2544 super.ignorePropertiesWithoutSetters(value); 2545 return this; 2546 } 2547 2548 @Override /* BeanContextBuilder */ 2549 public RestContextBuilder ignoreUnknownBeanProperties(boolean value) { 2550 super.ignoreUnknownBeanProperties(value); 2551 return this; 2552 } 2553 2554 @Override /* BeanContextBuilder */ 2555 public RestContextBuilder ignoreUnknownBeanProperties() { 2556 super.ignoreUnknownBeanProperties(); 2557 return this; 2558 } 2559 2560 @Override /* BeanContextBuilder */ 2561 public RestContextBuilder ignoreUnknownNullBeanProperties(boolean value) { 2562 super.ignoreUnknownNullBeanProperties(value); 2563 return this; 2564 } 2565 2566 @Override /* BeanContextBuilder */ 2567 public RestContextBuilder implClass(Class<?> interfaceClass, Class<?> implClass) { 2568 super.implClass(interfaceClass, implClass); 2569 return this; 2570 } 2571 2572 @Override /* BeanContextBuilder */ 2573 public RestContextBuilder implClasses(Map<String,Class<?>> values) { 2574 super.implClasses(values); 2575 return this; 2576 } 2577 2578 @Override /* BeanContextBuilder */ 2579 public RestContextBuilder locale(Locale value) { 2580 super.locale(value); 2581 return this; 2582 } 2583 2584 @Override /* BeanContextBuilder */ 2585 public RestContextBuilder mediaType(MediaType value) { 2586 super.mediaType(value); 2587 return this; 2588 } 2589 2590 @Override /* BeanContextBuilder */ 2591 public RestContextBuilder notBeanClasses(Class<?>...values) { 2592 super.notBeanClasses(values); 2593 return this; 2594 } 2595 2596 @Override /* BeanContextBuilder */ 2597 public RestContextBuilder notBeanClasses(Object...values) { 2598 super.notBeanClasses(values); 2599 return this; 2600 } 2601 2602 @Override /* BeanContextBuilder */ 2603 public RestContextBuilder notBeanClassesReplace(Class<?>...values) { 2604 super.notBeanClassesReplace(values); 2605 return this; 2606 } 2607 2608 @Override /* BeanContextBuilder */ 2609 public RestContextBuilder notBeanClassesReplace(Object...values) { 2610 super.notBeanClassesReplace(values); 2611 return this; 2612 } 2613 2614 @Override /* BeanContextBuilder */ 2615 public RestContextBuilder notBeanClassesRemove(Class<?>...values) { 2616 super.notBeanClassesRemove(values); 2617 return this; 2618 } 2619 2620 @Override /* BeanContextBuilder */ 2621 public RestContextBuilder notBeanClassesRemove(Object...values) { 2622 super.notBeanClassesRemove(values); 2623 return this; 2624 } 2625 2626 @Override /* BeanContextBuilder */ 2627 public RestContextBuilder notBeanPackages(Object...values) { 2628 super.notBeanPackages(values); 2629 return this; 2630 } 2631 2632 @Override /* BeanContextBuilder */ 2633 public RestContextBuilder notBeanPackages(String...values) { 2634 super.notBeanPackages(values); 2635 return this; 2636 } 2637 2638 @Override /* BeanContextBuilder */ 2639 public RestContextBuilder notBeanPackagesReplace(String...values) { 2640 super.notBeanPackagesReplace(values); 2641 return this; 2642 } 2643 2644 @Override /* BeanContextBuilder */ 2645 public RestContextBuilder notBeanPackagesReplace(Object...values) { 2646 super.notBeanPackagesReplace(values); 2647 return this; 2648 } 2649 2650 @Override /* BeanContextBuilder */ 2651 public RestContextBuilder notBeanPackagesRemove(String...values) { 2652 super.notBeanPackagesRemove(values); 2653 return this; 2654 } 2655 2656 @Override /* BeanContextBuilder */ 2657 public RestContextBuilder notBeanPackagesRemove(Object...values) { 2658 super.notBeanPackagesRemove(values); 2659 return this; 2660 } 2661 2662 @Override /* BeanContextBuilder */ 2663 public RestContextBuilder pojoSwaps(Class<?>...values) { 2664 super.pojoSwaps(values); 2665 return this; 2666 } 2667 2668 @Override /* BeanContextBuilder */ 2669 public RestContextBuilder pojoSwaps(Object...values) { 2670 super.pojoSwaps(values); 2671 return this; 2672 } 2673 2674 @Override /* BeanContextBuilder */ 2675 public RestContextBuilder pojoSwapsReplace(Class<?>...values) { 2676 super.pojoSwapsReplace(values); 2677 return this; 2678 } 2679 2680 @Override /* BeanContextBuilder */ 2681 public RestContextBuilder pojoSwapsReplace(Object...values) { 2682 super.pojoSwapsReplace(values); 2683 return this; 2684 } 2685 2686 @Override /* BeanContextBuilder */ 2687 public RestContextBuilder pojoSwapsRemove(Class<?>...values) { 2688 super.pojoSwapsRemove(values); 2689 return this; 2690 } 2691 2692 @Override /* BeanContextBuilder */ 2693 public RestContextBuilder pojoSwapsRemove(Object...values) { 2694 super.pojoSwapsRemove(values); 2695 return this; 2696 } 2697 2698 @Override /* BeanContextBuilder */ 2699 public RestContextBuilder sortProperties(boolean value) { 2700 super.sortProperties(value); 2701 return this; 2702 } 2703 2704 @Override /* BeanContextBuilder */ 2705 public RestContextBuilder sortProperties() { 2706 super.sortProperties(); 2707 return this; 2708 } 2709 2710 @Override /* BeanContextBuilder */ 2711 public RestContextBuilder timeZone(TimeZone value) { 2712 super.timeZone(value); 2713 return this; 2714 } 2715 2716 @Override /* BeanContextBuilder */ 2717 public RestContextBuilder useEnumNames(boolean value) { 2718 super.useEnumNames(value); 2719 return this; 2720 } 2721 2722 @Override /* BeanContextBuilder */ 2723 public RestContextBuilder useEnumNames() { 2724 super.useEnumNames(); 2725 return this; 2726 } 2727 2728 @Override /* BeanContextBuilder */ 2729 public RestContextBuilder useInterfaceProxies(boolean value) { 2730 super.useInterfaceProxies(value); 2731 return this; 2732 } 2733 2734 @Override /* BeanContextBuilder */ 2735 public RestContextBuilder useJavaBeanIntrospector(boolean value) { 2736 super.useJavaBeanIntrospector(value); 2737 return this; 2738 } 2739 2740 @Override /* BeanContextBuilder */ 2741 public RestContextBuilder useJavaBeanIntrospector() { 2742 super.useJavaBeanIntrospector(); 2743 return this; 2744 } 2745 2746 @Override /* ContextBuilder */ 2747 public RestContextBuilder set(String name, Object value) { 2748 super.set(name, value); 2749 this.properties.put(name, value); 2750 addTo(REST_properties, name, value); 2751 return this; 2752 } 2753 2754 @Override /* ContextBuilder */ 2755 public RestContextBuilder set(Map<String,Object> properties) { 2756 super.set(properties); 2757 this.properties.clear(); 2758 this.properties.putAll(properties); 2759 addTo(REST_properties, properties); 2760 return this; 2761 } 2762 2763 @Override /* ContextBuilder */ 2764 public RestContextBuilder add(Map<String,Object> properties) { 2765 super.add(properties); 2766 return this; 2767 } 2768 2769 @Override /* ContextBuilder */ 2770 public RestContextBuilder addTo(String name, Object value) { 2771 super.addTo(name, value); 2772 return this; 2773 } 2774 2775 @Override /* ContextBuilder */ 2776 public RestContextBuilder addTo(String name, String key, Object value) { 2777 super.addTo(name, key, value); 2778 return this; 2779 } 2780 2781 @Override /* ContextBuilder */ 2782 public RestContextBuilder removeFrom(String name, Object value) { 2783 super.removeFrom(name, value); 2784 return this; 2785 } 2786 2787 @Override /* ContextBuilder */ 2788 public RestContextBuilder apply(PropertyStore copyFrom) { 2789 super.apply(copyFrom); 2790 return this; 2791 } 2792 2793 @Override /* ContextBuilder */ 2794 public RestContextBuilder applyAnnotations(AnnotationList al, VarResolverSession vrs) { 2795 super.applyAnnotations(al, vrs); 2796 return this; 2797 } 2798 2799 @Override /* ContextBuilder */ 2800 public RestContextBuilder applyAnnotations(Class<?> fromClass) { 2801 super.applyAnnotations(fromClass); 2802 return this; 2803 } 2804 2805 @Override /* ContextBuilder */ 2806 public RestContextBuilder applyAnnotations(java.lang.reflect.Method fromMethod) { 2807 super.applyAnnotations(fromMethod); 2808 return this; 2809 } 2810 2811 //---------------------------------------------------------------------------------------------------- 2812 // Methods inherited from ServletConfig 2813 //---------------------------------------------------------------------------------------------------- 2814 2815 @Override /* ServletConfig */ 2816 public String getInitParameter(String name) { 2817 return inner.getInitParameter(name); 2818 } 2819 2820 @Override /* ServletConfig */ 2821 public Enumeration<String> getInitParameterNames() { 2822 return inner.getInitParameterNames(); 2823 } 2824 2825 @Override /* ServletConfig */ 2826 public ServletContext getServletContext() { 2827 return inner.getServletContext(); 2828 } 2829 2830 @Override /* ServletConfig */ 2831 public String getServletName() { 2832 return inner.getServletName(); 2833 } 2834}