RootResources.java - The top-level REST resource.
This class routes HTTP requests to child resources:
@RestResource(
path="/*",
title="Root resources",
description="Example of a router resource page.",
htmldoc=@HtmlDoc(
widgets={
ContentTypeMenuItem.class,
ThemeMenuItem.class
},
navlinks={
"options: ?method=OPTIONS",
"$W{ContentTypeMenuItem}",
"$W{ThemeMenuItem}",
"source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java"
},
aside={
"<div style='max-width:400px' class='text'>",
" <p>This is an example of a 'router' page that serves as a jumping-off point to child resources.</p>",
" <p>Resources can be nested arbitrarily deep through router pages.</p>",
" <p>Note the <span class='link'>options</span> link provided that lets you see the generated swagger doc for this page.</p>",
" <p>Also note the <span class='link'>sources</span> link on these pages to view the source code for the page.</p>",
" <p>All content on pages in the UI are serialized POJOs. In this case, it's a serialized array of beans with 2 properties, 'name' and 'description'.</p>",
" <p>Other features (such as this aside) are added through annotations.</p>",
"</div>"
}
),
properties={
// For testing purposes, we want to use single quotes in all the serializers so it's easier to do simple
// String comparisons.
// You can apply any of the Serializer/Parser/BeanContext settings this way.
@Property(name=WSERIALIZER_quoteChar, value="'")
},
children={
HelloWorldResource.class,
PetStoreResource.class,
DtoExamples.class,
ConfigResource.class,
LogsResource.class,
ShutdownResource.class
}
)
public class RootResources extends BasicRestServletJenaGroup {
// No code
}
juneau-examples-rest-jetty.cfg - The external configuration file.
Contains various useful settings.
Can be used for your own resource configurations.
#=======================================================================================================================
# Basic configuration file for REST microservices
# Subprojects can use this as a starting point.
#=======================================================================================================================
#=======================================================================================================================
# Jetty settings
#=======================================================================================================================
[Jetty]
# Path of the jetty.xml file used to configure the Jetty server.
config = jetty.xml
# Resolve Juneau variables in the jetty.xml file.
resolveVars = true
# Port to use for the jetty server.
# You can specify multiple ports. The first available will be used. '0' indicates to try a random port.
# The resulting available port gets set as the system property "availablePort" which can be referenced in the
# jetty.xml file as "$S{availablePort}" (assuming resolveVars is enabled).
port = 10000,0,0,0
# Optionally specify your servlets here:
#servlets = org.apache.juneau.microservice.sample.RootResources
#=======================================================================================================================
# REST settings
#=======================================================================================================================
[REST]
# Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @RestResource-annotated
# classes. These are static files that are served up by the servlet under the specified sub-paths.
# For example, given the following setting...
# staticFiles = htdocs:my-docs,styles/my-styles
# ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css".
# This path can be relative to the working directory, classpath root, or package of your resource class.
# Used by the BasicRestConfig interface that defines the following value:
# staticFiles="$C{REST/staticFiles}"
staticFiles = htdocs:htdocs
# Stylesheet to use for HTML views.
# Used by the BasicRestConfig interface that defines the following value:
# stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}"
theme = servlet:/htdocs/themes/devops.css
# Various look-and-feel settings used in the BasicRestConfig interface.
headerIcon = servlet:/htdocs/images/juneau.png
headerLink = http://juneau.apache.org
footerIcon = servlet:/htdocs/images/asf.png
footerLink = http://www.apache.org
favicon = $C{REST/headerIcon}
header =
<a href='$U{$C{REST/headerLink}}'>
<img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/>
</a>
footer =
<a href='$U{$C{REST/footerLink}}'>
<img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/>
</a>
#=======================================================================================================================
# Console settings
#=======================================================================================================================
[Console]
enabled = true
# List of available console commands.
# These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via
# the console.
# When listed here, the implementations must provide a no-arg constructor.
# They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method.
commands =
org.apache.juneau.microservice.console.ExitCommand,
org.apache.juneau.microservice.console.RestartCommand,
org.apache.juneau.microservice.console.HelpCommand,
org.apache.juneau.microservice.console.ConfigCommand
#=======================================================================================================================
# Logger settings
#-----------------------------------------------------------------------------------------------------------------------
# See FileHandler Java class for details.
#=======================================================================================================================
[Logging]
...
#=======================================================================================================================
# System properties
#-----------------------------------------------------------------------------------------------------------------------
# These are arbitrary system properties that are set during startup.
#=======================================================================================================================
[SystemProperties]
# Configure Jetty for StdErrLog Logging
# org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog
# Configure Jetty to log using java-util logging
org.eclipse.jetty.util.log.class = org.apache.juneau.microservice.jetty.JettyLogger
# Jetty logging level
# Possible values: ALL, DEBUG, INFO, WARN, OFF
org.eclipse.jetty.LEVEL = WARN
derby.stream.error.file = $C{Logging/logDir}/derby-errors.log