Create a new proxy interface against a 3rd-party REST interface.
The URL to the REST interface is based on the following values:
- The
RemoteResource#path() annotation on the interface (
remote-path
).
- The
RestClientBuilder#rootUrl(Object) on the client (
root-url
).
- The fully-qualified class name of the interface (
class-name
).
The URL calculation is as follows:
remote-path
- If remote path is absolute.
root-url/remote-path
- If remote path is relative and root-url has been specified.
root-url/class-name
- If remote path is not specified.
If the information is not available to resolve to an absolute URL, a
RemoteMetadataException is thrown.
Examples:
package org.apache.foo;
@RemoteResource(path="http://hostname/resturl/myinterface1")
public interface MyInterface1 { ... }
@RemoteResource(path="/myinterface2")
public interface MyInterface2 { ... }
public interface MyInterface3 { ... }
// Resolves to "http://localhost/resturl/myinterface1"
MyInterface1 i1 = RestClient
.create()
.build()
.getRemoteResource(MyInterface1.class);
// Resolves to "http://hostname/resturl/myinterface2"
MyInterface2 i2 = RestClient
.create()
.rootUrl("http://hostname/resturl")
.build()
.getRemoteResource(MyInterface2.class);
// Resolves to "http://hostname/resturl/org.apache.foo.MyInterface3"
MyInterface3 i3 = RestClient
.create()
.rootUrl("http://hostname/resturl")
.build()
.getRemoteResource(MyInterface3.class);
Notes:
-
If you plan on using your proxy in a multi-threaded environment, you'll want to use an underlying
pooling client connection manager.
The easiest way to do this is to use the
RestClientBuilder#pooled() method.
If you don't do this, you may end up seeing "Connection still allocated" exceptions.