Skip to content

Commit e9d27a6

Browse files
committed
fix: AiCoreService NoClassDefFound Error
1 parent 95409ae commit e9d27a6

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

core/src/main/java/com/sap/ai/sdk/core/AiCoreService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.function.BiFunction;
2121
import java.util.function.Function;
2222
import javax.annotation.Nonnull;
23+
24+
import io.github.cdimascio.dotenv.DotenvBuilder;
2325
import lombok.RequiredArgsConstructor;
2426
import lombok.extern.slf4j.Slf4j;
2527
import lombok.val;
@@ -34,16 +36,14 @@
3436
@RequiredArgsConstructor
3537
public class AiCoreService implements AiCoreDestination {
3638

39+
private static final String AI_RESOURCE_GROUP = "URL.headers.AI-Resource-Group";
40+
private static final DeploymentCache DEPLOYMENT_CACHE = new DeploymentCache();
41+
private static final DotenvBuilder DOT_ENV = Dotenv.configure().ignoreIfMissing();
42+
3743
Function<AiCoreService, Destination> baseDestinationHandler;
3844
final BiFunction<AiCoreService, Destination, ApiClient> clientHandler;
3945
final BiFunction<AiCoreService, Destination, DefaultHttpDestination.Builder> builderHandler;
4046

41-
private static final DeploymentCache DEPLOYMENT_CACHE = new DeploymentCache();
42-
43-
private static final String AI_RESOURCE_GROUP = "URL.headers.AI-Resource-Group";
44-
45-
/** loads the .env file from the root of the project */
46-
private static final Dotenv DOTENV = Dotenv.configure().ignoreIfMissing().load();
4747

4848
/** The resource group is defined by AiCoreDeployment.withResourceGroup(). */
4949
@Nonnull String resourceGroup;
@@ -163,7 +163,7 @@ public AiCoreDeployment forDeploymentByScenario(@Nonnull final String scenarioId
163163
@Nonnull
164164
protected Destination getBaseDestination()
165165
throws DestinationAccessException, DestinationNotFoundException {
166-
val serviceKey = DOTENV.get("AICORE_SERVICE_KEY");
166+
val serviceKey = DOT_ENV.load().get("AICORE_SERVICE_KEY");
167167
return DestinationResolver.getDestination(serviceKey);
168168
}
169169

core/src/test/java/com/sap/ai/sdk/core/DestinationResolverTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
import lombok.val;
99
import org.junit.jupiter.api.Test;
1010

11-
public class DestinationResolverTest {
11+
class DestinationResolverTest {
1212

1313
@Test
14-
@SneakyThrows
1514
void getDestinationWithoutEnvVarFailsLocally() {
1615
assertThatThrownBy(() -> DestinationResolver.getDestination(null))
1716
.isExactlyInstanceOf(DestinationAccessException.class)
1817
.hasMessage("Could not find any matching service bindings for service identifier 'aicore'");
1918
}
2019

2120
@Test
22-
@SneakyThrows
2321
void getDestinationWithBrokenEnvVarFailsLocally() {
2422
assertThatThrownBy(() -> DestinationResolver.getDestination(""))
2523
.isExactlyInstanceOf(DestinationResolver.AiCoreCredentialsInvalidException.class)
@@ -28,9 +26,8 @@ void getDestinationWithBrokenEnvVarFailsLocally() {
2826
}
2927

3028
@Test
31-
@SneakyThrows
3229
void getDestinationWithEnvVarSucceedsLocally() {
33-
val AICORE_SERVICE_KEY =
30+
val serviceKey =
3431
"""
3532
{
3633
"clientid": "",
@@ -44,7 +41,7 @@ void getDestinationWithEnvVarSucceedsLocally() {
4441
}
4542
}
4643
""";
47-
var result = DestinationResolver.getDestination(AICORE_SERVICE_KEY).asHttp();
44+
var result = DestinationResolver.getDestination(serviceKey).asHttp();
4845
assertThat(result.getUri()).hasToString("https://api.ai.core");
4946
}
5047
}

0 commit comments

Comments
 (0)