blob: ba419926689e8f2289d38b2ab57e7f80564d4ad6 [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.
***************************************************************************************************************************/
-->
{new: 8.2.0; todo}
Interceptors
<p>
The {@link oajr.client2.RestCallInterceptor} API provides a quick way of intercepting and manipulating requests and responses beyond
the existing {@link org.apache.http.protocol.HttpRequestInterceptor} and {@link org.apache.http.protocol.HttpResponseInterceptor} APIs.
</p>
<ul class='javatree'>
<li class='jc'>{@link oajr.client2.RestClientBuilder}
<ul>
<li class='jm'>{@link oajr.client2.RestClientBuilder#interceptors(Object...) interceptors(Object...)}
</ul>
<li class='jc'>{@link oajr.client2.RestRequest}
<ul>
<li class='jm'>{@link oajr.client2.RestRequest#interceptors(RestCallInterceptor...) interceptors(RestCallInterceptor...)}
</ul>
<li class='jic'>{@link oajr.client2.RestCallInterceptor}
<ul>
<li class='jm'>{@link oajr.client2.RestCallInterceptor#onInit(RestRequest) onInit(RestRequest)}
<li class='jm'>{@link oajr.client2.RestCallInterceptor#onConnect(RestRequest,RestResponse) onConnect(RestRequest,RestResponse)}
<li class='jm'>{@link oajr.client2.RestCallInterceptor#onClose(RestRequest,RestResponse) onClose(RestRequest,RestResponse)}
</ul>
</ul>
<h5 class='section'>Example:</h5>
<p class='bpcode w800'>
<jc>// Create a client with a customized interceptor.</jc>
RestClient <jv>client</jv> = RestClient
.<jsm>create</jsm>()
.interceptors(
<jk>new</jk> RestCallInterceptor() {
<ja>@Override</ja>
<jk>public void</jk> onInit(RestRequest <jv>req</jv>) <jk>throws</jk> Exception {
<jc>// Intercept immediately after RestRequest object is created and all headers/query/form-data has been
// set on the request from the client.</jc>
}
<ja>@Override</ja>
<jk>public void</jk> onConnect(RestRequest <jv>req</jv>, RestResponse <jv>res</jv>) <jk>throws</jk> Exception {
<jc>// Intercept immediately after an HTTP response has been received.</jc>
}
<ja>@Override</ja>
<jk>public void</jk> onClose(RestRequest <jv>req</jv>, RestResponse <jv>res</jv>) <jk>throws</jk> Exception {
<jc>// Intercept when the response body is consumed.</jc>
}
}
)
.build();
</p>