blob: 6c0671c53cf85f0d933af0f8fcd121af7f160327 [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.
***************************************************************************************************************************/
-->
Static files
<p>
The {@link oajr.annotation.Rest#staticFiles @Rest(staticFiles)}
annotation is used to define paths and locations of statically-served files such as images or HTML
documents.
</p>
<p>
The value is a JSON map of paths to packages/directories located on either the classpath or working
directory.
</p>
<h5 class='figure'>Example:</h5>
<p class='bpcode w800'>
<jk>package</jk> com.foo.mypackage;
<ja>@Rest</ja>(
path=<js>"/myresource"</js>,
staticFiles={<js>"htdocs:docs"</js>}
)
<jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet {...}
</p>
<p>
Static files are found by calling {@link java.lang.Class#getResource(String)} up the class hierarchy.
If not found, then an attempt is made to find the class in the Java working directory.
</p>
<p>
In the example above, given a GET request to <l>/myresource/htdocs/foobar.html</l>, the servlet will
attempt to find the <l>foobar.html</l> file in the following ordered locations:
</p>
<ol>
<li><l>com.foo.mypackage.docs</l> package.
<li><l>[working-dir]/docs</l> directory.
</ol>
<ul class='notes'>
<li>
Mappings are cumulative from parent to child.
<br>Child resources can override mappings made on parent resources.
<li>
The media type on the response is determined by the
{@link oajr.RestContext#getMediaTypeForName(String)} method.
</ul>
<ul class='seealso'>
<li class='jf'>{@link oajr.RestContext#REST_staticFiles}
</ul>