001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.server; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023 024import org.apache.juneau.commons.*; 025import org.apache.juneau.config.*; 026import org.apache.juneau.http.*; 027import org.apache.juneau.marshall.*; 028import org.apache.juneau.marshall.encoders.*; 029import org.apache.juneau.marshall.httppart.*; 030import org.apache.juneau.marshall.parser.*; 031import org.apache.juneau.marshall.serializer.*; 032import org.apache.juneau.rest.server.arg.*; 033import org.apache.juneau.rest.server.auth.*; 034import org.apache.juneau.rest.server.converter.*; 035import org.apache.juneau.rest.server.guard.*; 036import org.apache.juneau.rest.server.openapi.*; 037import org.apache.juneau.rest.server.processor.*; 038import org.apache.juneau.rest.server.servlet.*; 039import org.apache.juneau.rest.server.staticfile.*; 040import org.apache.juneau.rest.server.swagger.*; 041 042/** 043 * Used to denote that a class is a REST resource and to associate metadata on it. 044 * 045 * <p> 046 * Usually used on a subclass of {@link RestServlet}, but can be used to annotate any class that you want to expose as 047 * a REST resource. 048 * 049 * <h5 class='section'>Default response format (content negotiation):</h5> 050 * <p> 051 * The response format is <b>not</b> hardwired to JSON. The serializer used to render a response body is chosen by 052 * ordinary HTTP content negotiation — the request's <c>Accept</c> header is best-matched against the media types 053 * of the configured {@link #serializers() serializers} (see {@link Serializer#getMediaTypeRanges()}). A request that 054 * sends no <c>Accept</c> header (or a non-specific one such as <c>*/*</c>, which browsers send by default) is 055 * treated as <c>*/*</c> and matches the <b>first</b> serializer in the set. 056 * 057 * <p> 058 * In the default configuration ({@link BasicRestServlet} / {@link BasicRestResource}, via 059 * {@link org.apache.juneau.rest.server.config.BasicUniversalConfig}) the serializer set lists HTML first, so a browser 060 * — or any client that omits <c>Accept</c> — receives <b>HTML</b>, not JSON. To always get JSON, send an 061 * explicit <c>Accept: application/json</c> header. See {@link #serializers()} for how serializer ordering determines 062 * this default. 063 * 064 * <h5 class='section'>See Also:</h5><ul> 065 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestAnnotatedClasses">@Rest-Annotated Class</a> 066 067 * </ul> 068 */ 069@Target(TYPE) 070@Retention(RUNTIME) 071@Inherited 072@AnnotationGroup(Rest.class) 073public @interface Rest { 074 075 /** 076 * Allowed header URL parameters. 077 * 078 * <p> 079 * When specified, allows headers such as <js>"Accept"</js> and <js>"Content-Type"</js> to be passed in as URL query 080 * parameters. 081 * <br> 082 * For example: 083 * <p class='burlenc'> 084 * ?Accept=text/json&Content-Type=text/json 085 * </p> 086 * 087 * <h5 class='section'>Notes:</h5><ul> 088 * <li class='note'> 089 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 090 * (e.g. <js>"$L{my.localized.variable}"</js>). 091 * <li class='note'> 092 * Use <js>"*"</js> to represent all methods. 093 * <li class='note'> 094 * Use <js>"NONE"</js> (case insensitive) to suppress inheriting a value from a parent class. 095 * </ul> 096 * 097 * @return The annotation value. 098 */ 099 String allowedHeaderParams() default ""; 100 101 /** 102 * Allowed method headers. 103 * 104 * <p> 105 * A comma-delimited list of HTTP method names that are allowed to be passed as values in an <c>X-Method</c>, 106 * <c>X-HTTP-Method-Override</c>, <c>X-HTTP-Method</c> or <c>X-Method-Override</c> HTTP header to override the real HTTP 107 * method name. All four headers share this list; when more than one is sent they are tried in that order. 108 * <p> 109 * Allows you to override the actual HTTP method with a simulated method. 110 * <br>For example, if an HTTP Client API doesn't support <c>PATCH</c> but does support <c>POST</c> (because 111 * <c>PATCH</c> is not part of the original HTTP spec), you can add a <c>X-Method: PATCH</c> header on a normal 112 * <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. 113 * 114 * <h5 class='section'>Notes:</h5><ul> 115 * <li class='note'> 116 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 117 * (e.g. <js>"$L{my.localized.variable}"</js>). 118 * <li class='note'> 119 * Method names are case-insensitive. 120 * <li class='note'> 121 * Use <js>"*"</js> to represent all methods. 122 * <li class='note'> 123 * Use <js>"NONE"</js> (case insensitive) to suppress inheriting a value from a parent class. 124 * <li class='note'> 125 * Once the list admits at least one method, override claims must agree: a request whose override headers (or 126 * <c>method</c> query parameter) name more than one distinct method is refused with <c>400</c>, whether or not the 127 * list admits them. 128 * <li class='note'> 129 * On a safe request (<c>GET</c>, <c>HEAD</c>, <c>OPTIONS</c>, <c>TRACE</c>), an override is honored only when it names 130 * another safe method or an operation declared {@link RestOp#read() read=true}; anything else is refused with 131 * <c>405</c>. Overrides on a <c>POST</c> are unaffected. 132 * </ul> 133 * 134 * @return The annotation value. 135 */ 136 String allowedMethodHeaders() default ""; 137 138 /** 139 * Allowed method parameters. 140 * 141 * <p> 142 * When specified, the HTTP method can be overridden by passing in a <js>"method"</js> URL parameter. 143 * <br> 144 * For example: 145 * <p class='burlenc'> 146 * ?method=OPTIONS 147 * </p> 148 * <p> 149 * On a safe request (<c>GET</c>, <c>HEAD</c>, <c>OPTIONS</c>, <c>TRACE</c>), which is what a link or a typed URL sends, 150 * the parameter may only name another safe method or a custom method whose operation is declared 151 * {@link RestOp#read() read=true}. Anything else, for example <c>GET /foo?method=DELETE</c>, is refused with 152 * <c>405 Method Not Allowed</c>, so a link can never trigger a write. On a <c>POST</c>, the parameter may name any 153 * method in this list. 154 * 155 * <h5 class='section'>Notes:</h5><ul> 156 * <li class='note'> 157 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 158 * (e.g. <js>"$L{my.localized.variable}"</js>). 159 * <li class='note'> 160 * Use <js>"*"</js> to represent all methods. 161 * <li class='note'> 162 * Use <js>"NONE"</js> (case insensitive) to suppress inheriting a value from a parent class. 163 * </ul> 164 * 165 * @return The annotation value. 166 */ 167 String allowedMethodParams() default ""; 168 169 /** 170 * Resource-level authenticator. 171 * 172 * <p> 173 * Resolves the {@link java.security.Principal} and roles for requests to this resource and its descendant child 174 * resources (inherited unless cut off via {@code noInherit={"authenticator"}}), so that {@code roleGuard} / 175 * {@link RoleBasedRestGuard} / {@link Auth @Auth} 176 * / {@code isUserInRole} resolve against the computed identity. 177 * 178 * <h5 class='section'>Notes:</h5><ul> 179 * <li class='note'> 180 * The implementation is instantiated through the resource's bean store (constructor injection). 181 * <li class='note'> 182 * The default {@link org.apache.juneau.rest.server.auth.RestAuthenticator.Null RestAuthenticator.Null} sentinel means "not specified." 183 * </ul> 184 * 185 * <h5 class='section'>See Also:</h5><ul> 186 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerAuthenticator">REST Authenticator — Resource-Level Authentication</a> 187 * </ul> 188 * 189 * @return The annotation value. 190 * @since 10.0.0 191 */ 192 Class<? extends RestAuthenticator> authenticator() default RestAuthenticator.Null.class; 193 194 /** 195 * REST children. 196 * 197 * <p> 198 * Defines children of this resource. Each child resource is mounted under its own URL subtree (per the 199 * child's own {@code @Rest(path=...)} / {@code @Rest(paths=...)}) and constructs its own {@link RestContext}. 200 * 201 * <h5 class='section'>Children vs. mixins (resolution semantics)</h5> 202 * <p> 203 * Children are <b>isolated from the parent's resolution chain</b> by design — a child's serializers, parsers, 204 * guards, hooks, etc. are all resolved against the child's own {@link RestContext} only, NOT walked 205 * through the parent. This is the opposite of how {@link #mixins() mixins} resolve. See the 206 * <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerMixinSubContexts#mixin-vs-child-divergence">Mixin-vs-child divergence</a> 207 * topic for the rationale (children own their lifecycle and are externally mounted; mixins are inline composers 208 * sharing the host's URL namespace and resolution chain). 209 * 210 * <h5 class='section'>Inheritance Rules</h5> 211 * <ul> 212 * <li>Children on child are combined with those on parent class. 213 * <li>Children are list parent-to-child in the order they appear in the annotation. 214 * </ul> 215 * 216 * <h5 class='section'>See Also:</h5><ul> 217 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ChildResources">Child Resources</a> 218 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerMixinSubContexts">REST Server — Mixin Sub-Contexts</a> (for the mixin-vs-child divergence) 219 * </ul> 220 * 221 * @return The annotation value. 222 */ 223 Class<?>[] children() default {}; 224 225 /** 226 * Rich child definitions — the host-side seed form of {@link #children()}. 227 * 228 * <p> 229 * Each {@link Child @Child} entry names a child class (via {@link Child#type()}) <b>and</b> lets the host 230 * seed a curated set of {@code @Rest}-level settings onto that child's otherwise-isolated 231 * {@link RestContext} — guards, role guards, part serializer/parser, and a 232 * handful of default-scalar settings — without editing the child class. 233 * 234 * <p> 235 * Unlike {@link #mixinDefs() mixinDefs}, this does not override an inherited chain (children never inherit 236 * from the host); it seeds settings onto an isolated context. Additive-security seed members ({@code guards}, 237 * {@code converters}, {@code roleGuard}, {@code rolesDeclared}) can't be removed or weakened by the child; 238 * the remaining scalar seed members are a fallback the child's own explicit {@code @Rest} declaration wins 239 * over. See {@link Child} for the full semantics. 240 * 241 * <h5 class='section'>Example:</h5> 242 * <p class='bjava'> 243 * <ja>@Rest</ja>( 244 * childrenDefs=<ja>@Child</ja>(type=FooChild.<jk>class</jk>, maxInput=<js>"10M"</js>) 245 * ) 246 * <jk>public class</jk> MyResource { ... } 247 * </p> 248 * 249 * <p> 250 * This attribute is additive to {@link #children()}: bare-class entries in {@code children()} and rich 251 * entries here are discovered together (bare classes first, then {@code childrenDefs}). A 252 * {@code @Child(type=X.class)} with no seed members is the exact equivalent of a bare 253 * {@code children=X.class} entry. 254 * 255 * <h5 class='section'>See Also:</h5><ul> 256 * <li class='ja'>{@link Child} 257 * <li class='jm'>{@link #children()} 258 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ChildResources#host-side-seeding-with-child-1000">Host-side seeding with @Child (10.0.0)</a> 259 * </ul> 260 * 261 * @return The annotation value. 262 * @since 10.0.0 263 */ 264 Child[] childrenDefs() default {}; 265 266 /** 267 * REST mixins. 268 * 269 * <p> 270 * Defines operation-provider classes whose {@link RestOp @RestOp}-group methods should be composed into this 271 * resource. 272 * 273 * <p> 274 * Mixin methods are discovered the same way as local operation methods and surface under this resource's URL 275 * namespace. On path/method collisions, local methods on this resource win over mixin methods. 276 * 277 * <h5 class='section'>Per-mixin RestContext + host-to-mixin inheritance (since 10.0.0)</h5> 278 * <p> 279 * Each mixin class is elevated to its own {@link RestContext} parent-linked to this host's {@link RestContext}. 280 * The mixin's class-level {@code @Rest(...)} configuration applies to its own endpoints, with inheritance from 281 * the host: 282 * <ul> 283 * <li><b>List-shaped properties</b> ({@code serializers}, {@code parsers}, {@code encoders}, {@code converters}, 284 * {@code responseProcessors}, {@code restOpArgs}, {@code guards}) — host's chain runs first, then the mixin's 285 * appended. Host endpoints see only the host's chain. 286 * <li><b>Replace-shaped properties</b> ({@code partSerializer}, {@code partParser}) — the mixin's value wins 287 * over the host's for mixin endpoints when declared; otherwise the host's value is inherited. 288 * <li><b>{@code messages}</b> — the mixin's bundle is chained as a child of the host's via 289 * {@link org.apache.juneau.marshall.cp.Messages#chain Messages.chain(child, parent)} so mixin keys win and missing 290 * keys fall through to the host. 291 * <li><b>Lifecycle hooks</b> ({@code @RestStartCall}, {@code @RestEndCall}, {@code @RestPreCall}, 292 * {@code @RestPostCall}, {@code @RestDestroy}) — dual-fire host-then-mixin for mixin-endpoint requests; 293 * host-only for host-endpoint requests. 294 * </ul> 295 * 296 * <p> 297 * Use {@link #noInherit() @Rest(noInherit={...})} on a mixin class to cut off inheritance for a specific 298 * property — same token set as the host's {@code noInherit} machinery (e.g. {@code "serializers"}, 299 * {@code "guards"}, {@code "messages"}). 300 * 301 * <h5 class='section'>Mixins vs. children</h5> 302 * <p> 303 * Mixins are inline composers that share the host's URL namespace and inherit from the host's resolution chain. 304 * {@link #children() Children} are independently-mounted resources isolated from the host's resolution chain. 305 * See the 306 * <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerMixinSubContexts#mixin-vs-child-divergence">Mixin-vs-child divergence</a> 307 * topic for the rationale. 308 * 309 * <h5 class='section'>Inheritance Rules</h5> 310 * <ul> 311 * <li>Mixins on child are combined with those on parent class. 312 * <li>Mixins are listed parent-to-child in the order they appear in the annotation. 313 * <li>Transitive mixins ({@code A} mixes in {@code B}) parent-link flat to the host — both {@code A} and 314 * {@code B} get {@code parentContext = host}, never an {@code A → B} chain. 315 * </ul> 316 * 317 * <p> 318 * For host-side per-mixin setting overrides (applying guards / serializers / a mount path / etc. to a 319 * specific mixin's endpoints without editing the mixin class), see the rich {@link #mixinDefs() mixinDefs} 320 * companion attribute. 321 * 322 * <h5 class='section'>See Also:</h5><ul> 323 * <li class='jma'>{@link #mixinDefs()} 324 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a> 325 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerMixinSubContexts">REST Server — Mixin Sub-Contexts</a> 326 * </ul> 327 * 328 * @return The annotation value. 329 */ 330 Class<?>[] mixins() default {}; 331 332 /** 333 * Rich mixin definitions — the host-side override form of {@link #mixins()}. 334 * 335 * <p> 336 * Each {@link Mixin @Mixin} entry names a mixin class (via {@link Mixin#type()}) <b>and</b> lets the host 337 * override selected {@code @Rest}-level settings for that mixin's mixed-in endpoints — guards, role 338 * guards, serializers, default headers, mount path, etc. — without subclassing or editing the mixin 339 * class. 340 * 341 * <h5 class='section'>Example:</h5> 342 * <p class='bjava'> 343 * <ja>@Rest</ja>( 344 * mixinDefs=<ja>@Mixin</ja>(type=FooMixin.<jk>class</jk>, guards=AdminGuard.<jk>class</jk>) 345 * ) 346 * <jk>public class</jk> MyResource { ... } 347 * </p> 348 * 349 * <p> 350 * This attribute is additive to {@link #mixins()}: bare-class entries in {@code mixins()} and rich entries 351 * here are discovered together (bare classes first, then {@code mixinDefs}). A {@code @Mixin(type=X.class)} 352 * with no overrides is the exact equivalent of a bare {@code mixins=X.class} entry. 353 * 354 * <h5 class='section'>See Also:</h5><ul> 355 * <li class='ja'>{@link Mixin} 356 * <li class='jm'>{@link #mixins()} 357 * </ul> 358 * 359 * @return The annotation value. 360 * @since 10.0.0 361 */ 362 Mixin[] mixinDefs() default {}; 363 364 /** 365 * Mixin-declared opt-in: fold this class's own {@link #responseProcessors() responseProcessors} into the 366 * <b>host</b> resource's chain whenever this class is composed as a mixin via a plain 367 * {@link #mixins() @Rest(mixins=...)} reference. 368 * 369 * <p> 370 * By default ({@code false}) a mixin's {@code responseProcessors} apply only to the mixin's own endpoints 371 * — a host's own {@code @RestOp} methods see only the host's chain (the standard {@link #mixins() mixin} 372 * inheritance rule "host's chain runs first, then the mixin's appended; host endpoints see only the host's 373 * chain"). Setting this to {@code true} <b>on the mixin class itself</b> makes a plain 374 * {@code @Rest(mixins=ThisClass.class)} reference additionally append this class's own 375 * {@code responseProcessors} to the end of the host's own chain, so the host's own endpoints pick them up too. 376 * 377 * <p> 378 * This is the mixin-declared, response-processor-scoped counterpart to 379 * {@link Mixin#mergeIntoHost() @Mixin(mergeIntoHost=true)} (which is host-declared and folds <i>all</i> 380 * list-shaped attributes). Unlike {@code mergeIntoHost}, this directive lives with the mixin and folds 381 * <b>only</b> {@code responseProcessors} — never {@code guards}, {@code serializers}, or any other 382 * list-shaped attribute. It is intended for view-renderer mixins (e.g. {@code FreemarkerMixin}) so that 383 * declaring the mixin is enough to route the host's own {@code View} returns through the renderer. 384 * 385 * <p> 386 * Strictly opt-in and non-silent: it has no effect for a mixin that leaves it {@code false}, so existing 387 * mixins keep today's scoping exactly. Same-class de-duplication applies, so a response processor the host 388 * already declares is not added twice. 389 * 390 * @return The annotation value. 391 * @since 10.0.0 392 */ 393 boolean mergeResponseProcessorsIntoHost() default false; 394 395 /** 396 * Client version header. 397 * 398 * <p> 399 * Specifies the name of the header used to denote the client version on HTTP requests. 400 * 401 * <h5 class='section'>Notes:</h5><ul> 402 * <li class='note'> 403 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 404 * (e.g. <js>"$L{my.localized.variable}"</js>). 405 * </ul> 406 * 407 * @return The annotation value. 408 */ 409 String clientVersionHeader() default ""; 410 411 /** 412 * Optional location of configuration file for this servlet. 413 * 414 * <p> 415 * The configuration file . 416 * 417 * <h5 class='section'>Inheritance Rules</h5> 418 * <ul> 419 * <li>Config file is searched for in child-to-parent order. 420 * </ul> 421 * 422 * <h5 class='section'>Notes:</h5><ul> 423 * <li class='note'> 424 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 425 * (e.g. <js>"$L{my.localized.variable}"</js>). 426 * <li class='note'> 427 * Use the keyword <c>SYSTEM_DEFAULT</c> to refer to the system default configuration 428 * returned by the {@link Config#getSystemDefault()}. 429 * </ul> 430 * 431 * @return The annotation value. 432 */ 433 String config() default ""; 434 435 /** 436 * Eagerly initializes framework-managed memoizers during {@link RestContext} construction. 437 * 438 * <p> 439 * When enabled, framework bean memoizers and operation/child-context memoizers are force-fired inside the 440 * constructor try/catch so startup-time configuration errors fail fast. 441 * 442 * <p> 443 * This setting is disabled by default. 444 * 445 * <ul class='values'> 446 * <li><js>"true"</js> - Force eager initialization during context construction. 447 * <li><js>"false"</js> - Keep initialization lazy until first use (default). 448 * </ul> 449 * 450 * <h5 class='section'>Notes:</h5><ul> 451 * <li class='note'> 452 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 453 * (e.g. <js>"$L{my.localized.variable}"</js>). 454 * </ul> 455 * 456 * @return The annotation value. 457 */ 458 String eagerInit() default ""; 459 460 /** 461 * Opt this parent resource into deferred (first-invocation) construction of its {@link #children()} sub-resources. 462 * 463 * <p> 464 * When {@code "true"}, the {@link RestContext} instances for all {@code @Rest(children=...)} entries are 465 * <em>not</em> built at parent startup. Instead, each child's routing entry is registered immediately (so URL 466 * matching is fully operational from the first request), but the full {@link RestContext} — including all of its 467 * bean-store setup, memoizers, and lifecycle hooks — is constructed on the first inbound request to that child's 468 * URL prefix. Subsequent requests reuse the already-built context. 469 * 470 * <p> 471 * This is particularly useful when a parent resource exposes heavyweight admin or diagnostic children that are 472 * rarely invoked in production. Setting {@code lazyChildren="true"} on the parent lets the parent boot fast; 473 * each child pays its construction cost only when (and if) it is first accessed. 474 * 475 * <ul class='values'> 476 * <li><js>"true"</js> - Children are constructed on first invocation (deferred). 477 * <li><js>"false"</js> (default) - Children are constructed eagerly at parent startup. 478 * </ul> 479 * 480 * <h5 class='section'>Notes:</h5><ul> 481 * <li class='note'> 482 * The first request to a lazy child pays the full construction cost, which can be significant for 483 * heavyweight children. If predictable first-request latency is required, do not opt in. 484 * <li class='note'> 485 * Concurrent first-requests to the same lazy child are serialized: only one thread runs the construction; 486 * others block until it completes. 487 * <li class='note'> 488 * A lazy child that is never invoked is never constructed. Its lifecycle {@code @RestDestroy} / shutdown 489 * hooks are skipped at parent destruction time. 490 * <li class='note'> 491 * The programmatic knob {@link RestContext.Builder#lazyChildInit(boolean)} overrides this annotation. 492 * <li class='note'> 493 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 494 * (e.g. <js>"$E{LAZY_CHILDREN,false}"</js>). 495 * </ul> 496 * 497 * <h5 class='section'>See Also:</h5><ul> 498 * <li class='jm'>{@link RestContext.Builder#lazyChildInit(boolean)} 499 * <li class='jm'>{@link #children()} 500 * </ul> 501 * 502 * @return The annotation value. 503 */ 504 String lazyChildren() default ""; 505 506 /** 507 * Supported content media types. 508 * 509 * <p> 510 * Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource. 511 * 512 * <h5 class='section'>Notes:</h5><ul> 513 * <li class='note'> 514 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 515 * (e.g. <js>"$L{my.localized.variable}"</js>). 516 * </ul> 517 * 518 * @return The annotation value. 519 */ 520 String[] consumes() default {}; 521 522 /** 523 * Allowed serializer session option keys for this resource (ordered merge, prefix {@code -key} removes a key). 524 * 525 * <p> 526 * Comma-delimited list of session property keys (e.g. <js>"escapeSolidus,maxIndent"</js>) that clients may 527 * send via the <js>"X-Juneau-Serializer-Options"</js> header or <js>"juneauSerializerOptions"</js> query parameter. 528 * Keys not in the effective allowlist cause a {@code 400 Bad Request} response. 529 * 530 * <p> 531 * Entries are merged in application order. A leading hyphen removes a previously added key: <js>"-escapeSolidus"</js>. 532 * Method-level {@link RestGet#allowedSerializerOptions()} values are always merged on top. 533 * Use {@link #noInherit()} to prevent inheriting less-derived contributions. 534 * 535 * <h5 class='section'>See Also:</h5><ul> 536 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SessionOptions#safe-properties">Safe Properties</a> 537 * </ul> 538 * 539 * @return The annotation value. 540 */ 541 String[] allowedSerializerOptions() default {}; 542 543 /** 544 * Allowed parser session option keys for this resource (ordered merge, prefix {@code -key} removes a key). 545 * 546 * <p> 547 * Comma-delimited list of session property keys that clients may send via the <js>"X-Juneau-Parser-Options"</js> 548 * header or <js>"juneauParserOptions"</js> query parameter. Parser options are ignored for operations without 549 * a request-body parser. Keys not in the effective allowlist cause a {@code 400 Bad Request} response. 550 * 551 * <p> 552 * Use {@link #noInherit()} to prevent inheriting less-derived contributions. 553 * 554 * <h5 class='section'>See Also:</h5><ul> 555 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SessionOptions#safe-properties">Safe Properties</a> 556 * </ul> 557 * 558 * @return The annotation value. 559 */ 560 String[] allowedParserOptions() default {}; 561 562 /** 563 * Property names for which less-derived contributions are NOT inherited. 564 * 565 * <p> 566 * Accepted values include {@code "allowedParserOptions"}, {@code "allowedSerializerOptions"}, 567 * {@code "allowedHeaderParams"}, {@code "allowedMethodHeaders"}, {@code "allowedMethodParams"}, 568 * {@code "disableContentParam"}, {@code "renderResponseStackTraces"}, {@code "problemDetails"}, 569 * {@code "debugMarshalling"}, 570 * {@code "eagerInit"}, {@code "lazyChildren"}, {@code "clientVersionHeader"}, 571 * {@code "uriAuthority"}, {@code "uriContext"}, {@code "uriRelativity"}, and {@code "uriResolution"}. 572 * Each entry is SVL-resolved then comma-split. Prevents the named property from inheriting values from 573 * parent {@code @Rest} annotations (router hierarchy). The {@code noInherit} attribute itself is never inherited. 574 * 575 * <h5 class='section'>Mixin sub-contexts (since 10.0.0)</h5> 576 * <p> 577 * On a class declared via {@link #mixins() @Rest(mixins=...)} on a host, {@code noInherit} also blocks the 578 * host-to-mixin inheritance walk for the named property. The token set extends to every contribution list 579 * exposed by {@code @Rest}: {@code "serializers"}, {@code "parsers"}, {@code "encoders"}, {@code "converters"}, 580 * {@code "responseProcessors"}, {@code "restOpArgs"}, {@code "guards"}, 581 * {@code "partSerializer"}, {@code "partParser"}, and 582 * {@code "messages"}. For example, {@code @Rest(noInherit={"guards"})} on a mixin removes the host's guard 583 * chain from the mixin's endpoints (typical pattern for deliberately-unguarded probes like 584 * {@code HealthMixin}). 585 * 586 * <h5 class='section'>See Also:</h5><ul> 587 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SessionOptions">Session Options via HTTP</a> 588 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerMixinSubContexts">REST Server — Mixin Sub-Contexts</a> (for the per-property opt-out semantics) 589 * </ul> 590 * 591 * @return The annotation value. 592 */ 593 String[] noInherit() default {}; 594 595 /** 596 * Class-level response converters. 597 * 598 * <p> 599 * Associates one or more {@link RestConverter converters} with a resource class. 600 * 601 * <h5 class='section'>Inheritance Rules</h5> 602 * <ul> 603 * <li>Converters on child are combined with those on parent class. 604 * <li>Converters are executed child-to-parent in the order they appear in the annotation. 605 * <li>Converters on methods are executed before those on classes. 606 * </ul> 607 * 608 * @return The annotation value. 609 */ 610 Class<? extends RestConverter>[] converters() default {}; 611 612 /** 613 * Default <c>Accept</c> header. 614 * 615 * <p> 616 * The default value for the <c>Accept</c> header if not specified on a request. 617 * 618 * <p> 619 * This is a shortcut for using {@link #defaultRequestHeaders()} for just this specific header. 620 * 621 * <h5 class='section'>Notes:</h5><ul> 622 * <li class='note'> 623 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 624 * (e.g. <js>"$L{my.localized.variable}"</js>). 625 * </ul> 626 * 627 * @return The annotation value. 628 */ 629 String defaultAccept() default ""; 630 631 /** 632 * Default character encoding. 633 * 634 * <p> 635 * The default character encoding for the request and response if not specified on the request. 636 * 637 * <h5 class='section'>Notes:</h5><ul> 638 * <li class='note'> 639 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 640 * (e.g. <js>"$L{my.localized.variable}"</js>). 641 * </ul> 642 * 643 * <h5 class='section'>See Also:</h5><ul> 644 * <li class='ja'>{@link RestOp#defaultCharset} 645 * <li class='ja'>{@link RestGet#defaultCharset} 646 * <li class='ja'>{@link RestPut#defaultCharset} 647 * <li class='ja'>{@link RestPost#defaultCharset} 648 * <li class='ja'>{@link RestDelete#defaultCharset} 649 * </ul> 650 * 651 * @return The annotation value. 652 */ 653 String defaultCharset() default ""; 654 655 /** 656 * Default <c>Content-Type</c> header. 657 * 658 * <p> 659 * The default value for the <c>Content-Type</c> header if not specified on a request. 660 * 661 * <p> 662 * This is a shortcut for using {@link #defaultRequestHeaders()} for just this specific header. 663 * 664 * <h5 class='section'>Notes:</h5><ul> 665 * <li class='note'> 666 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 667 * (e.g. <js>"$L{my.localized.variable}"</js>). 668 * </ul> 669 * 670 * @return The annotation value. 671 */ 672 String defaultContentType() default ""; 673 674 /** 675 * Default request attributes. 676 * 677 * <p> 678 * Specifies default values for request attributes if they're not already set on the request. 679 * 680 * <p> 681 * Affects values returned by the following methods: 682 * <ul> 683 * <li class='jm'>{@link RestRequest#getAttribute(String)}. 684 * <li class='jm'>{@link RestRequest#getAttributes()}. 685 * </ul> 686 * 687 * <h5 class='section'>Example:</h5> 688 * <p class='bjava'> 689 * <jc>// Defined via annotation resolving to a config file setting with default value.</jc> 690 * <ja>@Rest</ja>(defaultRequestAttributes={<js>"Foo=bar"</js>, <js>"Baz: $C{REST/myAttributeValue}"</js>}) 691 * <jk>public class</jk> MyResource { 692 * 693 * <jc>// Override at the method level.</jc> 694 * <ja>@RestGet</ja>(defaultRequestAttributes={<js>"Foo: bar"</js>}) 695 * <jk>public</jk> Object myMethod() {...} 696 * } 697 * </p> 698 * 699 * <h5 class='section'>Notes:</h5><ul> 700 * <li class='note'> 701 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 702 * (e.g. <js>"$L{my.localized.variable}"</js>). 703 * </ul> 704 * 705 * <h5 class='section'>See Also:</h5><ul> 706 * <li class='ja'>{@link RestOp#defaultRequestAttributes()} 707 * <li class='ja'>{@link RestGet#defaultRequestAttributes()} 708 * <li class='ja'>{@link RestPut#defaultRequestAttributes()} 709 * <li class='ja'>{@link RestPost#defaultRequestAttributes()} 710 * <li class='ja'>{@link RestDelete#defaultRequestAttributes()} 711 * </ul> 712 * 713 * @return The annotation value. 714 */ 715 String[] defaultRequestAttributes() default {}; 716 717 /** 718 * Default request headers. 719 * 720 * <p> 721 * Specifies default values for request headers if they're not passed in through the request. 722 * 723 * <h5 class='section'>Notes:</h5><ul> 724 * <li class='note'> 725 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 726 * (e.g. <js>"$L{my.localized.variable}"</js>). 727 * </ul> 728 * 729 * @return The annotation value. 730 */ 731 String[] defaultRequestHeaders() default {}; 732 733 /** 734 * Default response headers. 735 * 736 * <p> 737 * Specifies default values for response headers if they're not set after the Java REST method is called. 738 * 739 * <h5 class='section'>Notes:</h5><ul> 740 * <li class='note'> 741 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 742 * (e.g. <js>"$L{my.localized.variable}"</js>). 743 * </ul> 744 * 745 * @return The annotation value. 746 */ 747 String[] defaultResponseHeaders() default {}; 748 749 /** 750 * Optional servlet description. 751 * 752 * <p> 753 * It is used to populate the Swagger description field. 754 * 755 * <h5 class='section'>Inheritance Rules</h5> 756 * <ul> 757 * <li>Description is searched for in child-to-parent order. 758 * </ul> 759 * 760 * <h5 class='section'>Notes:</h5><ul> 761 * <li class='note'> 762 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 763 * (e.g. <js>"$L{my.localized.variable}"</js>). 764 * <li class='note'> 765 * The format is plain-text. 766 * <br>Multiple lines are concatenated with newlines. 767 * </ul> 768 * 769 * @return The annotation value. 770 */ 771 String[] description() default {}; 772 773 /** 774 * Disable content URL parameter. 775 * 776 * <p> 777 * When enabled (the default — this attribute is <jk>false</jk> unless explicitly set), the HTTP request 778 * content on PUT and POST requests can be passed in as text using the <js>"content"</js> URL parameter, letting 779 * a caller exercise an endpoint's body-consuming logic straight from a URL (handy for a quick manual test or a 780 * bookmarked link) without an actual PUT/POST body. 781 * <br> 782 * For example: 783 * <p class='burlenc'> 784 * ?content=(name='John%20Smith',age=45) 785 * </p> 786 * 787 * <p> 788 * Because the override is on by default, treat it the same way as any other feature that lets untrusted URL 789 * content reach parsing/business logic: a link to a PUT/POST endpoint with a crafted <js>"content"</js> 790 * parameter is just as reproducible by a third party (e.g. embedded in a page that an authenticated user 791 * happens to load) as the equivalent real request body would be. The override is deliberately restricted to 792 * <c>PUT</c>/<c>POST</c> methods so that a simple cross-origin <c>GET</c> (the kind a browser issues with no 793 * preflight and no caller-controlled header for something as ordinary as an <code><img src=...></code> 794 * tag) can never trigger it this way, but resources that don't already validate that PUT/POST submissions are 795 * same-site in origin (e.g. with a token check, a custom-header check, or <c>SameSite</c> cookies) gain no 796 * additional protection here. Set this to <jk>true</jk> to disable the override entirely on any resource 797 * where it isn't a deliberate feature. 798 * 799 * <h5 class='section'>Notes:</h5><ul> 800 * <li class='note'> 801 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 802 * (e.g. <js>"$L{my.localized.variable}"</js>). 803 * </ul> 804 * 805 * @return The annotation value. 806 */ 807 String disableContentParam() default ""; 808 809 /** 810 * Opt the resource into <a class="doclink" href="https://www.rfc-editor.org/rfc/rfc7807">RFC 7807</a> / 811 * <a class="doclink" href="https://www.rfc-editor.org/rfc/rfc9457">RFC 9457</a> 812 * {@code application/problem+json} error responses. 813 * 814 * <p> 815 * When enabled, the resource: 816 * <ul class='spaced-list'> 817 * <li>Emits {@code application/problem+json} for thrown {@code BasicHttpException}s — regardless of the 818 * client's {@code Accept} header. The body is a serialized 819 * {@link org.apache.juneau.bean.rfc7807.Problem} populated from the exception's status code, reason phrase, 820 * and message. 821 * <li>Honors the client's {@code Accept} header on the success path. When a {@code @RestOp} method returns a 822 * {@link org.apache.juneau.bean.rfc7807.Problem} (or throws a 823 * {@link org.apache.juneau.bean.rfc7807.ProblemException}), the 824 * {@link ProblemDetailsProcessor} only serializes it as 825 * {@code application/problem+json} when the {@code Accept} header matches that media type (or {@code */*}). 826 * </ul> 827 * 828 * <ul class='values'> 829 * <li><js>"true"</js> — enable problem-details responses for this resource. 830 * <li><js>"false"</js> — disable problem-details responses for this resource (overrides an inherited 831 * {@code "true"} from a parent {@code @Rest}). 832 * <li><js>""</js> (default) — inherit from the next-most-derived {@code @Rest} in the resource-class 833 * hierarchy. Default behavior (no opt-in anywhere in the chain) is unchanged from prior releases. 834 * </ul> 835 * 836 * <h5 class='section'>Notes:</h5><ul> 837 * <li class='note'> 838 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 839 * (e.g. <js>"$L{my.localized.variable}"</js>). 840 * <li class='note'> 841 * Use {@link #noInherit()} to prevent inheriting an opt-in from a parent {@code @Rest}. 842 * </ul> 843 * 844 * <h5 class='section'>See Also:</h5><ul> 845 * <li class='jc'>{@link org.apache.juneau.bean.rfc7807.Problem} 846 * <li class='jc'>{@link org.apache.juneau.bean.rfc7807.ProblemException} 847 * <li class='jc'>{@link ProblemDetailsProcessor} 848 * </ul> 849 * 850 * @return The annotation value. 851 */ 852 String problemDetails() default ""; 853 854 /** 855 * Opt the resource into REST-driven serializer/parser debug behavior. 856 * 857 * <p> 858 * When enabled, the REST layer forces {@code Context.debug} on the serializer/parser sessions it creates to handle 859 * requests for this resource — engaging recursion-detection-that-throws (a genuine cycle throws 860 * {@code MarshallingRecursionException} instead of being size-guard-truncated), parse-input buffering (parse errors 861 * can quote the offending input), and stack-trace-prefixed marshalling exceptions. 862 * 863 * <p> 864 * This is a <b>behavior</b> switch, independent of the JUL logger level: raising a logger to 865 * {@link java.util.logging.Level#FINE FINE}/{@link java.util.logging.Level#FINEST FINEST} changes logging verbosity 866 * only and never changes marshalling behavior. A serializer/parser configured with {@code Context.debug} directly 867 * is unaffected by this setting. 868 * 869 * <ul class='values'> 870 * <li><js>"true"</js> — enable marshalling debug for this resource. 871 * <li><js>"false"</js> — disable marshalling debug for this resource (overrides an inherited 872 * {@code "true"} from a parent {@code @Rest}). 873 * <li><js>""</js> (default) — inherit from the next-most-derived {@code @Rest} in the resource-class 874 * hierarchy. Default behavior (no opt-in anywhere in the chain) is marshalling debug OFF. 875 * </ul> 876 * 877 * <h5 class='section'>Notes:</h5><ul> 878 * <li class='note'> 879 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 880 * (e.g. <js>"$L{my.localized.variable}"</js>). 881 * <li class='note'> 882 * Use {@link #noInherit()} to prevent inheriting an opt-in from a parent {@code @Rest}. 883 * </ul> 884 * 885 * @return The annotation value. 886 */ 887 String debugMarshalling() default ""; 888 889 /** 890 * Opt this resource into per-request virtual-thread dispatch (Java 21+). 891 * 892 * <p> 893 * When enabled, every {@code @RestOp}-annotated handler invocation on this resource is submitted to a 894 * {@code Executors.newVirtualThreadPerTaskExecutor()} virtual-thread-per-task executor 895 * lazily built by the {@link RestContext}. The platform request thread blocks on 896 * the virtual thread's completion (so the handler's return value, exceptions, and observability hooks are 897 * preserved verbatim), but blocking I/O inside the handler now parks a virtual thread instead of the 898 * carrier — i.e. the carrier thread is freed to service other concurrent requests while the handler is 899 * parked on socket / file / lock waits. Combined with {@link java.util.concurrent.CompletableFuture} 900 * return types ({@code @RestGet} / {@code @RestPost} returning {@code CompletableFuture<T>}) this is the 901 * high-throughput pattern. 902 * 903 * <p> 904 * <b>Graceful degradation on Java 17/18/19/20:</b> the flag is detected during {@code RestContext} 905 * initialization. If the runtime is older than Java 21, a one-shot {@code WARNING} is logged and the 906 * resource falls back to the standard caller-thread dispatch path — no runtime error. 907 * 908 * <p> 909 * Per-{@code @RestOp} overrides are available via {@link RestOp#virtualThreads()}; the op-level setting 910 * takes precedence over the resource-level setting. 911 * 912 * <ul class='values'> 913 * <li><js>"true"</js> — enable virtual-thread dispatch on Java 21+ (silently disabled on older JVMs). 914 * <li><js>"false"</js> — explicitly disable. 915 * <li><js>""</js> (default) — inherit from the next-most-derived {@code @Rest} in the resource-class 916 * hierarchy. 917 * </ul> 918 * 919 * <h5 class='section'>Notes:</h5><ul> 920 * <li class='note'> 921 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 922 * (e.g. <js>"$E{ENABLE_VIRTUAL_THREADS,false}"</js>). 923 * <li class='note'> 924 * Synchronized blocks and JNI calls in handler code <i>pin</i> a virtual thread to its carrier thread 925 * — prefer {@link java.util.concurrent.locks.ReentrantLock} over {@code synchronized} in handlers run 926 * under this flag. 927 * </ul> 928 * 929 * <h5 class='section'>See Also:</h5><ul> 930 * <li class='ja'>{@link RestOp#virtualThreads()} 931 * </ul> 932 * 933 * @return The annotation value. 934 */ 935 String virtualThreads() default ""; 936 937 /** 938 * Per-resource observability opt-in / opt-out control. 939 * 940 * <p> 941 * Controls whether the observability block ({@link org.apache.juneau.rest.server.metrics.MetricsRecorder} / 942 * {@link org.apache.juneau.rest.server.tracing.TracerHook}) fires for operations on this resource. 943 * Per-operation overrides are available via {@link RestOp#observability()} (and the verb annotations). 944 * 945 * <ul class='values'> 946 * <li><js>"true"</js> — strict opt-in: the resource <em>requires</em> a wired observability backend. 947 * If neither a {@code @Bean MetricsRecorder} nor a {@code @Bean TracerHook} is registered when the 948 * {@link RestContext} is built, construction fails with a precise error. 949 * All operations on this resource have observability enabled. 950 * <li><js>"false"</js> — explicit opt-out: the observability block is short-circuited for every 951 * operation on this resource, even when a wired backend is present. Also suppresses 952 * {@link org.apache.juneau.rest.server.tracing.TraceContextResponseProcessor} header injection for this resource. 953 * <li><js>""</js> (default) — inherits the existing behavior: the observability block runs per-op, 954 * but a missing {@code @Bean} silently falls back to the NoOp singleton — no startup error. 955 * </ul> 956 * 957 * <h5 class='section'>Notes:</h5><ul> 958 * <li class='note'> 959 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 960 * (e.g. <js>"$E{ENABLE_OBSERVABILITY,false}"</js>). 961 * <li class='note'> 962 * Per-operation overrides via {@link RestOp#observability()} (or verb annotations) take precedence over 963 * this resource-level setting. 964 * </ul> 965 * 966 * <h5 class='section'>See Also:</h5><ul> 967 * <li class='ja'>{@link RestOp#observability()} 968 * <li class='jc'>{@link org.apache.juneau.rest.server.metrics.MetricsRecorder} 969 * <li class='jc'>{@link org.apache.juneau.rest.server.tracing.TracerHook} 970 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerObservability">Observability — Micrometer + OpenTelemetry</a> 971 * </ul> 972 * 973 * @return The annotation value. 974 * @since 10.0.0 975 */ 976 String observability() default ""; 977 978 /** 979 * Configurable timeout (milliseconds) applied to {@link java.util.concurrent.CompletableFuture}-returning 980 * handlers by {@link AsyncResponseProcessor}. Default is 30,000 ms. 981 * 982 * <p> 983 * On timeout, the future is cancelled with {@code mayInterruptIfRunning=true} and the response is 984 * committed as {@code 504 Gateway Timeout}. Set to {@code "0"} to disable the timeout entirely. 985 * 986 * <p> 987 * Per-{@code @RestOp} overrides are available via {@link RestOp#asyncTimeoutMillis()}; the op-level 988 * setting takes precedence over the resource-level setting. 989 * 990 * <h5 class='section'>Notes:</h5><ul> 991 * <li class='note'> 992 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 993 * (e.g. <js>"$E{ASYNC_TIMEOUT_MS,30000}"</js>). 994 * </ul> 995 * 996 * <h5 class='section'>See Also:</h5><ul> 997 * <li class='jc'>{@link AsyncResponseProcessor} 998 * <li class='ja'>{@link RestOp#asyncTimeoutMillis()} 999 * </ul> 1000 * 1001 * @return The annotation value. 1002 * @since 10.0.0 1003 */ 1004 String asyncTimeoutMillis() default ""; 1005 1006 /** 1007 * Names the {@link java.util.concurrent.Executor} bean used to route {@link java.util.concurrent.CompletableFuture} 1008 * completion callbacks through a dedicated thread pool. 1009 * 1010 * <p> 1011 * When set, the {@link AsyncResponseProcessor} switches from 1012 * {@code future.whenComplete(callback)} to {@code future.whenCompleteAsync(callback, executor)}, so the 1013 * response-handler work runs on the named pool instead of the future's natural completion thread (often an 1014 * I/O-driver or database-callback thread). 1015 * 1016 * <p> 1017 * The value is the {@link org.apache.juneau.commons.inject.Bean#name() @Bean(name=...)} lookup key for an 1018 * {@link java.util.concurrent.Executor} registered in the resource's bean store. Empty string (default) 1019 * means no override — completion callbacks run on the future's natural thread (the existing behavior). 1020 * 1021 * <h5 class='section'>Example:</h5> 1022 * <p class='bjava'> 1023 * <ja>@Rest</ja>(path=<js>"/api"</js>, asyncCompletionExecutor=<js>"myCompletionPool"</js>) 1024 * <jk>public class</jk> ApiResource <jk>extends</jk> RestServlet { 1025 * 1026 * <ja>@Bean</ja>(name=<js>"myCompletionPool"</js>) 1027 * <jk>public</jk> Executor completionPool() { 1028 * <jk>return</jk> Executors.newFixedThreadPool(8); 1029 * } 1030 * 1031 * <ja>@RestGet</ja>(<js>"/orders/{id}"</js>) 1032 * <jk>public</jk> CompletableFuture<Order> getOrder(<ja>@Path</ja> String id) { 1033 * <jk>return</jk> orderService.fetchAsync(id); <jc>// callback runs on myCompletionPool</jc> 1034 * } 1035 * } 1036 * </p> 1037 * 1038 * <p> 1039 * Per-operation overrides are available via {@link RestOp#asyncCompletionExecutor()} (and the verb annotations). 1040 * A reference to a bean name that does not resolve in the bean store causes a startup failure. 1041 * 1042 * <h5 class='section'>Notes:</h5><ul> 1043 * <li class='note'> 1044 * MDC propagation still works when this executor is set — the 1045 * {@link MdcAsyncListener} wraps the callback <em>before</em> it is 1046 * routed through the executor, so the MDC snapshot is restored on whichever thread the executor picks. 1047 * </ul> 1048 * 1049 * <h5 class='section'>See Also:</h5><ul> 1050 * <li class='jc'>{@link AsyncResponseProcessor} 1051 * <li class='ja'>{@link RestOp#asyncCompletionExecutor()} 1052 * </ul> 1053 * 1054 * @return The annotation value. 1055 * @since 10.0.0 1056 */ 1057 String asyncCompletionExecutor() default ""; 1058 1059 /** 1060 * Specifies the compression encoders for this resource. 1061 * 1062 * <p> 1063 * Encoders are used to enable various kinds of compression (e.g. <js>"gzip"</js>) on requests and responses. 1064 * 1065 * <p> 1066 * Encoders are automatically inherited from {@link Rest#encoders()} annotations on parent classes with the encoders on child classes 1067 * prepended to the encoder group. 1068 * The {@link org.apache.juneau.marshall.encoders.EncoderSet.NoInherit EncoderSet.NoInherit} class can be used to prevent inheriting from the parent class. 1069 * 1070 * <h5 class='section'>Example:</h5> 1071 * <p class='bjava'> 1072 * <jc>// Define a REST resource that handles GZIP compression.</jc> 1073 * <ja>@Rest</ja>( 1074 * encoders={ 1075 * GzipEncoder.<jk>class</jk> 1076 * } 1077 * ) 1078 * <jk>public class</jk> MyResource { 1079 * ... 1080 * } 1081 * </p> 1082 * 1083 * <p> 1084 * The encoders can also be tailored at the method level using {@link RestOp#encoders()} (and related annotations). 1085 * 1086 * <p> 1087 * For programmatic equivalents, contribute an {@link EncoderSet} bean via 1088 * {@link org.apache.juneau.commons.inject.Bean @Bean(name="encoders")}. 1089 * 1090 * <h5 class='section'>Inheritance Rules</h5> 1091 * <ul> 1092 * <li>Encoders on child are combined with those on parent class. 1093 * </ul> 1094 * 1095 * <h5 class='section'>See Also:</h5><ul> 1096 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerEncoders">Encoders in REST servers</a> 1097 * </ul> 1098 * 1099 * @return The annotation value. 1100 */ 1101 Class<? extends Encoder>[] encoders() default {}; 1102 1103 /** 1104 * Default form data parameter definitions. 1105 * 1106 * <p> 1107 * Provides default values for {@link FormData @FormData} annotations on method parameters across all methods in this class. 1108 * 1109 * <h5 class='section'>Example:</h5> 1110 * <p class='bjava'> 1111 * <ja>@Rest</ja>( 1112 * formDataParams={ 1113 * <ja>@FormData</ja>(name=<js>"action"</js>, def=<js>"submit"</js>) 1114 * } 1115 * ) 1116 * <jk>public class</jk> MyResource {...} 1117 * </p> 1118 * 1119 * @return The annotation value. 1120 * @since 9.2.0 1121 */ 1122 FormData[] formDataParams() default {}; 1123 1124 /** 1125 * Class-level guards. 1126 * 1127 * <p> 1128 * Associates one or more {@link RestGuard RestGuards} with all REST methods defined in this class. 1129 * 1130 * <h5 class='section'>Inheritance Rules</h5> 1131 * <ul> 1132 * <li>Guards on child are combined with those on parent class. 1133 * <li>Guards are executed child-to-parent in the order they appear in the annotation. 1134 * <li>Guards on methods are executed before those on classes. 1135 * </ul> 1136 * 1137 * @return The annotation value. 1138 */ 1139 Class<? extends RestGuard>[] guards() default {}; 1140 1141 /** 1142 * Default header parameter definitions. 1143 * 1144 * <p> 1145 * Provides default values for {@link Header @Header} annotations on method parameters across all methods in this class. 1146 * 1147 * <h5 class='section'>Example:</h5> 1148 * <p class='bjava'> 1149 * <ja>@Rest</ja>( 1150 * headerParams={ 1151 * <ja>@Header</ja>(name=<js>"Accept-Language"</js>, def=<js>"en-US"</js>), 1152 * <ja>@Header</ja>(name=<js>"X-API-Version"</js>, def=<js>"1.0"</js>) 1153 * } 1154 * ) 1155 * <jk>public class</jk> MyResource {...} 1156 * </p> 1157 * 1158 * @return The annotation value. 1159 * @since 9.2.0 1160 */ 1161 Header[] headerParams() default {}; 1162 1163 /** 1164 * 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 * <p> 1171 * Applies uniformly across body-reading paths, including {@code multipart/form-data} uploads: a request whose 1172 * declared {@code Content-Length} or parsed part sizes exceed this ceiling is rejected with a {@code 413} 1173 * response before (or as soon as) the oversized content would otherwise be buffered. 1174 * 1175 * <h5 class='section'>Notes:</h5><ul> 1176 * <li class='note'> 1177 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1178 * (e.g. <js>"$L{my.localized.variable}"</js>). 1179 * </ul> 1180 * 1181 * <h5 class='section'>See Also:</h5><ul> 1182 * <li class='ja'>{@link RestOp#maxInput} 1183 * <li class='ja'>{@link RestPost#maxInput} 1184 * <li class='ja'>{@link RestPut#maxInput} 1185 * </ul> 1186 * 1187 * @return The annotation value. 1188 */ 1189 String maxInput() default ""; 1190 1191 /** 1192 * Messages. 1193 * 1194 * Identifies the location of the resource bundle for this class. 1195 * 1196 * <p> 1197 * There are two possible formats: 1198 * <ul> 1199 * <li>A simple string - Represents the {@link org.apache.juneau.marshall.cp.Messages.Builder#name(String) name} of the resource bundle. 1200 * <br><br><i>Example:</i> 1201 * <p class='bjava'> 1202 * <jc>// Bundle name is Messages.properties.</jc> 1203 * <ja>@Rest</ja>(messages=<js>"Messages"</js>) 1204 * </p> 1205 * <li>Simplified JSON - Represents parameters for the {@link org.apache.juneau.marshall.cp.Messages.Builder} class. 1206 * <br><br><i>Example:</i> 1207 * <p class='bjava'> 1208 * <jc>// Bundles can be found in two packages.</jc> 1209 * <ja>@Rest</ja>(messages=<js>"{name:'Messages',baseNames:['{package}.{name}','{package}.i18n.{name}']"</js>) 1210 * </p> 1211 * </ul> 1212 * 1213 * <p> 1214 * If the bundle name is not specified, the class name of the resource object is used. 1215 * 1216 * <h5 class='section'>Notes:</h5><ul> 1217 * <li class='note'> 1218 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1219 * (e.g. <js>"$L{my.localized.variable}"</js>). 1220 * </ul> 1221 * 1222 * @return The annotation value. 1223 */ 1224 String messages() default ""; 1225 1226 /** 1227 * Specifies the parsers for converting HTTP request bodies into POJOs. 1228 * 1229 * <p> 1230 * Parsers are used to convert the content of HTTP requests into POJOs. 1231 * <br>Any of the Juneau framework parsers can be used in this setting. 1232 * <br>The parser selected is based on the request <c>Content-Type</c> header matched against the values returned by the following method 1233 * using a best-match algorithm: 1234 * <ul class='javatree'> 1235 * <li class='jm'>{@link Parser#getMediaTypes()} 1236 * </ul> 1237 * 1238 * <p> 1239 * Parsers are automatically inherited from {@link Rest#parsers()} annotations on parent classes with the parsers on child classes 1240 * prepended to the parser group. 1241 * The {@link org.apache.juneau.marshall.parser.ParserSet.NoInherit ParserSet.NoInherit} class can be used to prevent inheriting from the parent class. 1242 * 1243 * <h5 class='section'>Example:</h5> 1244 * <p class='bjava'> 1245 * <jc>// Define a REST resource that can consume JSON and XML.</jc> 1246 * <ja>@Rest</ja>( 1247 * parsers={ 1248 * JsonParser.<jk>class</jk>, 1249 * XmlParser.<jk>class</jk> 1250 * } 1251 * ) 1252 * <jk>public class</jk> MyResource { 1253 * ... 1254 * } 1255 * </p> 1256 * 1257 * <p> 1258 * The parsers can also be tailored at the method level using {@link RestOp#parsers()} (and related annotations). 1259 * 1260 * <p> 1261 * For programmatic equivalents, contribute a {@link ParserSet} bean via 1262 * {@link org.apache.juneau.commons.inject.Bean @Bean(name="parsers")}. 1263 * 1264 * <h5 class='section'>Inheritance Rules</h5> 1265 * <ul> 1266 * <li>Parsers on child override those on parent class. 1267 * <li>{@link org.apache.juneau.marshall.parser.ParserSet.Inherit ParserSet.Inherit} class can be used to inherit and augment values from parent. 1268 * <li>{@link org.apache.juneau.marshall.parser.ParserSet.NoInherit ParserSet.NoInherit} class can be used to suppress inheriting from parent. 1269 * <li>Parsers on methods take precedence over those on classes. 1270 * </ul> 1271 * 1272 * <h5 class='section'>See Also:</h5><ul> 1273 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Marshalling">Marshalling</a> 1274 * </ul> 1275 * 1276 * @return The annotation value. 1277 */ 1278 Class<?>[] parsers() default {}; 1279 1280 /** 1281 * HTTP part parser. 1282 * 1283 * <p> 1284 * Specifies the {@link HttpPartParser} to use for parsing headers, query/form parameters, and URI parts. 1285 * 1286 * @return The annotation value. 1287 */ 1288 Class<? extends HttpPartParser> partParser() default HttpPartParser.Void.class; 1289 1290 /** 1291 * HTTP part serializer. 1292 * 1293 * <p> 1294 * Specifies the {@link HttpPartSerializer} to use for serializing headers, query/form parameters, and URI parts. 1295 * 1296 * @return The annotation value. 1297 */ 1298 Class<? extends HttpPartSerializer> partSerializer() default HttpPartSerializer.Void.class; 1299 1300 /** 1301 * Resource path. 1302 * 1303 * <p> 1304 * Used in the following situations: 1305 * <ul class='spaced-list'> 1306 * <li> 1307 * On child resources (resource classes attached to parents via the {@link #children()} annotation) to identify 1308 * the subpath used to access the child resource relative to the parent. 1309 * <li> 1310 * On top-level {@link RestServlet} classes deployed as Spring beans when <c>JuneauRestInitializer</c> is being used. 1311 * </ul> 1312 * 1313 * <h5 class='topic'>On child resources</h5> 1314 * <p> 1315 * The typical usage is to define a path to a child resource relative to the parent resource. 1316 * 1317 * <h5 class='figure'>Example:</h5> 1318 * <p class='bjava'> 1319 * <ja>@Rest</ja>( 1320 * children={ChildResource.<jk>class</jk>} 1321 * ) 1322 * <jk>public class</jk> TopLevelResource <jk>extends</jk> BasicRestServlet {...} 1323 * 1324 * <ja>@Rest</ja>( 1325 * path=<js>"/child"</js>, 1326 * children={GrandchildResource.<jk>class</jk>} 1327 * ) 1328 * <jk>public class</jk> ChildResource {...} 1329 * 1330 * <ja>@Rest</ja>( 1331 * path=<js>"/grandchild"</js> 1332 * ) 1333 * <jk>public class</jk> GrandchildResource { 1334 * <ja>@RestGet</ja>(<js>"/"</js>) 1335 * <jk>public</jk> String sayHello() { 1336 * <jk>return</jk> <js>"Hello!"</js>; 1337 * } 1338 * } 1339 * </p> 1340 * <p> 1341 * In the example above, assuming the <c>TopLevelResource</c> servlet is deployed to path <c>/myContext/myServlet</c>, 1342 * then the <c>sayHello</c> method is accessible through the URI <c>/myContext/myServlet/child/grandchild</c>. 1343 * 1344 * <p> 1345 * Note that in this scenario, the <c>path</c> attribute is not defined on the top-level resource. 1346 * Specifying the path on the top-level resource has no effect, but can be used for readability purposes. 1347 * 1348 * <h5 class='topic'>Path variables</h5> 1349 * <p> 1350 * The path can contain variables that get resolved to {@link Path @Path} parameters 1351 * or access through the {@link RestRequest#getPathParams()} method. 1352 * 1353 * <h5 class='figure'>Example:</h5> 1354 * <p class='bjava'> 1355 * <ja>@Rest</ja>( 1356 * path=<js>"/myResource/{foo}/{bar}"</js> 1357 * ) 1358 * <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet { 1359 * 1360 * <ja>@RestGet</ja>(<js>"/{baz}"</js>) 1361 * <jk>public void</jk> String doX(<ja>@Path</ja> String <jv>foo</jv>, <ja>@Path</ja> <jk>int</jk> <jv>bar</jv>, <ja>@Path</ja> MyPojo <jv>baz</jv>) { 1362 * ... 1363 * } 1364 * } 1365 * </p> 1366 * 1367 * <p> 1368 * Variables can be used on either top-level or child resources and can be defined on multiple levels. 1369 * 1370 * <p> 1371 * All variables in the path must be specified or else the target will not resolve and a <c>404</c> will result. 1372 * 1373 * <p> 1374 * When variables are used on a path of a top-level resource deployed as a Spring bean in a Spring Boot application, 1375 * the first part of the URL must be a literal which will be used as the servlet path of the registered servlet. 1376 * 1377 * <h5 class='section'>Notes:</h5><ul> 1378 * <li class='note'> 1379 * The leading slash is optional. <js>"/myResource"</js> and <js>"myResource"</js> is equivalent. 1380 * <li class='note'> 1381 * The paths <js>"/myResource"</js> and <js>"/myResource/*"</js> are equivalent. 1382 * <li class='note'> 1383 * Paths must not end with <js>"/"</js> (per the servlet spec). 1384 * <li class='note'> 1385 * Effective only when this class is registered directly with the servlet container as a top-level 1386 * resource. When this class is imported as a mixin via {@code @Rest(mixins=...)}, the importing 1387 * host's own {@code path()} or {@link #paths()} governs the mount and this annotation is silently 1388 * ignored — mixin endpoints land in the host's URL namespace. 1389 * </ul> 1390 * 1391 * <h5 class='section'>Inheritance Rules</h5> 1392 * <ul> 1393 * <li>Path is searched for in child-to-parent order. 1394 * </ul> 1395 * 1396 * @return The annotation value. 1397 */ 1398 String path() default ""; 1399 1400 /** 1401 * Additional servlet mount paths. 1402 * 1403 * <p> 1404 * Optional multi-mount companion to {@link #path()} for top-level servlet deployment. 1405 * 1406 * <p> 1407 * When specified, servlet containers may mount this resource on each listed path. 1408 * This is primarily intended for built-in support endpoints such as health probes where multiple exact URLs 1409 * should be served by a single servlet instance. 1410 * 1411 * <h5 class='section'>Runtime substitution (since 10.0.0)</h5> 1412 * <p> 1413 * Each array element is treated as a template: 1414 * <ol> 1415 * <li>The element runs through 1416 * <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1417 * variable substitution (e.g. {@code $C{health.paths}}, {@code $E{HEALTH_PATHS,/healthz}}, 1418 * {@code $S{my.system.prop,/healthz}}) using the bootstrap {@link org.apache.juneau.commons.svl.VarResolver 1419 * VarResolver} on the bean store. 1420 * <li>The post-SVL value is split on {@code ,}; each piece is trimmed and empty pieces are dropped. 1421 * A single template element can therefore expand to zero, one, or many mount paths. 1422 * </ol> 1423 * 1424 * <h5 class='figure'>Examples:</h5> 1425 * <p class='bjava'> 1426 * <jc>// 1. Single key resolving to a multi-value config string.</jc> 1427 * <ja>@Rest</ja>(paths={<js>"$C{health.paths}"</js>}) 1428 * 1429 * <jc>// 2. Mix literal + resolved element.</jc> 1430 * <ja>@Rest</ja>(paths={<js>"/api"</js>, <js>"$C{extra.paths}"</js>}) 1431 * 1432 * <jc>// 3. Env var with comma-separated defaults baked in.</jc> 1433 * <ja>@Rest</ja>(paths={<js>"$E{HEALTH_PATHS,/healthz,/readyz}"</js>}) 1434 * </p> 1435 * 1436 * <h5 class='section'>Notes:</h5><ul> 1437 * <li class='note'> 1438 * Paths are normalized to servlet path-specs by the hosting runtime. 1439 * <li class='note'> 1440 * When both {@link #path()} and {@link #paths()} are present, runtimes may use {@link #paths()} for 1441 * top-level mounting and continue using {@link #path()} for child-resource composition. 1442 * <li class='note'> 1443 * The annotation default sits at the lowest rung of the runtime-override resolution chain — see 1444 * {@link RestContext#getPaths()} for the full precedence order (programmatic > getter > annotation). 1445 * <li class='note'> 1446 * An SVL failure (unresolved variable with no default) falls back to the literal element rather than 1447 * throwing during construction. 1448 * <li class='note'> 1449 * Effective only when this class is registered directly with the servlet container as a top-level 1450 * resource. When this class is imported as a mixin via {@code @Rest(mixins=...)}, the importing 1451 * host's own {@link #path()} or {@code paths()} governs the mount and this annotation is silently 1452 * ignored — mixin endpoints land in the host's URL namespace. 1453 * </ul> 1454 * 1455 * @return The annotation value. 1456 */ 1457 String[] paths() default {}; 1458 1459 /** 1460 * Default path parameter definitions. 1461 * 1462 * <p> 1463 * Provides default values for {@link Path @Path} annotations on method parameters across all methods in this class. 1464 * 1465 * <h5 class='section'>Example:</h5> 1466 * <p class='bjava'> 1467 * <ja>@Rest</ja>( 1468 * pathParams={ 1469 * <ja>@Path</ja>(name=<js>"version"</js>, def=<js>"v1"</js>) 1470 * } 1471 * ) 1472 * <jk>public class</jk> MyResource {...} 1473 * </p> 1474 * 1475 * @return The annotation value. 1476 * @since 9.2.0 1477 */ 1478 Path[] pathParams() default {}; 1479 1480 /** 1481 * Supported accept media types. 1482 * 1483 * <p> 1484 * Overrides the media types inferred from the serializers that identify what media types can be produced by the resource. 1485 * 1486 * <h5 class='section'>Notes:</h5><ul> 1487 * <li class='note'> 1488 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1489 * (e.g. <js>"$L{my.localized.variable}"</js>). 1490 * </ul> 1491 * 1492 * @return The annotation value. 1493 */ 1494 String[] produces() default {}; 1495 1496 /** 1497 * Default query parameter definitions. 1498 * 1499 * <p> 1500 * Provides default values for {@link Query @Query} annotations on method parameters across all methods in this class. 1501 * Values specified here are used as defaults when the same property is not explicitly defined on a method parameter's 1502 * {@link Query @Query} annotation. 1503 * 1504 * <h5 class='section'>Example:</h5> 1505 * <p class='bjava'> 1506 * <jc>// Define common query parameters at class level</jc> 1507 * <ja>@Rest</ja>( 1508 * queryParams={ 1509 * <ja>@Query</ja>(name=<js>"format"</js>, def=<js>"json"</js>, description=<js>"Output format"</js>), 1510 * <ja>@Query</ja>(name=<js>"verbose"</js>, def=<js>"false"</js>, schema=<ja>@Schema</ja>(type=<js>"boolean"</js>)) 1511 * } 1512 * ) 1513 * <jk>public class</jk> MyResource { 1514 * 1515 * <jc>// Method will inherit the default query parameter definitions</jc> 1516 * <ja>@RestGet</ja> 1517 * <jk>public</jk> String doGet(<ja>@Query</ja>(<js>"format"</js>) String format, <ja>@Query</ja>(<js>"verbose"</js>) <jk>boolean</jk> verbose) {...} 1518 * 1519 * <jc>// Can override defaults on a per-method basis</jc> 1520 * <ja>@RestGet</ja> 1521 * <jk>public</jk> String doGet2(<ja>@Query</ja>(name=<js>"format"</js>, def=<js>"xml"</js>) String format) {...} 1522 * } 1523 * </p> 1524 * 1525 * <h5 class='section'>Notes:</h5><ul> 1526 * <li class='note'> 1527 * These defaults apply to validation, parsing, and OpenAPI/Swagger documentation generation. 1528 * <li class='note'> 1529 * Method-level {@link Query @Query} annotations take precedence over class-level definitions. 1530 * <li class='note'> 1531 * The {@link Query#name() name} attribute must be specified for each query definition. 1532 * </ul> 1533 * 1534 * @return The annotation value. 1535 * @since 9.2.0 1536 */ 1537 Query[] queryParams() default {}; 1538 1539 /** 1540 * Render response stack traces in responses. 1541 * 1542 * <p> 1543 * Render stack traces in HTTP response bodies when errors occur. 1544 * 1545 * <p> 1546 * Off by default. Besides the stack trace itself, this same setting also determines whether the 1547 * {@code Thrown} response header is set and whether an error whose exception type wasn't deliberately 1548 * thrown by application code (i.e. not a {@link org.apache.juneau.http.response.BasicHttpException 1549 * BasicHttpException} or one of its subclasses) has its class name/message echoed into the error body. 1550 * Leave this off in production so that an unplanned exception type (a database driver error, a 1551 * file-system exception, and the like) can't incidentally leak implementation detail to the caller; 1552 * turn it on only for local debugging. 1553 * 1554 * <h5 class='section'>Notes:</h5><ul> 1555 * <li class='note'> 1556 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1557 * (e.g. <js>"$L{my.localized.variable}"</js>). 1558 * </ul> 1559 * 1560 * @return The annotation value. 1561 */ 1562 String renderResponseStackTraces() default ""; 1563 1564 /** 1565 * Response processors. 1566 * 1567 * <p> 1568 * Specifies a list of {@link ResponseProcessor} classes that know how to convert POJOs returned by REST methods or 1569 * set via {@link RestResponse#setContent(Object)} into appropriate HTTP responses. 1570 * 1571 * <p> 1572 * These processors run in order and are the extension point that turns a method's return value into the response 1573 * body. The built-in {@link SerializedPojoProcessor} is the default POJO handler — it runs the 1574 * content-negotiated {@link #serializers() serializer}, so for ordinary POJO returns the effective response format 1575 * is governed by serializer ordering and the request <c>Accept</c> header (see {@link #serializers()}), not by this 1576 * list. 1577 * 1578 * <p> 1579 * A custom view-renderer {@link ResponseProcessor} installed here (for example a template-rendering processor 1580 * contributed by a view mixin — see {@link #mergeResponseProcessorsIntoHost()}) can instead claim a return 1581 * value and render it directly (e.g. as HTML from a template) before serializer negotiation is reached, changing the 1582 * effective response for the returns it handles. 1583 * 1584 * @return The annotation value. 1585 */ 1586 Class<? extends ResponseProcessor>[] responseProcessors() default {}; 1587 1588 /** 1589 * Java REST operation method parameter resolvers. 1590 * 1591 * <p> 1592 * By default, the Juneau framework will automatically Java method parameters of various types (e.g. 1593 * <c>RestRequest</c>, <c>Accept</c>, <c>Reader</c>). 1594 * <br>This setting allows you to provide your own resolvers for your own class types that you want resolved. 1595 * 1596 * @return The annotation value. 1597 */ 1598 Class<? extends RestOpArg>[] restOpArgs() default {}; 1599 1600 /** 1601 * Role guard. 1602 * 1603 * <p> 1604 * An expression defining if a user with the specified roles are allowed to access methods on this class. 1605 * 1606 * <p> 1607 * This is a shortcut for specifying {@link RestOp#roleGuard()} on all the REST operations on a class. 1608 * 1609 * <h5 class='section'>Example:</h5> 1610 * <p class='bjava'> 1611 * <ja>@Rest</ja>( 1612 * path=<js>"/foo"</js>, 1613 * roleGuard=<js>"ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)"</js> 1614 * ) 1615 * <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet { 1616 * ... 1617 * } 1618 * </p> 1619 * 1620 * <h5 class='section'>Notes:</h5><ul> 1621 * <li class='note'> 1622 * Supports any of the following expression constructs: 1623 * <ul> 1624 * <li><js>"foo"</js> - Single arguments. 1625 * <li><js>"foo,bar,baz"</js> - Multiple OR'ed arguments. 1626 * <li><js>"foo | bar | baz"</js> - Multiple OR'ed arguments, pipe syntax. 1627 * <li><js>"foo || bar || baz"</js> - Multiple OR'ed arguments, Java-OR syntax. 1628 * <li><js>"fo*"</js> - Patterns including <js>'*'</js> and <js>'?'</js>. 1629 * <li><js>"fo* & *oo"</js> - Multiple AND'ed arguments, ampersand syntax. 1630 * <li><js>"fo* && *oo"</js> - Multiple AND'ed arguments, Java-AND syntax. 1631 * <li><js>"fo* || (*oo || bar)"</js> - Parenthesis. 1632 * </ul> 1633 * <li> 1634 * AND operations take precedence over OR operations (as expected). 1635 * <li> 1636 * Whitespace is ignored. 1637 * <li> 1638 * <jk>null</jk> or empty expressions always match as <jk>false</jk>. 1639 * <li> 1640 * If patterns are used, you must specify the list of declared roles using {@link #rolesDeclared()}. 1641 * <li> 1642 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1643 * (e.g. <js>"$L{my.localized.variable}"</js>). 1644 * </ul> 1645 * 1646 * @return The annotation value. 1647 */ 1648 String roleGuard() default ""; 1649 1650 /** 1651 * Declared roles. 1652 * 1653 * <p> 1654 * A comma-delimited list of all possible user roles. 1655 * 1656 * <p> 1657 * Used in conjunction with {@link #roleGuard()} is used with patterns. 1658 * 1659 * <p> 1660 * This is a shortcut for specifying {@link RestOp#rolesDeclared()} on all the REST operations on a class. 1661 * 1662 * <h5 class='section'>Example:</h5> 1663 * <p class='bjava'> 1664 * <ja>@Rest</ja>( 1665 * rolesDeclared=<js>"ROLE_ADMIN,ROLE_READ_WRITE,ROLE_READ_ONLY,ROLE_SPECIAL"</js>, 1666 * roleGuard=<js>"ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)"</js> 1667 * ) 1668 * <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet { 1669 * ... 1670 * } 1671 * </p> 1672 * 1673 * @return The annotation value. 1674 */ 1675 String rolesDeclared() default ""; 1676 1677 /** 1678 * Specifies the serializers for POJOs into HTTP response bodies. 1679 * 1680 * <p> 1681 * Serializer are used to convert POJOs to HTTP response bodies. 1682 * <br>Any of the Juneau framework serializers can be used in this setting. 1683 * <br>The serializer selected is based on the request <c>Accept</c> header matched against the values returned by the following method 1684 * using a best-match algorithm: 1685 * <ul class='javatree'> 1686 * <li class='jm'>{@link Serializer#getMediaTypeRanges()} 1687 * </ul> 1688 * 1689 * <p> 1690 * <b>Ordering determines the default response format.</b> A request that sends no <c>Accept</c> header (or a 1691 * non-specific one such as <c>*/*</c>, which browsers send by default) is treated as <c>*/*</c> and matches 1692 * the <b>first</b> serializer in this list. That is why the default configuration 1693 * ({@link org.apache.juneau.rest.server.config.BasicUniversalConfig}) lists HTML first — so a browser, or any 1694 * client that omits <c>Accept</c>, receives HTML rather than JSON. Order this list deliberately, and send an 1695 * explicit <c>Accept: application/json</c> to force JSON regardless of ordering. 1696 * 1697 * <p> 1698 * Serializers are automatically inherited from {@link Rest#serializers()} annotations on parent classes with the serializers on child classes 1699 * prepended to the serializer group. 1700 * The {@link org.apache.juneau.marshall.serializer.SerializerSet.NoInherit SerializerSet.NoInherit} class can be used to prevent inheriting from the parent class. 1701 * 1702 * <h5 class='section'>Example:</h5> 1703 * <p class='bjava'> 1704 * <jc>// Define a REST resource that can produce JSON and XML.</jc> 1705 * <ja>@Rest</ja>( 1706 * serializers={ 1707 * JsonParser.<jk>class</jk>, 1708 * XmlParser.<jk>class</jk> 1709 * } 1710 * ) 1711 * <jk>public class</jk> MyResource { 1712 * ... 1713 * } 1714 * </p> 1715 * 1716 * <p> 1717 * The serializers can also be tailored at the method level using {@link RestOp#serializers()} (and related annotations). 1718 * 1719 * <p> 1720 * For programmatic equivalents, contribute a {@link SerializerSet} bean via 1721 * {@link org.apache.juneau.commons.inject.Bean @Bean(name="serializers")}. 1722 * 1723 * <h5 class='section'>Inheritance Rules</h5> 1724 * <ul> 1725 * <li>Serializers on child override those on parent class. 1726 * <li>{@link org.apache.juneau.marshall.serializer.SerializerSet.Inherit SerializerSet.Inherit} class can be used to inherit and augment values from parent. 1727 * <li>{@link org.apache.juneau.marshall.serializer.SerializerSet.NoInherit SerializerSet.NoInherit} class can be used to suppress inheriting from parent. 1728 * <li>Serializers on methods take precedence over those on classes. 1729 * </ul> 1730 * 1731 * <h5 class='section'>See Also:</h5><ul> 1732 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Marshalling">Marshalling</a> 1733 * </ul> 1734 * 1735 * @return The annotation value. 1736 */ 1737 Class<? extends Serializer>[] serializers() default {}; 1738 1739 /** 1740 * Optional site name. 1741 * 1742 * <p> 1743 * The site name is intended to be a title that can be applied to the entire site. 1744 * 1745 * <p> 1746 * One possible use is if you want to add the same title to the top of all pages by defining a header on a 1747 * common parent class like so: 1748 * <p class='bjava'> 1749 * <ja>@HtmlDocConfig</ja>( 1750 * header={ 1751 * <js>"<h1>$RS{siteName}</h1>"</js>, 1752 * <js>"<h2>$RS{title}</h2>"</js> 1753 * } 1754 * ) 1755 * </p> 1756 * 1757 * <h5 class='section'>Notes:</h5><ul> 1758 * <li class='note'> 1759 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1760 * (e.g. <js>"$L{my.localized.variable}"</js>). 1761 * </ul> 1762 * 1763 * @return The annotation value. 1764 */ 1765 String siteName() default ""; 1766 1767 /** 1768 * Static files. 1769 * 1770 * <p> 1771 * Used to retrieve localized files to be served up as static files through the REST API via the following 1772 * predefined methods: 1773 * <ul class='javatree'> 1774 * <li class='jm'>{@code BasicRestResource.getHtdoc(String, Locale)}. 1775 * <li class='jm'>{@code BasicRestServlet.getHtdoc(String, Locale)}. 1776 * </ul> 1777 * 1778 * <p> 1779 * The static file finder can be accessed through the following methods: 1780 * <ul class='javatree'> 1781 * <li class='jm'>{@link RestContext#getStaticFiles()} 1782 * </ul> 1783 * 1784 * <h5 class='section'>Inheritance Rules</h5> 1785 * <ul> 1786 * <li>Static files on child are combined with those on parent class. 1787 * <li>Static files are are executed child-to-parent in the order they appear in the annotation. 1788 * </ul> 1789 * 1790 * @return The annotation value. 1791 */ 1792 Class<? extends StaticFiles> staticFiles() default StaticFiles.Void.class; 1793 1794 /** 1795 * Provides swagger-specific metadata on this resource. 1796 * 1797 * <p> 1798 * Used to populate the auto-generated OPTIONS swagger documentation. 1799 * 1800 * <h5 class='section'>Example:</h5> 1801 * <p class='bjava'> 1802 * <ja>@Rest</ja>( 1803 * path=<js>"/addressBook"</js>, 1804 * 1805 * <jc>// Swagger info.</jc> 1806 * swagger=@Swagger({ 1807 * <js>"contact:{name:'John Smith',email:'john@smith.com'},"</js>, 1808 * <js>"license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},"</js>, 1809 * <js>"version:'2.0',</js>, 1810 * <js>"termsOfService:'You are on your own.',"</js>, 1811 * <js>"tags:[{name:'Java',description:'Java utility',externalDocs:{description:'Home page',url:'http://juneau.apache.org'}}],"</js>, 1812 * <js>"externalDocs:{description:'Home page',url:'http://juneau.apache.org'}"</js> 1813 * }) 1814 * ) 1815 * </p> 1816 * 1817 * <h5 class='section'>See Also:</h5><ul> 1818 * <li class='ja'>{@link Swagger} 1819 * </ul> 1820 * 1821 * @return The annotation value. 1822 */ 1823 Swagger swagger() default @Swagger; 1824 1825 /** 1826 * Swagger provider. 1827 * 1828 * @return The annotation value. 1829 */ 1830 Class<? extends SwaggerProvider> swaggerProvider() default SwaggerProvider.Void.class; 1831 1832 /** 1833 * OpenAPI 3.1 provider. 1834 * 1835 * <p> 1836 * Sibling of {@link #swaggerProvider()} for the OpenAPI 3.1 emission path. Defaults to 1837 * {@link org.apache.juneau.rest.server.openapi.OpenApiProvider.Void OpenApiProvider.Void} 1838 * which resolves to {@code BasicOpenApiProvider} unless the bean store provides an override. 1839 * 1840 * @return The annotation value. 1841 */ 1842 Class<? extends OpenApiProvider> openApiProvider() default OpenApiProvider.Void.class; 1843 1844 /** 1845 * Optional servlet title. 1846 * 1847 * <p> 1848 * It is used to populate the Swagger title field. 1849 * 1850 * <h5 class='section'>Inheritance Rules</h5> 1851 * <ul> 1852 * <li>Label is searched for in child-to-parent order. 1853 * </ul> 1854 * 1855 * <h5 class='section'>Notes:</h5><ul> 1856 * <li class='note'> 1857 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1858 * (e.g. <js>"$L{my.localized.variable}"</js>). 1859 * <li class='note'> 1860 * Corresponds to the swagger field <c>/info/title</c>. 1861 * </ul> 1862 * 1863 * @return The annotation value. 1864 */ 1865 String[] title() default {}; 1866 1867 /** 1868 * Resource authority path. 1869 * 1870 * <p> 1871 * Overrides the authority path value for this resource and any child resources. 1872 * 1873 * <h5 class='section'>Notes:</h5><ul> 1874 * <li class='note'> 1875 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1876 * (e.g. <js>"$L{my.localized.variable}"</js>). 1877 * </ul> 1878 * 1879 * @return The annotation value. 1880 */ 1881 String uriAuthority() default ""; 1882 1883 /** 1884 * Resource context path. 1885 * 1886 * <p> 1887 * Overrides the context path value for this resource and any child resources. 1888 * 1889 * <h5 class='section'>Notes:</h5><ul> 1890 * <li class='note'> 1891 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1892 * (e.g. <js>"$L{my.localized.variable}"</js>). 1893 * </ul> 1894 * 1895 * @return The annotation value. 1896 */ 1897 String uriContext() default ""; 1898 1899 /** 1900 * URI-resolution relativity. 1901 * 1902 * <p> 1903 * Specifies how relative URIs should be interpreted by serializers. 1904 * 1905 * <p> 1906 * See {@link UriRelativity} for possible values. 1907 * 1908 * <h5 class='section'>Notes:</h5><ul> 1909 * <li class='note'> 1910 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1911 * (e.g. <js>"$L{my.localized.variable}"</js>). 1912 * </ul> 1913 * 1914 * @return The annotation value. 1915 */ 1916 String uriRelativity() default ""; 1917 1918 /** 1919 * URI-resolution. 1920 * 1921 * <p> 1922 * Specifies how relative URIs should be interpreted by serializers. 1923 * 1924 * <p> 1925 * See {@link UriResolution} for possible values. 1926 * 1927 * <h5 class='section'>Notes:</h5><ul> 1928 * <li class='note'> 1929 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">REST Server SVL Variables</a> 1930 * (e.g. <js>"$L{my.localized.variable}"</js>). 1931 * </ul> 1932 * 1933 * @return The annotation value. 1934 */ 1935 String uriResolution() default ""; 1936}