blob: e2f70d57f409df3c7b92dd6f2eb01e1ad820bb9f [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.
***************************************************************************************************************************/
-->
Default Headers
<p>
The following annotations are provided for specifying default header values for requests and responses:
</p>
<ul class='javatree'>
<li class='ja'>
{@link oajr.annotation.Rest#defaultRequestHeaders() Rest(defaultRequestHeaders)}
<br>Defines default headers on request when the client doesn't specify them.
<li class='ja'>
{@link oajr.annotation.Rest#defaultResponseHeaders() Rest(defaultResponseHeaders)}
<br>Appends the specified headers if they weren't already set programmatically.
</ul>
<h5 class='figure'>Example:</h5>
<p class='bpcode w800'>
<jc>// Servlet with default headers</jc>
<ja>@Rest</ja>(
<jc>// Assume "text/json" Accept value when Accept not specified</jc>
defaultRequestHeaders={<js>"Accept: text/json"</js>},
<jc>// Add a version header attribute to all responses</jc>
defaultResponseHeaders={<js>"X-Version: 1.0"</js>}
)
<jk>public</jk> MyRestServlet <jk>extends</jk> BasicRestServlet {
...
}
</p>
<p>
Default headers can also be specified programmatically by overriding the following methods:
</p>
<ul class='javatree'>
<li class='jac'>
{@link oajr.RestContextBuilder}
<ul>
<li class='jm'>
{@link oajr.RestContextBuilder#defaultRequestHeaders(String[])}
<li class='jm'>
{@link oajr.RestContextBuilder#defaultResponseHeaders(String[])}
</ul>
</li>
</ul>