@@ -42,7 +42,7 @@ public class RestConnection implements IRestConnection {
4242
4343 private final Client client ;
4444
45- private final String endpoint ;
45+ private final String baseUrl ;
4646
4747 /**
4848 * Supported HTTP methods
@@ -73,22 +73,22 @@ public RestConnection(Client client) throws SparkPostException {
7373 *
7474 * @param client
7575 * Client object to use (in particular for authentication info)
76- * @param endpoint
76+ * @param baseUrl
7777 * Endpoint to use instead of the default defaultApiEndpoint
7878 * @throws SparkPostException
7979 */
80- public RestConnection (Client client , String endpoint ) throws SparkPostException {
80+ public RestConnection (Client client , String baseUrl ) throws SparkPostException {
8181
8282 this .client = client ;
83- if (StringUtils .isAnyEmpty (endpoint )) {
84- this .endpoint = defaultApiEndpoint ;
83+ if (StringUtils .isAnyEmpty (baseUrl )) {
84+ this .baseUrl = defaultApiEndpoint ;
8585 } else {
8686
87- this .endpoint = endpoint ;
87+ this .baseUrl = baseUrl ;
8888 }
8989
90- if (endpoint .endsWith ("/" )) {
91- throw new IllegalStateException ("SPARKPOST_BASE_URL should not end with a '/', SPARKPOST_BASE_URL=" + endpoint + "" );
90+ if (baseUrl .endsWith ("/" )) {
91+ throw new IllegalStateException ("SPARKPOST_BASE_URL should not end with a '/', SPARKPOST_BASE_URL=" + baseUrl + "" );
9292 }
9393 }
9494
@@ -106,8 +106,8 @@ private HttpURLConnection createConnectionObject(String path, Method method) thr
106106 HttpURLConnection conn ;
107107 try {
108108 URL url ;
109- url = new URL (this .endpoint + path );
110-
109+ url = new URL (this .baseUrl + path );
110+
111111 // Retrieve the URLConnection object (but doesn't actually connect):
112112 // (HttpUrlConnection doesn't connect to the server until we've
113113 // got one of its streams)
@@ -311,7 +311,7 @@ private Response receiveSuccessResponse(HttpURLConnection conn, Response respons
311311 return response ;
312312 }
313313
314- // This is used to handle 2xx HTTP responses
314+ // This is used to handle non 2xx HTTP responses
315315 private Response receiveErrorResponse (HttpURLConnection conn , Response response ) throws SparkPostException , IOException {
316316 response .setRequestId (conn .getHeaderField ("X-SparkPost-Request-Id" ));
317317
@@ -330,7 +330,6 @@ private Response receiveErrorResponse(HttpURLConnection conn, Response response)
330330 ServerErrorResponses errorResponses = null ;
331331
332332 try {
333- // We are in the success case handling but check the error stream anyway just in case
334333 try (BufferedReader rd = new BufferedReader (new InputStreamReader (conn .getErrorStream (), DEFAULT_CHARSET ))) {
335334
336335 String line = "" ;
@@ -345,8 +344,8 @@ private Response receiveErrorResponse(HttpURLConnection conn, Response response)
345344 try {
346345 errorResponses = (ServerErrorResponses ) ServerErrorResponses .decode (response , ServerErrorResponses .class );
347346 } catch (Exception e ) {
348- // Maybe there is something wrong where HTML is returned or some other very bad error. So we protect
349- // ourselves from that exception so we can throw a more specific exception later.
347+ // Maybe there is something wrong where HTML is returned or some other very bad error. Protect
348+ // against exception here so a more specific exception can be thrown later later.
350349 logger .error ("Failed to parse server response:\n " , e );
351350 }
352351
@@ -355,7 +354,7 @@ private Response receiveErrorResponse(HttpURLConnection conn, Response response)
355354 }
356355 } catch (Exception e ) {
357356 // Log but ignore since an exception is getting thrown anyway
358- logger .error ("Error while handlign an HTTP response error. Ignoring and will use orginal exception" , e );
357+ logger .error ("Error while handling an HTTP response error. Ignoring and will use orginal exception" , e );
359358 }
360359
361360 if (logger .isDebugEnabled ()) {
@@ -392,7 +391,7 @@ private Response receiveErrorResponse(HttpURLConnection conn, Response response)
392391 }
393392 }
394393
395- // This method actually performs an HTTP request.
394+ // This method actually performs the HTTP request
396395 // It is called by get(), put(), post() and delete() below
397396 private Response doHttpMethod (String path , Method method , String data , Response response ) throws SparkPostException {
398397 HttpURLConnection conn = null ;
@@ -414,7 +413,8 @@ private Response doHttpMethod(String path, Method method, String data, Response
414413 }
415414 }
416415
417- /* (non-Javadoc)
416+ /*
417+ * (non-Javadoc)
418418 * @see com.sparkpost.transport.IRestConnection#get(java.lang.String)
419419 */
420420 @ Override
@@ -423,7 +423,8 @@ public Response get(String path) throws SparkPostException {
423423 return doHttpMethod (path , Method .GET , null , response );
424424 }
425425
426- /* (non-Javadoc)
426+ /*
427+ * (non-Javadoc)
427428 * @see com.sparkpost.transport.IRestConnection#post(java.lang.String, java.lang.String)
428429 */
429430 @ Override
@@ -432,7 +433,8 @@ public Response post(String path, String json) throws SparkPostException {
432433 return doHttpMethod (path , Method .POST , json , response );
433434 }
434435
435- /* (non-Javadoc)
436+ /*
437+ * (non-Javadoc)
436438 * @see com.sparkpost.transport.IRestConnection#put(java.lang.String, java.lang.String)
437439 */
438440 @ Override
@@ -441,7 +443,8 @@ public Response put(String path, String json) throws SparkPostException {
441443 return doHttpMethod (path , Method .PUT , json , response );
442444 }
443445
444- /* (non-Javadoc)
446+ /*
447+ * (non-Javadoc)
445448 * @see com.sparkpost.transport.IRestConnection#delete(java.lang.String)
446449 */
447450 @ Override
0 commit comments