This is an automated email from the ASF dual-hosted git repository. jamesbognar pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push: new b92c316 MockRestClient improvements. b92c316 is described below commit b92c3169d6c9fc89016a3cfeec19ae182cb0f2af Author: JamesBognar <james.bog...@salesforce.com> AuthorDate: Fri May 29 12:28:37 2020 -0400 MockRestClient improvements. --- .../org/apache/juneau/rest/client2/RestClient.java | 21 +++++++++++++++++++-- .../org/apache/juneau/rest/client2/RestRequest.java | 7 +++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java index b197ef2..27da129 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java @@ -2806,6 +2806,7 @@ public class RestClient extends BeanContext implements HttpClient, Closeable { final String methodUC = method.toUpperCase(Locale.ENGLISH); try { HttpRequestBase reqb = null; + final URI uri = toURI(url); if (hasBody) { reqb = new HttpEntityEnclosingRequestBase() { @Override /* HttpRequest */ @@ -2813,7 +2814,8 @@ public class RestClient extends BeanContext implements HttpClient, Closeable { return methodUC; } }; - req = new RestRequest(this, reqb, toURI(url)); + reqb.setURI(uri); + req = createRequest(reqb); } else { reqb = new HttpRequestBase() { @Override /* HttpRequest */ @@ -2821,7 +2823,8 @@ public class RestClient extends BeanContext implements HttpClient, Closeable { return methodUC; } }; - req = new RestRequest(this, reqb, toURI(url)); + reqb.setURI(uri); + req = createRequest(reqb); } } catch (URISyntaxException e1) { throw new RestCallException(e1); @@ -2842,6 +2845,20 @@ public class RestClient extends BeanContext implements HttpClient, Closeable { } /** + * Creates a {@link RestRequest} object from the specified {@link HttpRequest} object. + * + * <p> + * Subclasses can override this method to provide their own specialized {@link RestRequest} objects. + * + * @param httpRequest The request object to wrap. + * @return A new {@link RestRequest} object. + * @throws RestCallException If an exception or non-200 response code occurred during the connection attempt. + */ + protected RestRequest createRequest(HttpRequestBase httpRequest) throws RestCallException { + return new RestRequest(this, httpRequest); + } + + /** * Create a new proxy interface against a 3rd-party REST interface. * * <p> diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java index 93640ea..b6d300f 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java @@ -61,7 +61,7 @@ import org.apache.juneau.xml.*; * <li class='link'>{@doc juneau-rest-client} * </ul> */ -public final class RestRequest extends BeanSession implements HttpUriRequest, Configurable { +public class RestRequest extends BeanSession implements HttpUriRequest, Configurable { private static final ContentType TEXT_PLAIN = ContentType.create("text/plain"); @@ -89,16 +89,15 @@ public final class RestRequest extends BeanSession implements HttpUriRequest, Co * * @param client The client that created this request. * @param request The wrapped Apache HTTP client request object. - * @param uri The URI for this call. * @throws RestCallException If an exception or non-200 response code occurred during the connection attempt. */ - protected RestRequest(RestClient client, HttpRequestBase request, URI uri) throws RestCallException { + protected RestRequest(RestClient client, HttpRequestBase request) throws RestCallException { super(client, BeanSessionArgs.DEFAULT); this.client = client; this.request = request; this.errorCodes = client.errorCodes; this.partSerializer = client.getPartSerializerSession(); - this.uriBuilder = new URIBuilder(uri); + this.uriBuilder = new URIBuilder(request.getURI()); this.ignoreErrors = client.ignoreErrors; }