Skip to content

Commit

Permalink
Merge branch '6.0.0-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
yallen011 committed Nov 16, 2020
2 parents 7c230e8 + 8cc476e commit ed1094f
Show file tree
Hide file tree
Showing 115 changed files with 550 additions and 841 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Added
- ASR (Automatic Speech Recognition)

### Changed
- Refactored Application v2 requests to remove duplicated code
- Deprecated Product.MESSAGE from RedactRequest. Use Product.MESSAGES instead
- Deprecated InsightClient#getStandardNumberInsight(number, country, cnam). Use InsightClient#getStandardNumberInsight(StandardInsightRequest) instead
- Deprecated InsightClient.getAdvancedNumberInsight(number, country, ipAddress, cnam). Use InsightClient#getAdvancedNumberInsight(AdvancedInsightRequest) instead
- Deprecated InsightClient.getAdvancedNumberInsight(number, country, ipAddress). Use InsightClient#getAdvancedNumberInsight(AdvancedInsightRequest) instead
- Deprecated public constructors and setters in VerifyRequest use VerifyRequest.Builder instead
- Deprecated MD5Util use HashUtil instead
- Removed setters from BaseRequest. Set fields in the builders of Psd2Request or VerifyRequest instead.

## [5.6.0]
### Added
- NotifyEvent structure for Notify Actions
- SHA256 hashing option

### Changed
- Create application request use basic auth for authentication
- Changed application requests to use basic auth in header for authentication

### Fixed
- Fixed error throw when trying to log No Content responses
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/vonage/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public HttpWrapper(HttpConfig httpConfig, AuthMethod... authMethods) {
}

