| <!-- |
| /*************************************************************************************************************************** |
| * 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. |
| ***************************************************************************************************************************/ |
| --> |
| |
| RestContext |
| |
| <p> |
| The {@link oajr.RestContext} object is the workhorse class for all of the configuration |
| of a single REST resource class. |
| It's by-far the most important class in the REST API. |
| </p> |
| <p> |
| Every class annotated with <l>@Rest</l> ends up with an instance of this object. |
| The object itself is read-only and unchangeable. |
| It is populated through the following: |
| </p> |
| <ul class='javatree'> |
| <li class='ja'>{@link oajr.annotation.Rest} - Settings copied from the annotation during servlet initialization. |
| <li class='jm'>{@link oajr.RestContextBuilder} - Builder used during servlet initialization. |
| </ul> |
| <p> |
| The annotation should be self-explanatory at this point. |
| The builder allows you to perform all of the same configuration as the annotation programmatically. |
| </p> |
| <p> |
| The {@link oajr.RestContextBuilder} class extends {@link oaj.BeanContextBuilder} |
| allowing you to programmatically set any properties defined on that builder class. |
| It also implements {@link javax.servlet.ServletConfig} |
| </p> |
| <p> |
| To access this object, simply pass it in as a constructor argument or in an INIT hook: |
| </p> |
| <p class='bpcode w800'> |
| <jc>// Option #1 - Pass in through constructor.</jc> |
| <jk>public</jk> MyResource(RestContextBuilder builder) { |
| builder |
| .pojoSwaps(TemporalCalendarSwap.Rfc1123DateTime.<jk>class</jk>) |
| .set(<jsf>PARSER_debug</jsf>, <jk>true</jk>); |
| } |
| |
| <jc>// Option #2 - Use an INIT hook.</jc> |
| <ja>@RestHook</ja>(<jsf>INIT</jsf>) |
| <jk>public void</jk> init(RestContextBuilder builder) <jk>throws</jk> Exception { |
| builder |
| .pojoSwaps(TemporalCalendarSwap.Rfc1123DateTime.<jk>class</jk>) |
| .set(<jsf>PARSER_debug</jsf>, <jk>true</jk>); |
| } |
| </p> |
| <p> |
| Warning: The builder class is huge. |
| Through it, you can configure bean/serializer/parser settings, define config files, children, |
| resource finders, info providers, etc... |
| </p> |