Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvariyath committed Feb 18, 2025
2 parents 9d3d5a8 + 62c49b5 commit c1220cf
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -36,8 +39,8 @@ static void setUp() throws Exception {
.build();

server = HttpServer.builder(eventloop, servlet)
.withListenPort(8080)
.build();
.withListenPort(randomPort())
.build();

server.listen();

Expand All @@ -48,6 +51,14 @@ static void setUp() throws Exception {
client = HttpClient.builder(eventloop, dnsClient).build();
}

private static int randomPort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
throw new RuntimeException("Failed to find a free port", e);
}
}

@AfterAll
static void tearDown() {
if (server != null) {
Expand Down
2 changes: 1 addition & 1 deletion persistence-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<module>scylladb</module>
<module>spring-data-cassandra-2</module>
<module>spring-data-jpa-repo-3</module>
<!--<module>spring-boot-persistence-4</module>--> <!-- failing after spring boot upgrade to 3.3.2 --> <!-- JAVA-42045 -->
<module>spring-boot-persistence-4</module>
<!--<module>spring-boot-persistence-5</module>--> <!-- failing after spring boot upgrade to 3.3.2 --> <!-- JAVA-42046 -->
<module>hibernate-annotations-2</module>
<module>hibernate-reactive</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
@Component
public class JsonUtils {

@Value("users.json")
@Value("classpath:users.json")
private File userFile;

@Value("groups.json")
@Value("classpath:groups.json")
private File groupFile;

@Value("groups_with_members.json")
@Value("classpath:groups_with_members.json")
private File groupsWithMembersFile;

private static final ObjectMapper MAPPER = new ObjectMapper();
Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,6 @@
<module>persistence-modules/spring-boot-persistence-mongodb</module> <!-- JAVA-42144 -->
<module>persistence-modules/spring-boot-persistence-mongodb-2</module> <!-- JAVA-42371 -->
<module>persistence-modules/spring-boot-persistence-mongodb-4</module> <!-- JAVA-42372 -->
<module>persistence-modules/spring-boot-persistence-4</module> <!-- JAVA-42045 -->
<module>persistence-modules/spring-boot-persistence-5</module> <!-- JAVA-42046 -->
<module>persistence-modules/spring-data-elasticsearch</module> <!-- JAVA-42359 -->
<module>persistence-modules/spring-data-mongodb-2</module> <!-- JAVA-42145 -->
Expand Down Expand Up @@ -1487,7 +1486,6 @@
<module>persistence-modules/spring-boot-persistence-mongodb</module> <!-- JAVA-42144 -->
<module>persistence-modules/spring-boot-persistence-mongodb-2</module> <!-- JAVA-42371 -->
<module>persistence-modules/spring-boot-persistence-mongodb-4</module> <!-- JAVA-42372 -->
<module>persistence-modules/spring-boot-persistence-4</module> <!-- JAVA-42045 -->
<module>persistence-modules/spring-boot-persistence-5</module> <!-- JAVA-42046 -->
<module>persistence-modules/spring-data-elasticsearch</module> <!-- JAVA-42359 -->
<module>persistence-modules/spring-data-mongodb-2</module> <!-- JAVA-42145 -->
Expand Down
2 changes: 1 addition & 1 deletion spring-ai-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

<properties>
<spring-boot.version>3.4.1</spring-boot.version>
<spring-ai.version>1.0.0-M5</spring-ai.version>
<spring-ai.version>1.0.0-M6</spring-ai.version>
<junit-jupiter.version>5.9.0</junit-jupiter.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class OrderManagementAIAssistant {
public ChatResponse callChatClient(Set<String> functionNames, String promptString) {
Prompt prompt = new Prompt(promptString, OpenAiChatOptions
.builder()
.withFunctions(functionNames)
.functions(functionNames)
.build()
);
return chatClient.call(prompt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
package com.baeldung.spring.ai.om;

import org.springframework.ai.autoconfigure.anthropic.AnthropicAutoConfiguration;
import org.springframework.ai.autoconfigure.bedrock.converse.BedrockConverseProxyChatAutoConfiguration;
import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration;
import org.springframework.ai.autoconfigure.vectorstore.chroma.ChromaVectorStoreAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
/**
* Excluding the below auto-configurations to avoid start up
* failure. Their corresponding starters are present on the classpath but are
* only needed by other articles in the shared codebase.
*/
@SpringBootApplication(exclude = {
OllamaAutoConfiguration.class,
AnthropicAutoConfiguration.class,
ChromaVectorStoreAutoConfiguration.class,
BedrockConverseProxyChatAutoConfiguration.class
})
@PropertySource("classpath:application-aiassistant.properties")
public class OrderManagementApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.baeldung.springai.chromadb;

import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
/**
* Excluding the below auto-configurations to avoid start up
* failure. Their corresponding starters are present on the classpath but are
* only needed by other articles in the shared codebase.
*/
@SpringBootApplication(exclude = {
OpenAiAutoConfiguration.class
})
@PropertySource("classpath:application-chromadb.properties")
public class Application {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.baeldung.springai.huggingface;

import org.springframework.ai.autoconfigure.anthropic.AnthropicAutoConfiguration;
import org.springframework.ai.autoconfigure.bedrock.converse.BedrockConverseProxyChatAutoConfiguration;
import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
import org.springframework.ai.autoconfigure.vectorstore.chroma.ChromaVectorStoreAutoConfiguration;
import org.springframework.boot.SpringApplication;
Expand All @@ -13,7 +15,9 @@
*/
@SpringBootApplication(exclude = {
OpenAiAutoConfiguration.class,
ChromaVectorStoreAutoConfiguration.class
AnthropicAutoConfiguration.class,
ChromaVectorStoreAutoConfiguration.class,
BedrockConverseProxyChatAutoConfiguration.class
})
@PropertySource("classpath:application-huggingface.properties")
public class Application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ spring.datasource.password=
spring.jpa.hibernate.ddl-auto=none

spring.ai.openai.chat.options.model=gpt-4o-mini
spring.ai.openai.api-key=xxxxxxx
spring.autoconfigure.exclude=org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration,org.springframework.ai.autoconfigure.vectorstore.chroma.ChromaVectorStoreAutoConfiguration
spring.ai.openai.api-key=xxxxxxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

@SpringBootTest
@ActiveProfiles("aiassistant")

@Sql(scripts = "classpath:/order_mgmt.sql", executionPhase = BEFORE_TEST_CLASS)
public class AiOrderManagementLiveTest {

Expand All @@ -34,7 +33,7 @@ public class AiOrderManagementLiveTest {
void whenOrderInfoProvided_thenSaveInDB(String promptString) {
ChatResponse response = this.orderManagementAIAssistant
.callChatClient(Set.of("createOrderFn"), promptString);
String resultContent = response.getResult().getOutput().getContent();
String resultContent = response.getResult().getOutput().getText();
logger.info("The response from the LLM service: {}", resultContent);
}

Expand All @@ -46,7 +45,7 @@ void whenUserIDProvided_thenFetchUserOrders(String promptString) {
.callChatClient(Set.of("getUserOrdersFn"), promptString);
String resultContent = response.getResult()
.getOutput()
.getContent();
.getText();
logger.info("The response from the LLM service: {}", resultContent);
}

Expand All @@ -64,7 +63,7 @@ void whenUserIDProvided_thenCreateOrderIfUserHasLessThanTwoOrders(String promptS
.callChatClient(Set.of("getUserOrdersFn", "createOrderFn"), promptString);
String resultContent = response.getResult()
.getOutput()
.getContent();
.getText();
logger.info("The response from the LLM service: {}", resultContent);
}

Expand All @@ -75,7 +74,7 @@ void whenIncompleteOrderInfoProvided_thenAskUserForMoreInfo(String promptString)
.callChatClient(Set.of("createOrderFn"), promptString);
String resultContent = response.getResult()
.getOutput()
.getContent();
.getText();
logger.info("The response from the LLM service: {}", resultContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class SemanticSearchLiveTest {
@ValueSource(strings = {"Love and Romance", "Time and Mortality", "Jealousy and Betrayal"})
void whenSearchingShakespeareTheme_thenRelevantPoemsReturned(String theme) {
SearchRequest searchRequest = SearchRequest
.builder()
.query(theme)
.withTopK(MAX_RESULTS);
.topK(MAX_RESULTS)
.build();
List<Document> documents = vectorStore.similaritySearch(searchRequest);

assertThat(documents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void whenChatClientProvidesAnswerRelevantToTopic_thenRelevancyEvaluationSucceeds
.call()
.chatResponse();

String answer = chatResponse.getResult().getOutput().getContent();
String answer = chatResponse.getResult().getOutput().getText();
List<Document> documents = chatResponse.getMetadata().get(QuestionAnswerAdvisor.RETRIEVED_DOCUMENTS);
EvaluationRequest evaluationRequest = new EvaluationRequest(question, documents, answer);

Expand Down Expand Up @@ -86,7 +86,7 @@ void whenChatClientProvidesFactuallyCorrectAnswer_thenFactCheckingEvaluationSucc
.call()
.chatResponse();

String answer = chatResponse.getResult().getOutput().getContent();
String answer = chatResponse.getResult().getOutput().getText();
List<Document> documents = chatResponse.getMetadata().get(QuestionAnswerAdvisor.RETRIEVED_DOCUMENTS);
EvaluationRequest evaluationRequest = new EvaluationRequest(question, documents, answer);

Expand Down
23 changes: 23 additions & 0 deletions spring-kafka/src/main/java/com/baeldung/sasl/KafkaConsumer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.baeldung.sasl;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class KafkaConsumer {

public static final String TOPIC = "test-topic";
public final List<String> messages = new ArrayList<>();

@KafkaListener(topics = TOPIC)
public void receive(ConsumerRecord<String, String> consumerRecord) {
log.info("Received payload: '{}'", consumerRecord.toString());
messages.add(consumerRecord.value());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.baeldung.sasl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class KafkaSaslApplication {

public static void main(String[] args) {
System.setProperty("spring.config.name", "application-sasl");
SpringApplication.run(KafkaSaslApplication.class, args);
}
}
19 changes: 19 additions & 0 deletions spring-kafka/src/main/resources/application-sasl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
kafka:
bootstrap-servers: localhost:9092
properties:
sasl.mechanism: GSSAPI
sasl.jaas.config: >
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
keyTab="./src/test/resources/sasl/keytabs/client.keytab"
principal="[email protected]"
serviceName="kafka";
security:
protocol: "SASL_PLAINTEXT"
consumer:
group-id: test
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.baeldung.sasl;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = KafkaSaslApplication.class)
class SpringContextTest {

@Test
void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
15 changes: 15 additions & 0 deletions spring-kafka/src/test/resources/sasl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use a minimal base image
FROM debian:bullseye

RUN apt-get update && \
apt-get install -y krb5-kdc krb5-admin-server krb5-user && \
rm -rf /var/lib/apt/lists/*

COPY config/krb5.conf /etc/krb5.conf
COPY setup_kdc.sh /setup_kdc.sh

RUN chmod +x /setup_kdc.sh

EXPOSE 88 749

CMD ["/setup_kdc.sh"]
1 change: 1 addition & 0 deletions spring-kafka/src/test/resources/sasl/config/kadm5.acl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/[email protected] *
17 changes: 17 additions & 0 deletions spring-kafka/src/test/resources/sasl/config/kafka_server_jaas.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
KafkaServer {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
keyTab="/etc/kafka/keytabs/kafka.keytab"
principal="kafka/[email protected]"
serviceName="kafka";
};

Client {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
keyTab="/etc/kafka/keytabs/client.keytab"
principal="[email protected]"
serviceName="kafka";
};
17 changes: 17 additions & 0 deletions spring-kafka/src/test/resources/sasl/config/krb5.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[libdefaults]
default_realm = BAELDUNG.COM
dns_lookup_realm = false
dns_lookup_kdc = false
forwardable = true
rdns = true

[realms]
BAELDUNG.COM = {
kdc = kdc
admin_server = kdc
}

[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Server {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
keyTab="/etc/kafka/keytabs/zookeeper.keytab"
principal="zookeeper/[email protected]";
};
Loading

0 comments on commit c1220cf

Please sign in to comment.