Class ConfigResource
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.juneau.rest.server.servlet.RestServlet
org.apache.juneau.rest.server.servlet.BasicRestServlet
org.apache.juneau.microservice.examples.ConfigResource
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
Shows contents of the microservice configuration file, and updates it.
Reads are GETs. Writes are PUTs only, sent by a REST client or from the command line; there is no
HTML edit form, because a browser form cannot carry the header-borne token a CSRF boundary requires. A PUT
cannot be sent cross-site without a CORS preflight, so a boundary in front of this resource (see
AdminBoundary) admits it without a token:
curl -X PUT -H 'Content-Type: text/plain' --data-binary @my.cfg http://localhost:10000/config curl -X PUT -H 'Content-Type: text/plain' -d 'newValue' http://localhost:10000/config/MySection/myKey
A GET returns the whole configuration, including any secrets in it, and this resource has no
authentication of its own. Do not expose it on an untrusted network.
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetConfigEntry(String section, String key) getConfigSection(String section) setConfigContents(Reader contents) setConfigSection(String section, Map<String, Object> contents) setConfigValue(String section, String key, String value) Methods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
ConfigResource
public ConfigResource()
-
-
Method Details
-
getConfig
-
getConfigEntry
public String getConfigEntry(@Path("section") @Schema(d="Section name in config file.") String section, @Path("key") @Schema(d="Key name in section.") String key) throws org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound - Throws:
org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound
-
getConfigSection
public JsonMap getConfigSection(@Path("section") @Schema(d="Section name in config file.") String section) throws org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound - Throws:
org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound
-
setConfigContents
public JsonMap setConfigContents(@Content @Schema(d="New contents in INI file format.") Reader contents) throws Exception - Throws:
Exception
-
setConfigSection
public JsonMap setConfigSection(@Path("section") @Schema(d="Section name in config file.") String section, @Content @Schema(d="New contents of config section as a simple map of key/value pairs.") Map<String, Object> contents) throws Exception- Throws:
Exception
-
setConfigValue
public String setConfigValue(@Path("section") @Schema(d="Section name in config file.") String section, @Path("key") @Schema(d="Key name in section.") String key, @Content @Schema(d="New value for entry.") String value) throws org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound - Throws:
org.apache.juneau.microservice.examples.ConfigResource.SectionNotFound
-