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 org.apache.juneau.commons.inject.*; 020 021/** 022 * The env-driven {@code RestContext.*} default properties for a resource, resolved as a single bound object. 023 * 024 * <p> 025 * Each property supplies the environment-level default for the corresponding {@link Rest @Rest} attribute (for 026 * example {@link #getClientVersionHeader()} backs {@code @Rest(clientVersionHeader)}). A resource's 027 * {@code @Rest} annotation values, when present, take precedence over these defaults; these properties only 028 * establish the starting value before the annotation chain is applied. 029 * 030 * <p> 031 * Values are resolved under the {@code RestContext} prefix from the standard {@link org.apache.juneau.commons.settings.Settings Settings} 032 * source chain (thread-local override, global override, registered property sources, system properties, system 033 * environment) as well as any per-resource {@link org.apache.juneau.commons.settings.PropertySource PropertySource} 034 * beans registered in the resource's bean store — so a resource's {@code @Rest(config=...)} file can set a 035 * {@code RestContext.*} key and have it take effect. Relaxed key matching is enabled, so a key may be spelled in 036 * camelCase, dotted, or {@code SCREAMING_SNAKE_CASE} form. 037 * 038 * <p> 039 * A key absent from every source leaves the corresponding property at its default value shown below. The bound 040 * instance for a resource is retrievable via {@link RestContext#getRestContextProperties()} or from the resource 041 * bean store via {@code beanStore().getBean(RestContextProperties.class)}. 042 * 043 * <p> 044 * The {@code RestContext.uriAuthority} and {@code RestContext.uriContext} settings are intentionally not part of 045 * this bean: they carry a null-versus-empty distinction that is represented separately on {@link RestContext}. The 046 * {@code juneau.restLogger.level} setting is likewise separate, as it is owned by the call-logger subsystem rather 047 * than {@code RestContext}. 048 * 049 * <h5 class='section'>See Also:</h5><ul> 050 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ConfigProperties">@ConfigProperties Annotation Basics</a> 051 * </ul> 052 * 053 * @since 10.0.0 054 */ 055@ConfigProperties(prefix = "RestContext") 056@SuppressWarnings({ 057 "java:S9438" // Fields are bound reflectively from config sources by @ConfigProperties; making them final breaks binding. 058}) 059public class RestContextProperties { 060 061 private static final String FALSE = "false"; 062 063 private String allowedHeaderParams = "Accept,Content-Type"; 064 private String allowedMethodHeaders = ""; 065 private String allowedMethodParams = "HEAD,OPTIONS"; 066 private String disableContentParam = FALSE; 067 private String renderResponseStackTraces = FALSE; 068 private String problemDetails = FALSE; 069 private String debugMarshalling = FALSE; 070 private String virtualThreads = FALSE; 071 private String responseTraceparent = "true"; 072 private String mdcAsyncPropagation = "true"; 073 private String eagerInit = FALSE; 074 private String lazyChildren = FALSE; 075 private String clientVersionHeader = "Client-Version"; 076 private String uriRelativity = ""; 077 private String uriResolution = ""; 078 079 /** 080 * The default set of header names that may be passed via URL query parameter ({@code @Rest(allowedHeaderParams)}). 081 * 082 * @return The comma-delimited value. Never <jk>null</jk>. 083 */ 084 public String getAllowedHeaderParams() { 085 return allowedHeaderParams; 086 } 087 088 /** 089 * The default set of HTTP method names that may be specified via a request header ({@code @Rest(allowedMethodHeaders)}). 090 * 091 * @return The comma-delimited value. Never <jk>null</jk>. 092 */ 093 public String getAllowedMethodHeaders() { 094 return allowedMethodHeaders; 095 } 096 097 /** 098 * The default set of HTTP method names that may be specified via URL query parameter ({@code @Rest(allowedMethodParams)}). 099 * 100 * @return The comma-delimited value. Never <jk>null</jk>. 101 */ 102 public String getAllowedMethodParams() { 103 return allowedMethodParams; 104 } 105 106 /** 107 * The raw (unresolved) {@code @Rest(disableContentParam)} default — whether the {@code &content=} URL 108 * parameter is disabled. 109 * 110 * <p> 111 * The value is stored verbatim — without SVL variable resolution or boolean conversion — because SVL 112 * resolution requires the resource's var resolver, which this bean does not carry. {@link RestContext} reads this 113 * raw value, resolves any SVL variables, and parses it to a boolean. 114 * 115 * @return The raw value. Never <jk>null</jk>. 116 */ 117 public String getDisableContentParamRaw() { 118 return disableContentParam; 119 } 120 121 /** 122 * The raw (unresolved) {@code @Rest(renderResponseStackTraces)} default — whether stack traces are rendered 123 * in error responses. 124 * 125 * <p> 126 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 127 * 128 * @return The raw value. Never <jk>null</jk>. 129 */ 130 public String getRenderResponseStackTracesRaw() { 131 return renderResponseStackTraces; 132 } 133 134 /** 135 * The raw (unresolved) {@code @Rest(problemDetails)} default — whether RFC 7807 136 * {@code application/problem+json} responses are emitted. 137 * 138 * <p> 139 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 140 * 141 * @return The raw value. Never <jk>null</jk>. 142 */ 143 public String getProblemDetailsRaw() { 144 return problemDetails; 145 } 146 147 /** 148 * The raw (unresolved) {@code @Rest(debugMarshalling)} default — whether REST-driven serializer/parser debug 149 * behavior is enabled. 150 * 151 * <p> 152 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 153 * 154 * @return The raw value. Never <jk>null</jk>. 155 */ 156 public String getDebugMarshallingRaw() { 157 return debugMarshalling; 158 } 159 160 /** 161 * The raw (unresolved) {@code @Rest(virtualThreads)} default — whether per-request virtual-thread dispatch is 162 * opted into on Java 21+. 163 * 164 * <p> 165 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 166 * 167 * @return The raw value. Never <jk>null</jk>. 168 */ 169 public String getVirtualThreadsRaw() { 170 return virtualThreads; 171 } 172 173 /** 174 * The raw (unresolved) default controlling whether the server writes W3C {@code traceparent} / {@code tracestate} 175 * response headers when a tracer is active. Defaults to {@code "true"}. 176 * 177 * <p> 178 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 179 * 180 * @return The raw value. Never <jk>null</jk>. 181 */ 182 public String getResponseTraceparentRaw() { 183 return responseTraceparent; 184 } 185 186 /** 187 * The raw (unresolved) default controlling whether the request thread's SLF4J MDC map is propagated to 188 * asynchronous completion threads. Defaults to {@code "true"}. 189 * 190 * <p> 191 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 192 * 193 * @return The raw value. Never <jk>null</jk>. 194 */ 195 public String getMdcAsyncPropagationRaw() { 196 return mdcAsyncPropagation; 197 } 198 199 /** 200 * The raw (unresolved) {@code @Rest(eagerInit)} default — whether framework beans are force-initialized 201 * during construction. 202 * 203 * <p> 204 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 205 * 206 * @return The raw value. Never <jk>null</jk>. 207 */ 208 public String getEagerInitRaw() { 209 return eagerInit; 210 } 211 212 /** 213 * The raw (unresolved) {@code @Rest(lazyChildren)} default — whether child-context construction is deferred. 214 * 215 * <p> 216 * Stored verbatim; {@link RestContext} owns SVL resolution and boolean parsing (see {@link #getDisableContentParamRaw()}). 217 * 218 * @return The raw value. Never <jk>null</jk>. 219 */ 220 public String getLazyChildrenRaw() { 221 return lazyChildren; 222 } 223 224 /** 225 * The default request header used for client-version matching ({@code @Rest(clientVersionHeader)}). 226 * 227 * @return The value. Never <jk>null</jk>. 228 */ 229 public String getClientVersionHeader() { 230 return clientVersionHeader; 231 } 232 233 /** 234 * The raw (unresolved) {@code @Rest(uriRelativity)} default value. Blank means unset. 235 * 236 * <p> 237 * The value is stored verbatim — without SVL variable resolution or enum conversion — because SVL 238 * resolution requires the resource's var resolver, which this bean does not carry. {@link RestContext} reads 239 * this raw value, resolves any SVL variables, and applies lenient enum parsing. 240 * 241 * @return The raw value. Never <jk>null</jk>. 242 */ 243 public String getUriRelativityRaw() { 244 return uriRelativity; 245 } 246 247 /** 248 * The raw (unresolved) {@code @Rest(uriResolution)} default value. Blank means unset. 249 * 250 * <p> 251 * The value is stored verbatim — without SVL variable resolution or enum conversion — because SVL 252 * resolution requires the resource's var resolver, which this bean does not carry. {@link RestContext} reads 253 * this raw value, resolves any SVL variables, and applies lenient enum parsing. 254 * 255 * @return The raw value. Never <jk>null</jk>. 256 */ 257 public String getUriResolutionRaw() { 258 return uriResolution; 259 } 260}