Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Jan 17, 2025
1 parent f177247 commit c66633f
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 409 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
~ Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
Expand All @@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>ai-services-mgt</artifactId>
<version>7.7.87-SNAPSHOT</version>
<version>7.7.92-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -85,7 +85,6 @@

<build>
<plugins>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand All @@ -109,6 +108,7 @@
org.apache.http; version="${httpcore.version.osgi.import.range}",
org.apache.http.client; version="${httpcomponents-httpclient.imp.pkg.version.range}",
org.apache.http.client.methods; version="${httpcomponents-httpclient.imp.pkg.version.range}",
org.apache.http.client.config; version="${httpcomponents-httpclient.imp.pkg.version.range}",
org.apache.http.entity; version="${httpcore.version.osgi.import.range}",
org.apache.http.message; version="${httpcore.version.osgi.import.range}",
org.apache.http.protocol; version="${httpcore.version.osgi.import.range}",
Expand Down Expand Up @@ -145,6 +145,12 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>**/*Exception.class</exclude>
<exclude>**/*Constants*.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
*/
public class AIConstants {

private AIConstants () {

}

public static final String AI_SERVICE_KEY_PROPERTY_NAME = "AIServices.Key";
public static final String AI_TOKEN_ENDPOINT_PROPERTY_NAME = "AIServices.TokenEndpoint";
public static final String AI_TOKEN_SERVICE_MAX_RETRIES_PROPERTY_NAME = "AIServices.TokenRequestMaxRetries";
public static final String AI_TOKEN_CONNECTION_TIMEOUT_PROPERTY_NAME = "AIServices.TokenConnectionTimeout";
public static final String AI_TOKEN_CONNECTION_REQUEST_TIMEOUT_PROPERTY_NAME = "AIServices" +
".TokenConnectionRequestTimeout";
public static final String AI_TOKEN_SOCKET_TIMEOUT_PROPERTY_NAME = "AIServices.TokenSocketTimeout";
public static final String AI_TOKEN_SOCKET_TIMEOUT_PROPERTY_NAME = "AIServices.TokenConnectionSocketTimeout";

public static final String HTTP_CONNECTION_POOL_SIZE_PROPERTY_NAME = "AIServices.HTTPConnectionPoolSize";
public static final String HTTP_CONNECTION_TIMEOUT_PROPERTY_NAME = "AIServices.HTTPConnectionTimeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,20 @@
/**
* Client Exception class for AI service.
*/
public class AIClientException extends Exception {

private final String errorCode;
private String serverMessage;
private int serverStatusCode;
public class AIClientException extends AIException {

public AIClientException(String message, String errorCode) {

super(message);
this.errorCode = errorCode;
super(message, errorCode);
}

public AIClientException(String message, String errorCode, int serverStatusCode, String serverMessage) {

super(message);
this.errorCode = errorCode;
this.serverStatusCode = serverStatusCode;
this.serverMessage = serverMessage;
super(message, errorCode, serverStatusCode, serverMessage);
}

public AIClientException(String message, String errorCode, Throwable cause) {

super(message, cause);
this.errorCode = errorCode;
}

public String getErrorCode() {

return errorCode;
}

public String getServerMessage() {

return serverMessage;
}

public int getServerStatusCode() {

return serverStatusCode;
super(message, errorCode, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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 org.wso2.carbon.identity.ai.service.mgt.exceptions;

/**
* Generic Exception class for AI service.
*/
public class AIException extends Exception {

private String errorCode;
// This is the error message that comes from the server.
private String serverMessage;
// This is the status code that comes from the server.
private int serverStatusCode;

public AIException(String message, String errorCode) {

super(message);
this.errorCode = errorCode;
}

public AIException(String message, Throwable cause) {

super(message, cause);
}

public AIException(String message, String errorCode, int serverStatusCode, String serverMessage) {

super(message);
this.errorCode = errorCode;
this.serverStatusCode = serverStatusCode;
this.serverMessage = serverMessage;
}

public AIException(String message, String errorCode, Throwable cause) {

super(message, cause);
this.errorCode = errorCode;
}

public String getErrorCode() {

return errorCode;
}

public String getServerMessage() {

return serverMessage;
}

public int getServerStatusCode() {

return serverStatusCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,25 @@
/**
* Client Exception class for AI service.
*/
public class AIServerException extends Exception {

private String errorCode;
private String serverMessage;
private int serverStatusCode;
public class AIServerException extends AIException {

public AIServerException(String message, String errorCode) {

super(message);
this.errorCode = errorCode;
super(message, errorCode);
}

public AIServerException(String message, String errorCode, int serverStatusCode, String serverMessage) {
public AIServerException(String message, Throwable e) {

super(message);
this.errorCode = errorCode;
this.serverStatusCode = serverStatusCode;
this.serverMessage = serverMessage;
super(message, e);
}

public AIServerException(String message, Throwable cause) {
public AIServerException(String message, String errorCode, int serverStatusCode, String serverMessage) {

super(message, cause);
super(message, errorCode, serverStatusCode, serverMessage);
}

public AIServerException(String message, String errorCode, Throwable cause) {

super(message, cause);
this.errorCode = errorCode;
}

public String getErrorCode() {

return errorCode;
}

public String getServerMessage() {

return serverMessage;
}

public int getServerStatusCode() {

return serverStatusCode;
super(message, errorCode, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*/
public class AIAccessTokenManager {

private static volatile AIAccessTokenManager instance; // Volatile for thread safety.
private static volatile AIAccessTokenManager instance;
private static final Object lock = new Object(); // Lock for synchronization.

private static final Log LOG = LogFactory.getLog(AIAccessTokenManager.class);
Expand All @@ -83,7 +83,7 @@ private AIAccessTokenManager() {
String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
String[] parts = decodedString.split(":");
if (parts.length == 2) {
this.clientId = parts[0]; // Extract clientId.
this.clientId = parts[0];
} else {
throw new IllegalArgumentException("Invalid AI service key.");
}
Expand Down Expand Up @@ -208,6 +208,7 @@ public String requestAccessToken() throws AIServerException {
}

private static int readIntProperty(String key, int defaultValue) {

String value = IdentityUtil.getProperty(key);
return value != null ? Integer.parseInt(value) : defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,18 @@ private static Map<String, Object> convertJsonStringToMap(String jsonString) thr
}
}

protected static HttpResponseWrapper executeHttpRequest(HttpUriRequest httpRequest)
private static HttpResponseWrapper executeHttpRequest(HttpUriRequest httpRequest)
throws IOException {

// Here we don't close the client connection since we are using a connection pool.
HttpResponse httpResponse = httpClient.execute(httpRequest);
int status = httpResponse.getStatusLine().getStatusCode();
String response = EntityUtils.toString(httpResponse.getEntity());
return new HttpResponseWrapper(status, response);
}

private static int readIntProperty(String key, int defaultValue) {

String value = IdentityUtil.getProperty(key);
return value != null ? Integer.parseInt(value) : defaultValue;
}
Expand Down

This file was deleted.

Loading

0 comments on commit c66633f

Please sign in to comment.