blob: 1fda6557eef75f08bc4423027b51c3990fde0b8f [file] [log] [blame]
<!--
/***************************************************************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
***************************************************************************************************************************/
-->
{8.0.0-new,8.1.2-deprecated}
Installing in Eclipse
<p>
Follow these instructions to import the REST examples project using Jetty into Eclipse.
</p>
<ol class='spaced-list'>
<li>
Download the <c>juneau-examples-rest-jetty-{@property juneauVersion}.zip</c> file from the downloads page
(located in the binaries) and import it into your workspace as an existing project:
<br><br>
<img class='bordered' src='doc-files/juneau-examples-rest-jetty.Installing.1.png' style='width:524px'>
<li>
Select the archive file and import the project:
<br><br>
<img class='bordered' src='doc-files/juneau-examples-rest-jetty.Installing.2.png' style='width:549px'>
<li>
In your workspace, you should now see the following project:
<br><br>
<img class='bordered' src='doc-files/juneau-examples-rest-jetty.Installing.3.png' style='width:400px'>
</ol>
<p>
The important elements in this project are:
</p>
<ul class='spaced-list'>
<li>
<l>App.java</l> - The entry point.
<br>This class creates and starts our microservice:
<br><br>
<p class='bcode w800'>
<jk>public class</jk> App {
<jk>public static void</jk> main(String[] args) <jk>throws</jk> Exception {
JettyMicroservice
.<jsm>create</jsm>()
.args(args)
.servlet(RootResources.<jk>class</jk>)
.build()
.start()
.startConsole()
.join();
}
}
</p>
<li>
<l>RootResources.java</l> - The top-level REST resource.
<br>This class routes HTTP requests to child resources:
<br><br>
<p class='bcode w800'>
<ja>@Rest</ja>(
path=<js>"/*"</js>,
title=<js>"Root resources"</js>,
description=<js>"Example of a router resource page."</js>,
htmldoc=<ja>@HtmlDoc</ja>(
widgets={
ContentTypeMenuItem.<jk>class</jk>,
ThemeMenuItem.<jk>class</jk>
},
navlinks={
<js>"options: ?method=OPTIONS"</js>,
<js>"$W{ContentTypeMenuItem}"</js>,
<js>"$W{ThemeMenuItem}"</js>,
<js>"source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java"</js>
},
aside={
<js>"&lt;div style='max-width:400px' class='text'&gt;"</js>,
<js>" &lt;p&gt;This is an example of a 'router' page that serves as a jumping-off point to child resources.&lt;/p&gt;"</js>,
<js>" &lt;p&gt;Resources can be nested arbitrarily deep through router pages.&lt;/p&gt;"</js>,
<js>" &lt;p&gt;Note the &lt;span class='link'&gt;options&lt;/span&gt; link provided that lets you see the generated swagger doc for this page.&lt;/p&gt;"</js>,
<js>" &lt;p&gt;Also note the &lt;span class='link'&gt;sources&lt;/span&gt; link on these pages to view the source code for the page.&lt;/p&gt;"</js>,
<js>" &lt;p&gt;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'.&lt;/p&gt;"</js>,
<js>" &lt;p&gt;Other features (such as this aside) are added through annotations.&lt;/p&gt;"</js>,
<js>"&lt;/div&gt;"</js>
}
),
children={
HelloWorldResource.<jk>class</jk>,
PetStoreResource.<jk>class</jk>,
DtoExamples.<jk>class</jk>,
ConfigResource.<jk>class</jk>,
LogsResource.<jk>class</jk>,
ShutdownResource.<jk>class</jk>
}
)
<ja>@SerializerConfig</ja>(
<jc>// For testing purposes, we want to use single quotes in all the serializers so it's easier to do simple
// String comparisons.</jc>
quoteChar=<js>"'"</js>
)
<jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletJenaGroup {
<jc>// No code</jc>
}
</p>
<li>
<l>juneau-examples-rest-jetty.cfg</l> - The external configuration file.
<br>Contains various useful settings.
<br>Can be used for your own resource configurations.
<br><br>
<p class='bcode w800'>
<cc>#=======================================================================================================================
# Basic configuration file for REST microservices
# Subprojects can use this as a starting point.
#=======================================================================================================================</cc>
<cc>#=======================================================================================================================
# Jetty settings
#=======================================================================================================================</cc>
<cs>[Jetty]</cs>
<cc># Path of the jetty.xml file used to configure the Jetty server.</cc>
<ck>config</ck> = <cv>jetty.xml</cv>
<cc># Resolve Juneau variables in the jetty.xml file.</cc>
<ck>resolveVars</ck> = <cv>true</cv>
<cc># 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).</cc>
<ck>port</ck> = <cv>10000,0,0,0</cv>
<cc># Optionally specify your servlets here:
#servlets = org.apache.juneau.microservice.sample.RootResources</cc>
<cc>#=======================================================================================================================
# REST settings
#=======================================================================================================================</cc>
<cs>[REST]</cs>
<cc># Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-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}"</cc>
<ck>staticFiles</ck> = htdocs:htdocs
<cc># 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}"</cc>
<ck>theme</ck> = <cv>servlet:/htdocs/themes/devops.css</cv>
<cc># Various look-and-feel settings used in the BasicRestConfig interface.</cc>
<ck>headerIcon</ck> = <cv>servlet:/htdocs/images/juneau.png</cv>
<ck>headerLink</ck> = <cv>http://juneau.apache.org</cv>
<ck>footerIcon</ck> = <cv>servlet:/htdocs/images/asf.png</cv>
<ck>footerLink</ck> = <cv>http://www.apache.org</cv>
<ck>favicon</ck> = <cv>$C{REST/headerIcon}</cv>
<ck>header</ck> =
<cv>&lt;a href='$U{$C{REST/headerLink}}'&gt;
&lt;img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/&gt;
&lt;/a&gt;</cv>
<ck>footer</ck> =
<cv>&lt;a href='$U{$C{REST/footerLink}}'&gt;
&lt;img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/&gt;
&lt;/a&gt;</cv>
<cc>#=======================================================================================================================
# Console settings
#=======================================================================================================================</cc>
<cs>[Console]</cs>
<ck>enabled</ck> = <cv>true</cv>
<cc># 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.</cc>
<ck>commands</ck> =
<cv>org.apache.juneau.microservice.console.ExitCommand,
org.apache.juneau.microservice.console.RestartCommand,
org.apache.juneau.microservice.console.HelpCommand,
org.apache.juneau.microservice.console.ConfigCommand</cv>
<cc>#=======================================================================================================================
# Logger settings
#-----------------------------------------------------------------------------------------------------------------------
# See FileHandler Java class for details.
#=======================================================================================================================</cc>
<cs>[Logging]</cs>
...
<cc>#=======================================================================================================================
# System properties
#-----------------------------------------------------------------------------------------------------------------------
# These are arbitrary system properties that are set during startup.
#=======================================================================================================================</cc>
<cs>[SystemProperties]</cs>
<cc># Configure Jetty for StdErrLog Logging
# org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog</cc>
<cc># Configure Jetty to log using java-util logging</cc>
<ck>org.eclipse.jetty.util.log.class</ck> = <cv>org.apache.juneau.microservice.jetty.JettyLogger</cv>
<cc># Jetty logging level
# Possible values: ALL, DEBUG, INFO, WARN, OFF</cc>
<ck>org.eclipse.jetty.LEVEL</ck> = <cv>WARN
<ck>derby.stream.error.file</ck> = <cv>$C{Logging/logDir}/derby-errors.log</cv>
</p>
<li>
<l>jetty.xml</l> - The Jetty configuration file.
<br>A bare-bones config file that can be extended to use any Jetty features.
<br><br>
<p class='bcode w800'>
<xt>&lt;Configure</xt> <xa>id</xa>=<xs>"ExampleServer"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.server.Server"</xs>&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"connectors"</xs><xt>&gt;</xt>
<xt>&lt;Array</xt> <xa>type</xa>=<xs>"org.eclipse.jetty.server.Connector"</xs><xt>&gt;</xt>
<xt>&lt;Item&gt;</xt>
<xt>&lt;New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.ServerConnector"</xs><xt>&gt;</xt>
<xt>&lt;Arg&gt;</xt>
<xt>&lt;Ref</xt> <xa>refid</xa>=<xs>"ExampleServer"</xs><xt>/&gt;</xt>
<xt>&lt;/Arg&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"port"</xs><xt>&gt;</xt>$S{availablePort,8080}<xt>&lt;/Set&gt;</xt>
<xt>&lt;/New&gt;</xt>
<xt>&lt;/Item&gt;</xt>
<xt>&lt;/Array&gt;</xt>
<xt>&lt;/Set&gt;</xt>
<xt>&lt;New</xt> <xa>id</xa>=<xs>"context"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.servlet.ServletContextHandler"</xs><xt>&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"contextPath"</xs><xt>&gt;/&lt;/Set&gt;</xt>
<xc>&lt;!-- Optionally specify your servlets here --&gt;
&lt;!--Call name="addServlet"&gt;
&lt;Arg&gt;org.apache.juneau.microservice.sample.RootResources&lt;/Arg&gt;
&lt;Arg&gt;/*&lt;/Arg&gt;
&lt;/Call--&gt;</xc>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"sessionHandler"</xs><xt>&gt;</xt>
<xt>&lt;New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.session.SessionHandler"</xs><xt>/&gt;</xt>
<xt>&lt;/Set&gt;</xt>
<xt>&lt;/New&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"handler"</xs><xt>&gt;</xt>
<xt>&lt;New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.handler.HandlerCollection"</xs><xt>&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"handlers"</xs><xt>&gt;</xt>
<xt>&lt;Array</xt> <xa>type</xa>=<xs>"org.eclipse.jetty.server.Handler"</xs><xt>&gt;</xt>
<xt>&lt;Item&gt;</xt>
<xt>&lt;Ref</xt> <xa>refid</xa>=<xs>"context"</xs><xt>/&gt;</xt>
<xt>&lt;/Item&gt;</xt>
<xt>&lt;Item&gt;</xt>
<xt>&lt;New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.handler.DefaultHandler"</xs><xt>/&gt;</xt>
<xt>&lt;/Item&gt;</xt>
<xt>&lt;/Array&gt;</xt>
<xt>&lt;/Set&gt;</xt>
<xt>&lt;/New&gt;</xt>
<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"requestLog"</xs><xt>&gt;</xt>
<xt>&lt;New</xt> <xa>id</xa>=<xs>"RequestLogImpl"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.server.NCSARequestLog"</xs><xt>&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"filename"</xs><xt>&gt;&lt;Property</xt> <xa>name</xa>=<xs>"jetty.logs"</xs> <xa>default</xa>=<xs>"$C{Logging/logDir,logs}"</xs><xt>/&gt;</xt>/jetty-requests.log<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"filenameDateFormat</xs><xt>"&gt;</xt>yyyy_MM_dd<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"LogTimeZone"</xs><xt>&gt;</xt>GMT<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"retainDays"</xs><xt>&gt;</xt>90<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"append"</xs><xt>&gt;</xt>false<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"LogLatency"</xs><xt>&gt;</xt>true<xt>&lt;/Set&gt;</xt>
<xt>&lt;/New&gt;</xt>
<xt>&lt;/Set&gt;</xt>
<xt>&lt;Get</xt> <xa>name</xa>=<xs>"ThreadPool"</xs><xt>&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"minThreads"</xs> <xa>type</xa>=<xs>"int"</xs><xt>&gt;</xt>10<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"maxThreads"</xs> <xa>type</xa>=<xs>"int"</xs><xt>&gt;</xt>100<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"idleTimeout"</xs> <xa>type</xa>=<xs>"int"</xs><xt>&gt;</xt>60000<xt>&lt;/Set&gt;</xt>
<xt>&lt;Set</xt> <xa>name</xa>=<xs>"detailedDump"</xs><xt>&gt;</xt>true<xt>&lt;/Set&gt;</xt>
<xt>&lt;/Get&gt;</xt>
<xt>&lt;/Configure&gt;</xt>
</p>
</ul>
<p>
At this point, you're ready to start the microservice from your workspace.
</p>