R
- the response type, i.e. the type of the objectRef sent from the server back to the client.public abstract class AbstractRequest<R> extends Object implements Request<R>
Implementors are encouraged to sub-class AbstractRequest
or VoidRequest
instead of
directly implementing Request
.
Constructor and Description |
---|
AbstractRequest() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertResponseIndicatesSuccess(javax.ws.rs.core.Response response) |
protected javax.ws.rs.client.Invocation.Builder |
assignCredentials(javax.ws.rs.client.Invocation.Builder builder) |
protected javax.ws.rs.client.WebTarget |
createWebTarget(String... pathSegments)
Create a
WebTarget from the given path segments. |
protected String |
encodePath(String path)
Encodes the given
path (using urlEncode(String) ) and removes leading & trailing slashes. |
protected String |
getBaseURL()
Get the server's base-URL.
|
protected javax.ws.rs.client.Client |
getClientOrFail() |
LocalServerRestClient |
getLocalServerRestClient()
Gets the
LocalServerRestClient . |
protected LocalServerRestClient |
getLocalServerRestClientOrFail()
Gets the
LocalServerRestClient or throws an exception, if it was not assigned. |
protected String |
getPath(Class<?> dtoClass) |
protected void |
handleException(RuntimeException x) |
void |
setLocalServerRestClient(LocalServerRestClient localServerRestClient)
Sets the
LocalServerRestClient . |
protected void |
throwOriginalExceptionIfPossible(Error error) |
protected static String |
urlEncode(String string)
Encodes the given
string . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
execute, isResultNullable
public AbstractRequest()
public LocalServerRestClient getLocalServerRestClient()
Request
LocalServerRestClient
.
LocalServerRestClient.execute(Request)
assigns this property, before invoking
Request.execute()
. After the invocation, this property is cleared, again.
getLocalServerRestClient
in interface Request<R>
LocalServerRestClient
. Never null
during
execution (but otherwise it normally is null
).Request.setLocalServerRestClient(LocalServerRestClient)
public void setLocalServerRestClient(LocalServerRestClient localServerRestClient)
Request
LocalServerRestClient
.setLocalServerRestClient
in interface Request<R>
localServerRestClient
- the LocalServerRestClient
. May be null
.Request.getLocalServerRestClient()
protected LocalServerRestClient getLocalServerRestClientOrFail()
LocalServerRestClient
or throws an exception, if it was not assigned.
Implementors are encouraged to use this method instead of getLocalServerRestClient()
in their
Request.execute()
method.
LocalServerRestClient
. Never null
.protected void handleException(RuntimeException x)
protected javax.ws.rs.client.Invocation.Builder assignCredentials(javax.ws.rs.client.Invocation.Builder builder)
protected static String urlEncode(String string)
string
.
This method does not use URLEncoder
, because of
JERSEY-417.
The result of this method can be used in both URL-paths and URL-query-parameters.
string
- the String
to be encoded. Must not be null
.String
.protected javax.ws.rs.client.WebTarget createWebTarget(String... pathSegments)
WebTarget
from the given path segments.
This method prefixes the path with the base-URL
and appends
all path segments separated via slashes ('/').
We do not use client.target(getBaseURL()).path("...")
, because the
path(...)
method does not encode curly braces
(which might be part of a file name!).
Instead it resolves them using matrix-parameters.
The matrix-parameters need to be encoded manually, too (at least I tried it and it failed, if I didn't).
Because of these reasons and in order to make the calls more compact, we assemble the path
ourselves here.
pathSegments
- the parts of the path. May be null
. The path segments are
appended to the path as they are. They are not encoded at all! If you require encoding,
use encodePath(String)
or urlEncode(String)
before! Furthermore, all path segments
are separated with a slash inbetween them, but not at the end. If a single path segment
already contains a slash, duplicate slashes might occur.null
.protected String getBaseURL()
This base-URL is the base of the CloudStoreREST
application. Hence all URLs
beneath this base-URL are processed by the CloudStoreREST
application.
In other words: All repository-names are located directly beneath this base-URL. The special services, too, are located directly beneath this base-URL.
For example, if the server's base-URL is "https://host.domain:8443/", then the test-service is available via "https://host.domain:8443/_test" and the repository with the alias "myrepo" is "https://host.domain:8443/myrepo".
protected javax.ws.rs.client.Client getClientOrFail()
protected String encodePath(String path)
path
(using urlEncode(String)
) and removes leading & trailing slashes.
Slashes are not encoded, but retained as they are; only the path segments (the strings between the slashes) are encoded.
Duplicate slashes are removed.
The result of this method can be used in both URL-paths and URL-query-parameters.
For example the input "/some//ex ample///path/" becomes "some/ex%20ample/path".
path
- the path to be encoded. Must not be null
.null
.protected void assertResponseIndicatesSuccess(javax.ws.rs.core.Response response)
protected void throwOriginalExceptionIfPossible(Error error)
Copyright © 2013–2019. All rights reserved.