Skip to content

Commit

Permalink
Remove UnsupportedEncodingException catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Dec 2, 2024
1 parent 39a2643 commit 2dde5c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
27 changes: 10 additions & 17 deletions src/main/java/com/vonage/client/AbstractMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/vonage/client/verify/VerifyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/vonage/client/AbstractMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected Set<Class<? extends AuthMethod>> getAcceptableAuthMethods() {
}

@Override
public RequestBuilder makeRequest(String request) throws UnsupportedEncodingException {
public RequestBuilder makeRequest(String request) {
return RequestBuilder.get(request);
}

Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2dde5c9

Please sign in to comment.