public HttpClient getHttpClient() {
if (this.httpClient == null) {
this.httpClient = createHttpClient();
if (httpClient == null) {
httpClient = createHttpClient();
}
return this.httpClient;
return httpClient;
}

public void setHttpClient(HttpClient httpClient) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/VonageClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public Builder privateKeyPath(String privateKeyPath) throws VonageUnableToReadPr
* generating an {@link JWTAuthMethod} with the provided credentials.
*/
public VonageClient build() {
this.authCollection = generateAuthCollection(applicationId,
authCollection = generateAuthCollection(applicationId,
apiKey,
apiSecret,
signatureSecret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RequestBuilder makeRequest(Void request) throws UnsupportedEncodingExcept
}

public BalanceResponse execute() {
return this.execute(null);
return execute(null);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/account/PricingMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected Class[] getAcceptableAuthMethods() {

@Override
public RequestBuilder makeRequest(PricingRequest pricingRequest) {
return RequestBuilder.get(this.getUri()).addParameter("country", pricingRequest.getCountryCode());
return RequestBuilder.get(getUri()).addParameter("country", pricingRequest.getCountryCode());
}

@Override
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/vonage/client/application/ApplicationMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageClientException;
import org.apache.http.client.methods.RequestBuilder;

public abstract class ApplicationMethod<RequestT, ResultT> extends AbstractMethod<RequestT, ResultT> {

public ApplicationMethod(HttpWrapper httpWrapper) {
super(httpWrapper);
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageBadRequestException;
import com.vonage.client.VonageClientException;
Expand All @@ -29,7 +28,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class CreateApplicationMethod extends AbstractMethod<Application, Application> {
class CreateApplicationMethod extends ApplicationMethod<Application, Application> {
private static final Class[] ALLOWED_AUTH_METHODS = new Class[]{TokenAuthMethod.class};

private static final String PATH = "/applications";
Expand Down Expand Up @@ -59,9 +58,4 @@ public Application parseResponse(HttpResponse response) throws IOException, Vona

return Application.fromJson(new BasicResponseHandler().handleResponse(response));
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageBadRequestException;
import com.vonage.client.VonageClientException;
Expand All @@ -27,7 +26,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class DeleteApplicationMethod extends AbstractMethod<String, Void> {
class DeleteApplicationMethod extends ApplicationMethod<String, Void> {
private static final Class[] ALLOWED_AUTH_METHODS = new Class[]{TokenAuthMethod.class};

private static final String PATH = "/applications/%s";
Expand Down Expand Up @@ -56,9 +55,4 @@ public Void parseResponse(HttpResponse response) throws IOException, VonageClien

return null;
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageBadRequestException;
import com.vonage.client.VonageClientException;
Expand All @@ -28,7 +27,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class GetApplicationMethod extends AbstractMethod<String, Application> {
class GetApplicationMethod extends ApplicationMethod<String, Application> {
private static final Class[] ALLOWED_AUTH_METHODS = new Class[]{TokenAuthMethod.class};

private static final String PATH = "/applications/%s";
Expand Down Expand Up @@ -57,9 +56,4 @@ public Application parseResponse(HttpResponse response) throws IOException, Vona

return Application.fromJson(new BasicResponseHandler().handleResponse(response));
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageBadRequestException;
import com.vonage.client.VonageClientException;
Expand All @@ -28,7 +27,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class ListApplicationsMethod extends AbstractMethod<ListApplicationRequest, ApplicationList> {
class ListApplicationsMethod extends ApplicationMethod<ListApplicationRequest, ApplicationList> {
private static final Class[] ALLOWED_AUTH_METHODS = new Class[]{TokenAuthMethod.class};

private static final String PATH = "/applications";
Expand Down Expand Up @@ -69,9 +68,4 @@ public ApplicationList parseResponse(HttpResponse response) throws IOException,

return ApplicationList.fromJson(new BasicResponseHandler().handleResponse(response));
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application;

import com.vonage.client.AbstractMethod;
import com.vonage.client.HttpWrapper;
import com.vonage.client.VonageBadRequestException;
import com.vonage.client.VonageClientException;
Expand All @@ -29,7 +28,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class UpdateApplicationMethod extends AbstractMethod<Application, Application> {
class UpdateApplicationMethod extends ApplicationMethod<Application, Application> {
private static final Class[] ALLOWED_AUTH_METHODS = new Class[]{TokenAuthMethod.class};

private static final String PATH = "/applications/%s";
Expand Down Expand Up @@ -59,9 +58,4 @@ public Application parseResponse(HttpResponse response) throws IOException, Vona

return Application.fromJson(new BasicResponseHandler().handleResponse(response));
}

@Override
protected RequestBuilder applyAuth(RequestBuilder request) throws VonageClientException {
return getAuthMethod(getAcceptableAuthMethods()).applyAsBasicAuth(request);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/vonage/client/auth/AuthCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void add(AuthMethod auth) {
*
* @throws VonageUnacceptableAuthException if no matching AuthMethod is found.
*/
@SuppressWarnings("unchecked")
public <T extends AuthMethod> T getAuth(Class<T> type) throws VonageUnacceptableAuthException {
for (AuthMethod availableAuthMethod : authList) {
if (type.isInstance(availableAuthMethod)) {
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/com/vonage/client/auth/MD5Util.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/com/vonage/client/auth/RequestSigning.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static boolean verifyRequestSignature(HttpServletRequest request, String
*
* @param request The HttpServletRequest to be verified.
* @param secretKey The pre-shared secret key used by the sender of the request to create the signature.
* @param hashType Hash type to be used to construct request parameters.
*
* @return true if the signature is correct for this request and secret key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SignatureAuthMethod extends AbstractAuthMethod {
public SignatureAuthMethod(String apiKey, String secret) {
this.apiKey = apiKey;
this.secret = secret;
this.hashType = HashUtil.HashType.MD5;
hashType = HashUtil.HashType.MD5;
}

public SignatureAuthMethod(String apiKey, String secret, HashUtil.HashType hashType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public String calculate(String input) throws NoSuchAlgorithmException, InvalidKe
* @return hashed representation of the input string
* @throws NoSuchAlgorithmException if the algorithm is not available.
* @throws UnsupportedEncodingException if the encoding type is invalid
* @throws InvalidKeyException Only applicable to HMAC encoding types, when a bad key is provided.
*/
public String calculate(String input, String secretKey, String encoding) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
return this.calculate(input + secretKey, encoding);
return calculate(input + secretKey, encoding);
}

/**
Expand All @@ -44,6 +45,7 @@ public String calculate(String input, String secretKey, String encoding) throws
* @return hashed representation of the input string
* @throws NoSuchAlgorithmException if the algorithm is not available.
* @throws UnsupportedEncodingException if the encoding type is invalid
* @throws InvalidKeyException Only applicable to HMAC encoding types, when a bad key is provided.
*/
public abstract String calculate(String input, String encoding) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static String calculate(String input, HashType hashType) throws NoSuchAlg
* @return representation of the input string with given hash type
* @throws NoSuchAlgorithmException if the algorithm is not available.
* @throws InvalidKeyException Only applicable to HMAC encoding types, when a bad key is provided.
* @throws UnsupportedEncodingException if the specified encoding is unavailable.
*/
public static String calculate(String input, String encoding, HashType hashType) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
return hashTypes.get(hashType).calculate(input, encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HmacMd5Hasher extends AbstractHasher {

byte[] digest = sha1HMAC.doFinal(input.getBytes(encoding));

return this.buildHexString(digest);
return buildHexString(digest);
}

/**
Expand All @@ -43,6 +43,6 @@ public class HmacMd5Hasher extends AbstractHasher {
* @throws InvalidKeyException if key is invalid
*/
@Override public String calculate(String input, String encoding) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
return this.calculate(input, input, encoding);
return calculate(input, input, encoding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HmacSha1Hasher extends AbstractHasher {

byte[] digest = sha1HMAC.doFinal(input.getBytes(encoding));

return this.buildHexString(digest);
return buildHexString(digest);
}

/**
Expand All @@ -43,6 +43,6 @@ public class HmacSha1Hasher extends AbstractHasher {
* @throws InvalidKeyException if key is invalid
*/
@Override public String calculate(String input, String encoding) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
return this.calculate(input, input, encoding);
return calculate(input, input, encoding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HmacSha256Hasher extends AbstractHasher {

byte[] digest = sha256HMAC.doFinal(input.getBytes(encoding));

return this.buildHexString(digest);
return buildHexString(digest);
}

/**
Expand All @@ -43,6 +43,6 @@ public class HmacSha256Hasher extends AbstractHasher {
* @throws InvalidKeyException if key is invalid
*/
@Override public String calculate(String input, String encoding) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
return this.calculate(input, input, encoding);
return calculate(input, input, encoding);
}
}
Loading

0 comments on commit ed1094f

Please sign in to comment.