From 2dde5c9bb6082d1bf326a0d9986686a1a174b71e Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Mon, 2 Dec 2024 16:35:11 +0000 Subject: [PATCH] Remove UnsupportedEncodingException catch block --- .../com/vonage/client/AbstractMethod.java | 27 +++++++------------ .../vonage/client/verify/VerifyClient.java | 1 - .../com/vonage/client/AbstractMethodTest.java | 8 +++--- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/vonage/client/AbstractMethod.java b/src/main/java/com/vonage/client/AbstractMethod.java index 932493056..2b0618766 100644 --- a/src/main/java/com/vonage/client/AbstractMethod.java +++ b/src/main/java/com/vonage/client/AbstractMethod.java @@ -71,25 +71,20 @@ protected ResultT postProcessParsedResponse(ResultT response) { */ @Override public ResultT execute(RequestT request) throws VonageResponseParseException, VonageClientException { - try { - HttpUriRequest httpRequest = applyAuth(makeRequest(request)) - .setHeader("User-Agent", httpWrapper.getUserAgent()) - .setCharset(StandardCharsets.UTF_8).build(); + HttpUriRequest httpRequest = applyAuth(makeRequest(request)) + .setHeader("User-Agent", httpWrapper.getUserAgent()) + .setCharset(StandardCharsets.UTF_8).build(); - try (CloseableHttpResponse response = httpWrapper.getHttpClient().execute(httpRequest)) { - try { - return postProcessParsedResponse(parseResponse(response)); - } - catch (IOException iox) { - throw new VonageResponseParseException(iox); - } + try (CloseableHttpResponse response = httpWrapper.getHttpClient().execute(httpRequest)) { + try { + return postProcessParsedResponse(parseResponse(response)); } catch (IOException iox) { - throw new VonageMethodFailedException("Something went wrong while executing the HTTP request.", iox); + throw new VonageResponseParseException(iox); } } - catch (UnsupportedEncodingException uex) { - throw new VonageUnexpectedException("UTF-8 encoding is not supported by this JVM.", uex); + catch (IOException iox) { + throw new VonageMethodFailedException("Something went wrong while executing the HTTP request.", iox); } } @@ -140,10 +135,8 @@ protected AuthMethod getAuthMethod() throws VonageUnexpectedException { * @param request A RequestT representing input to the REST call to be made * * @return A ResultT representing the response from the executed REST call - * - * @throws UnsupportedEncodingException if UTF-8 encoding is not supported by the JVM */ - protected abstract RequestBuilder makeRequest(RequestT request) throws UnsupportedEncodingException; + protected abstract RequestBuilder makeRequest(RequestT request); /** * Construct a ResultT representing the contents of the HTTP response returned from the Vonage Voice API. diff --git a/src/main/java/com/vonage/client/verify/VerifyClient.java b/src/main/java/com/vonage/client/verify/VerifyClient.java index 800876935..0444e3cd9 100644 --- a/src/main/java/com/vonage/client/verify/VerifyClient.java +++ b/src/main/java/com/vonage/client/verify/VerifyClient.java @@ -16,7 +16,6 @@ package com.vonage.client.verify; import com.vonage.client.*; -import com.vonage.client.auth.ApiKeyHeaderAuthMethod; import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod; import com.vonage.client.common.HttpMethod; import java.util.Locale; diff --git a/src/test/java/com/vonage/client/AbstractMethodTest.java b/src/test/java/com/vonage/client/AbstractMethodTest.java index fc67a351f..9699e7e4a 100644 --- a/src/test/java/com/vonage/client/AbstractMethodTest.java +++ b/src/test/java/com/vonage/client/AbstractMethodTest.java @@ -63,7 +63,7 @@ protected Set> getAcceptableAuthMethods() { } @Override - public RequestBuilder makeRequest(String request) throws UnsupportedEncodingException { + public RequestBuilder makeRequest(String request) { return RequestBuilder.get(request); } @@ -119,7 +119,7 @@ public void setUp() throws Exception { when(mockWrapper.getAuthCollection()).thenReturn(mockAuthMethods); } - ConcreteMethod mockJsonResponse(String json, boolean failing) throws Exception { + ConcreteMethod mockJsonResponse(String json, boolean failing) { ConcreteMethod method = spy(failing ? new ConcreteMethodFailingParse(mockWrapper) : new ConcreteMethod(mockWrapper) ); @@ -311,8 +311,8 @@ protected AuthMethod getAuthMethod() throws VonageUnexpectedException { } @Override - public RequestBuilder makeRequest(String request) throws UnsupportedEncodingException { - return builder.setEntity(new StringEntity(request)); + public RequestBuilder makeRequest(String request) { + return builder.setEntity(new StringEntity(request, ContentType.TEXT_PLAIN)); } } return new LocalMethod();