-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
- Loading branch information
Showing
106 changed files
with
12,071 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
spring-data-opensearch-examples/spring-boot-java-client-gradle/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Spring Data OpenSearch Java Client Spring Boot Example Project | ||
=== | ||
|
||
This sample project demonstrates the usage of the [Spring Data OpenSearch](https://github.com/opensearch-project/spring-data-opensearch/) in the typical Spring Boot web application using [opensearch-java](https://github.com/opensearch-project/opensearch-java) client. The application assumes that there is an [OpenSearch](https://opensearch.org) service up and running on the local machine, available at `https://localhost:9200` (protected by basic authentication with default credentials). | ||
|
||
1. The easiest way to get [OpenSearch](https://opensearch.org) service up and running is by using [Docker](https://www.docker.com/): | ||
|
||
```shell | ||
docker run -p 9200:9200 -e "discovery.type=single-node" opensearchproject/opensearch:2.11.1 | ||
``` | ||
|
||
2. Build and run the project using [Gradle](https://gradle.org/): | ||
|
||
```shell | ||
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootRun | ||
``` | ||
|
||
3. Exercise the REST endpoint available at: `http://localhost:8080/marketplace` | ||
|
||
- Fetch all products: `curl 'http://localhost:8080/marketplace/search'` | ||
- Search products by name: `curl 'http://localhost:8080/marketplace/search?name=pillow'` | ||
- Search products by name and price greater than: `curl 'http://localhost:8080/marketplace/search?name=pillow&price=35.0'` |
63 changes: 63 additions & 0 deletions
63
spring-data-opensearch-examples/spring-boot-java-client-gradle/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
alias(springLibs.plugins.spring.boot) | ||
alias(pluginLibs.plugins.spotless) | ||
alias(pluginLibs.plugins.editorconfig) | ||
id("java-conventions") | ||
} | ||
|
||
buildscript { | ||
dependencies { | ||
classpath(pluginLibs.editorconfig) | ||
classpath(pluginLibs.spotless) | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":spring-data-opensearch")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
api(project(":spring-data-opensearch-starter")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
implementation(springLibs.boot.web) | ||
implementation(jacksonLibs.core) | ||
implementation(jacksonLibs.databind) | ||
implementation(opensearchLibs.client) | ||
implementation(opensearchLibs.java.client) | ||
testImplementation(springLibs.test) | ||
testImplementation(springLibs.boot.test) | ||
testImplementation(springLibs.boot.test.autoconfigure) | ||
testImplementation(opensearchLibs.testcontainers) | ||
testImplementation(project(":spring-data-opensearch-test-autoconfigure")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
|
||
constraints { | ||
implementation("ch.qos.logback:logback-classic") { | ||
version { | ||
require("1.4.12") | ||
} | ||
because("Fixes CVE-2023-6378") | ||
} | ||
} | ||
} | ||
|
||
description = "Spring Data OpenSearch Spring Boot Example Project" | ||
|
||
spotless { | ||
java { | ||
target("src/main/java/**/*.java", "src/test/java/org/opensearch/**/*.java") | ||
|
||
trimTrailingWhitespace() | ||
indentWithSpaces() | ||
endWithNewline() | ||
|
||
removeUnusedImports() | ||
importOrder() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...-java-client-gradle/src/main/java/org/opensearch/data/example/MarketplaceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.data.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration; | ||
|
||
@SpringBootApplication(exclude = ElasticsearchDataAutoConfiguration.class) | ||
public class MarketplaceApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(MarketplaceConfiguration.class, args); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ava-client-gradle/src/main/java/org/opensearch/data/example/MarketplaceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.data.example; | ||
|
||
import java.security.KeyManagementException; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; | ||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; | ||
import org.apache.http.ssl.SSLContextBuilder; | ||
import org.opensearch.client.RestClientBuilder; | ||
import org.opensearch.data.example.repository.MarketplaceRepository; | ||
import org.opensearch.spring.boot.autoconfigure.RestClientBuilderCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; | ||
|
||
@Configuration | ||
@EnableElasticsearchRepositories(basePackageClasses = MarketplaceRepository.class) | ||
@ComponentScan(basePackageClasses = MarketplaceConfiguration.class) | ||
public class MarketplaceConfiguration { | ||
/** | ||
* Allow to connect to the OpenSearch instance which uses self-signed certificates | ||
*/ | ||
@Bean | ||
RestClientBuilderCustomizer customizer() { | ||
return new RestClientBuilderCustomizer() { | ||
@Override | ||
public void customize(HttpAsyncClientBuilder builder) { | ||
try { | ||
builder.setSSLContext(new SSLContextBuilder() | ||
.loadTrustMaterial(null, new TrustSelfSignedStrategy()) | ||
.build()); | ||
} catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) { | ||
throw new RuntimeException("Failed to initialize SSL Context instance", ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void customize(RestClientBuilder builder) { | ||
// No additional customizations needed | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.