@@ -175,7 +175,7 @@ public EAAction<O> retrieveOne(@NotNull String... pathSegments) {
175175 }
176176
177177 @ NotNull
178- protected ConnectionDetails openConnection (@ NotNull String endpointPath , @ NotNull String objectField , @ Nullable Map <String , Object > queryParams , @ Nullable String ... pathSegments ) throws IOException {
178+ public String buildUrl (@ NotNull String endpointPath , @ Nullable Map <String , Object > queryParams , @ Nullable String ... pathSegments ) {
179179 // Build query parameters
180180 final StringBuilder queryString = new StringBuilder ();
181181 if (queryParams != null && !queryParams .isEmpty ()) {
@@ -216,8 +216,14 @@ protected ConnectionDetails openConnection(@NotNull String endpointPath, @NotNul
216216 final StringBuilder path = new StringBuilder ();
217217 if (pathSegments != null ) for (final String segment : pathSegments ) path .append ("/" ).append (segment );
218218
219+ // Build and return full URL
220+ return http .url + endpointPath + path + queryString ;
221+ }
222+
223+ @ NotNull
224+ protected ConnectionDetails openConnection (@ NotNull String url , @ NotNull String objectField ) throws IOException {
219225 // Open connection
220- final HttpURLConnection connection = (HttpURLConnection ) URI .create (http . url + endpointPath + path + queryString ).toURL ().openConnection ();
226+ final HttpURLConnection connection = (HttpURLConnection ) URI .create (url ).toURL ().openConnection ();
221227 connection .setRequestMethod ("GET" );
222228 for (final Map .Entry <String , String > header : http .headers .entrySet ()) connection .setRequestProperty (header .getKey (), header .getValue ());
223229
@@ -227,7 +233,7 @@ protected ConnectionDetails openConnection(@NotNull String endpointPath, @NotNul
227233 final JsonObject json = GSONProvider .GSON .fromJson (body , JsonObject .class );
228234 if (json == null ) {
229235 if (statusCode >= 400 ) throw new EAHttpResponseException (statusCode , connection .getResponseMessage (), body );
230- throw new EAHttpRequestException ("GET " + endpointPath , new IllegalStateException ("Failed to parse JSON response" ));
236+ throw new EAHttpRequestException ("GET " + url , new IllegalStateException ("Failed to parse JSON response" ));
231237 }
232238
233239 // Error
@@ -291,13 +297,13 @@ private PaginatedResponse<O> executePage(@Nullable Map<String, Object> queryPara
291297 if (page != null ) params .put ("page" , page );
292298 if (limit != null ) params .put ("limit" , limit );
293299
294- final String endpointPath = getPath ();
300+ final String url = buildUrl ( getPath (), params );
295301 final String objectField = getPaginatedFieldName ();
296302
297303 HttpURLConnection connection = null ;
298304 try {
299305 // Open connection and get details
300- final ConnectionDetails details = openConnection (endpointPath , objectField , params );
306+ final ConnectionDetails details = openConnection (url , objectField );
301307 connection = details .connection ;
302308
303309 // Parse objects
@@ -313,21 +319,21 @@ private PaginatedResponse<O> executePage(@Nullable Map<String, Object> queryPara
313319 } catch (final RuntimeException e ) {
314320 throw e ;
315321 } catch (final Exception e ) {
316- throw new EAHttpRequestException ("GET " + endpointPath , e );
322+ throw new EAHttpRequestException ("GET " + url , e );
317323 } finally {
318324 if (connection != null ) connection .disconnect ();
319325 }
320326 }
321327
322328 @ NotNull
323329 private EAItemData <O > executeOne (@ Nullable String ... pathSegments ) {
324- final String endpointPath = getPath ();
330+ final String url = buildUrl ( getPath (), null , pathSegments );
325331 final String objectField = getSingleFieldName ();
326332
327333 HttpURLConnection connection = null ;
328334 try {
329335 // Open connection and get details
330- final ConnectionDetails details = openConnection (endpointPath , objectField , null , pathSegments );
336+ final ConnectionDetails details = openConnection (url , objectField );
331337 connection = details .connection ;
332338
333339 // Parse object
@@ -339,7 +345,7 @@ private EAItemData<O> executeOne(@Nullable String... pathSegments) {
339345 } catch (final RuntimeException e ) {
340346 throw e ;
341347 } catch (final Exception e ) {
342- throw new EAHttpRequestException ("GET " + endpointPath , e );
348+ throw new EAHttpRequestException ("GET " + url , e );
343349 } finally {
344350 if (connection != null ) connection .disconnect ();
345351 }
0 commit comments