| <!DOCTYPE HTML> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc --> |
| <title>RestInit (Apache Juneau 9.0.0)</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta name="description" content="declaration: package: org.apache.juneau.rest.annotation, annotation type: RestInit"> |
| <meta name="generator" content="javadoc/AnnotationTypeWriterImpl"> |
| <link rel="stylesheet" type="text/css" href="../../../../../javadoc.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.css" title="Style"> |
| <script type="text/javascript" src="../../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jszip/dist/jszip.min.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jszip-utils/dist/jszip-utils.min.js"></script> |
| <!--[if IE]> |
| <script type="text/javascript" src="../../../../../script-dir/jszip-utils/dist/jszip-utils-ie.min.js"></script> |
| <![endif]--> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-3.4.1.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-ui.js"></script> |
| </head> |
| <body class="class-declaration"> |
| <script type="text/javascript">var pathtoroot = "../../../../../"; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <div class="flexBox"> |
| <header role="banner" class="flexHeader"> |
| <nav role="navigation"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a id="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../index.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <div class="navListSearch"><label for="search">SEARCH:</label> |
| <input type="text" id="search" value="search" disabled="disabled"> |
| <input type="reset" id="reset" value="reset" disabled="disabled"> |
| </div> |
| </div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <div class="skipNav"><a id="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| </nav> |
| </header> |
| <div class="flexContent"> |
| <main role="main"> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">org.apache.juneau.rest.annotation</a></div> |
| <h1 title="Annotation Type RestInit" class="title">Annotation Type RestInit</h1> |
| </div> |
| <div class="contentContainer"> |
| <section class="description"> |
| <hr> |
| <pre>@Target({METHOD,TYPE}) |
| @Retention(RUNTIME) |
| @Inherited |
| @Repeatable(<a href="RestInitAnnotation.Array.html" title="annotation in org.apache.juneau.rest.annotation">Array.class</a>) |
| public @interface <a href="../../../../../src-html/org/apache/juneau/rest/annotation/RestInit.html#line.78">RestInit</a></pre> |
| <div class="block">Identifies a method that gets called during servlet initialization. |
| |
| <p> |
| This method is called from within the <code>Servlet.init(ServletConfig)</code> method after the <a href="../RestContext.Builder.html" title="class in org.apache.juneau.rest"><code>RestContext.Builder</code></a> |
| object has been created and initialized with the annotations defined on the class, but before the |
| <a href="../RestContext.html" title="class in org.apache.juneau.rest"><code>RestContext</code></a> object has been created. |
| |
| <p> |
| The only valid parameter type for this method is <a href="../RestContext.Builder.html" title="class in org.apache.juneau.rest"><code>RestContext.Builder</code></a> which can be used to configure the servlet. |
| |
| <p> |
| An example of this is the <c>PetStoreResource</c> class that uses an init method to perform initialization |
| of an internal data structure. |
| |
| <h5 class='figure'>Example:</h5> |
| <p class='bjava'> |
| <ja>@Rest</ja>(...) |
| <jk>public class</jk> PetStoreResource <jk>extends</jk> BasicRestServlet <jk>implements</jk> BasicUniversalJenaConfig { |
| |
| <jc>// Our database.</jc> |
| <jk>private</jk> Map<Integer,Pet> <jf>petDB</jf>; |
| |
| <ja>@RestInit</ja> |
| <jk>public void</jk> onInit(RestContext.Builder <jv>builder</jv>) <jk>throws</jk> Exception { |
| <jc>// Load our database from a local JSON file.</jc> |
| <jf>petDB</jf> = JsonParser.<jsf>DEFAULT</jsf>.parse(getClass().getResourceAsStream(<js>"PetStore.json"</js>), LinkedHashMap.<jk>class</jk>, Integer.<jk>class</jk>, Pet.<jk>class</jk>); |
| } |
| } |
| </p> |
| |
| <ul class='notes'> |
| <li class='note'> |
| The method should return <jk>void</jk> although if it does return any value, the value will be ignored. |
| <li class='note'> |
| The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it. |
| <li class='note'> |
| Static methods can be used. |
| <li class='note'> |
| Multiple init methods can be defined on a class. |
| <br>Init methods on parent classes are invoked before init methods on child classes. |
| <br>The order of init method invocations within a class is alphabetical, then by parameter count, then by parameter types. |
| <li class='note'> |
| The method can throw any exception causing initialization of the servlet to fail. |
| <li class='note'> |
| Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>. |
| <br>The method is still considered part of the parent class for ordering purposes even though it's |
| overridden by the child class. |
| </ul> |
| |
| <ul class='seealso'> |
| <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.jrs.AnnotatedClasses.jrs.LifecycleHooks">Lifecycle Hooks</a> |
| </ul></div> |
| </section> |
| <section class="summary"> |
| <ul class="blockList"> |
| <!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== --> |
| <li class="blockList"> |
| <section class="memberSummary"><a id="annotation.type.optional.element.summary"> |
| <!-- --> |
| </a> |
| <h2>Optional Element Summary</h2> |
| <div class="memberSummary"> |
| <table> |
| <caption><span>Optional Elements</span><span class="tabEnd"> </span></caption> |
| <thead> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colSecond" scope="col">Optional Element</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="altColor"> |
| <td class="colFirst"><code>java.lang.String[]</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#on()">on</a></span></code></th> |
| <td class="colLast"> |
| <div class="block">Dynamically apply this annotation to the specified methods.</div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </section> |
| </li> |
| </ul> |
| </section> |
| <section class="details"> |
| <ul class="blockList"> |
| <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> |
| <li class="blockList"> |
| <section class="memberDetails"><a id="annotation.type.element.detail"> |
| <!-- --> |
| </a> |
| <h2>Element Details</h2> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <section class="detail"> |
| <h3><a id="on()">on</a></h3> |
| <div class="memberSignature"><span class="returnType">java.lang.String[]</span> <span class="memberName"><a href="../../../../../src-html/org/apache/juneau/rest/annotation/RestInit.html#line.93">on</a></span></div> |
| <div class="block">Dynamically apply this annotation to the specified methods. |
| |
| <ul class='seealso'> |
| <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-marshall.jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> |
| </ul></div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>The annotation value.</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>{}</dd> |
| </dl> |
| </section> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </section> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| </main> |
| <footer role="contentinfo"> |
| <nav role="navigation"> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a id="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../index.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| </div> |
| <a id="skip.navbar.bottom"> |
| <!-- --> |
| </a> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </nav> |
| <p class="legalCopy"><small>Copyright © 2016–2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p> |
| </footer> |
| </div> |
| </div> |
| </body> |
| </html> |