Skip to content

Commit

Permalink
Merge branch 'main' into gen-sdk-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude authored Jan 5, 2024
2 parents e0a4c02 + 8c4da5d commit ac895ad
Show file tree
Hide file tree
Showing 77 changed files with 40,948 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
a8ec45c8ea4ba559247b654d01b0d35b21a68865
33f3224cb40e3fa8c56ddb88962e3a4e9319685d
430a1a0a5dd4efe78e21526c37bec9dbce036401


7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dependencies {
implementation "com.commercetools.sdk:commercetools-http-client:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-sdk-java-importapi:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-sdk-java-ml:${versions.commercetools}"
}
```

Expand All @@ -61,11 +60,6 @@ dependencies {
<artifactId>commercetools-sdk-java-importapi</artifactId>
<version>${commercetools.version}</version>
</dependency>
<dependency>
<groupId>com.commercetools.sdk</groupId>
<artifactId>commercetools-sdk-java-ml</artifactId>
<version>${commercetools.version}</version>
</dependency>
</dependencies>
```

Expand All @@ -81,7 +75,6 @@ dependencies {
* `commercetools-sdk-java-api`: models and request builders for the product API
* `commercetools-sdk-java-importapi`: models and request builders for the import API
* `commercetools-sdk-java-history`: models and request builders for the audit log API
* `commercetools-sdk-java-ml`: models and request builders for the machine learning API
* `commercetools-sdk-compat-v1`: Compatibility layer for Java v1 SDK
* `commercetools-money`: Provider for JSR-354 money instances
* `commercetools-monitoring-newrelic`: Middleware to integrate NewRelic monitoring
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def documentationProjects= [
":commercetools:commercetools-sdk-java-api",
":commercetools:commercetools-sdk-java-history",
":commercetools:commercetools-sdk-java-importapi",
":commercetools:commercetools-sdk-java-ml",
":commercetools:internal-docs",
":rmf:rmf-java-base"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

package commercetools;

import static java.lang.String.format;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.concurrent.ExecutionException;

import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import com.commercetools.api.defaultconfig.ServiceRegion;
import com.commercetools.api.models.product.ProductPagedQueryResponse;
import commercetools.utils.CommercetoolsTestUtils;

import io.vrap.rmf.base.client.*;
Expand Down Expand Up @@ -40,7 +45,7 @@ public void introspection() throws ExecutionException, InterruptedException {
(credentials.getClientId() + ":" + credentials.getClientSecret()).getBytes(StandardCharsets.UTF_8));

final ApiHttpHeaders headers = new ApiHttpHeaders()
.withHeader(ApiHttpHeaders.AUTHORIZATION, String.format("Basic %s", auth))
.withHeader(ApiHttpHeaders.AUTHORIZATION, format("Basic %s", auth))
.withHeader(ApiHttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
final String body = "token=" + token.getAccessToken();

Expand Down Expand Up @@ -76,7 +81,7 @@ public void revoke() throws ExecutionException, InterruptedException {
.encodeToString(
(credentials.getClientId() + ":" + credentials.getClientSecret()).getBytes(StandardCharsets.UTF_8));
final ApiHttpHeaders headers = new ApiHttpHeaders()
.withHeader(ApiHttpHeaders.AUTHORIZATION, String.format("Basic %s", auth))
.withHeader(ApiHttpHeaders.AUTHORIZATION, format("Basic %s", auth))
.withHeader(ApiHttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

// build the revoke request
Expand All @@ -103,4 +108,28 @@ public void revoke() throws ExecutionException, InterruptedException {

Assertions.assertFalse(tokenIntrospection.getBody().isActive());
}

@Test
public void apiRootWithStaticAuthToken() throws ExecutionException, InterruptedException {
final ClientCredentials credentials = ClientCredentials.of()
.withClientId(CommercetoolsTestUtils.getClientId())
.withClientSecret(CommercetoolsTestUtils.getClientSecret())
.build();
final ClientCredentialsTokenSupplier tokenSupplier = new ClientCredentialsTokenSupplier(
credentials.getClientId(), credentials.getClientSecret(), "",
ServiceRegion.GCP_EUROPE_WEST1.getOAuthTokenUrl(), HttpClientSupplier.of().get());
final AuthenticationToken token = tokenSupplier.getToken().get();

final ApiRootBuilder builder = ApiRootBuilder.of()
.withProjectKey(CommercetoolsTestUtils.getProjectKey())
.withApiBaseUrl(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl())
.withStaticTokenFlow(token);
final ProjectApiRoot projectApiRoot = builder.buildProjectRoot();
final ApiHttpResponse<ProductPagedQueryResponse> productPagedQueryResponseApiHttpResponse = projectApiRoot
.products()
.get()
.executeBlocking();

Assertions.assertEquals(productPagedQueryResponseApiHttpResponse.getStatusCode(), 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public void queryById() {
});
}

@Test
public void exists() {
CartsFixtures.withCart(cart -> {
int statusCode = CommercetoolsTestUtils.getProjectApiRoot()
.carts()
.withKey(cart.getKey())
.head()
.executeBlocking()
.getStatusCode();
Assertions.assertThat(statusCode).isEqualTo(200);
});
}

@Test
public void queryByKey() {
CartsFixtures.withCart(cart -> {
Expand Down
1 change: 0 additions & 1 deletion commercetools/internal-docs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dependencies {
implementation project(":commercetools:commercetools-sdk-java-api")
implementation project(":commercetools:commercetools-sdk-java-importapi")
implementation project(":commercetools:commercetools-sdk-java-ml")
implementation project(":commercetools:commercetools-sdk-java-history")
implementation project(":commercetools:commercetools-http-client")
implementation project(":commercetools:commercetools-okhttp-client4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* <ul>
* <li>{@link com.commercetools.api.client.ByProjectKeyRequestBuilder Project API}</li>
* <li>{@link com.commercetools.importapi.client.ByProjectKeyRequestBuilder Import API}</li>
* <li>{@link com.commercetools.ml.client.ByProjectKeyRequestBuilder Machine learning API}</li>
* <li>{@link com.commercetools.history.client.ByProjectKeyRequestBuilder Audit log API}</li>
* </ul>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import com.commercetools.api.models.product.Attribute;
import com.commercetools.api.models.product.AttributeContainer;
import com.commercetools.api.models.product.AttributesAccessor;
import com.commercetools.api.models.product.ProductReference;
import com.commercetools.api.models.product.ProductVariant;
import com.commercetools.api.models.product.ProductVariantDraftBuilder;
import com.commercetools.api.models.product_type.AttributeDefinition;
import com.commercetools.api.models.product_type.AttributeLocalizedEnumValue;
import com.commercetools.api.models.product_type.AttributePlainEnumValue;
import com.commercetools.api.models.product_type.AttributeType;
import com.commercetools.api.models.product_type.ProductType;
import com.commercetools.ml.models.common.ProductReference;

import io.vrap.rmf.base.client.utils.json.JsonException;

Expand Down
38 changes: 38 additions & 0 deletions examples/spring-dynatrace-oneagent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
**/application.properties

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
1 change: 1 addition & 0 deletions examples/spring-dynatrace-oneagent/.java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
30 changes: 30 additions & 0 deletions examples/spring-dynatrace-oneagent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use an official OpenJDK runtime as a base image
FROM openjdk:17-jdk-slim

ENV DT_PAAS_TOKEN="your PAAS token from Dynatrace (https://docs.dynatrace.com/docs/manage/access-control/access-tokens#paas-token)"
ENV DT_ENVIRONMENT_URL="your environment URL from Dynatrace (https://docs.dynatrace.com/docs/setup-and-configuration/setup-on-container-platforms/docker/set-up-oneagent-on-containers-for-application-only-monitoring#cloud-platforms)"
ENV CTP_CLIENT_SECRET="CTP client secret"
ENV CTP_CLIENT_ID="CTP client ID"
ENV CTP_PROJECT_KEY="CTP project key"

# Set the working directory inside the container
WORKDIR /app

# Copy the packaged JAR file into the container at the specified path
COPY build/libs/spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar /app/spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar

# Expose the port that your Spring Boot application will run on
EXPOSE 8080

RUN apt-get update && \
apt-get install -y wget unzip && \
rm -rf /var/lib/apt/lists/*

# ARGs for Dynatrace OneAgent

RUN mkdir -p /opt/dynatrace/oneagent && ARCHIVE=$(mktemp) && wget -O $ARCHIVE "https://$DT_ENVIRONMENT_URL.live.dynatrace.com/api/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&flavor=default&arch=arm&include=$DT_ONEAGENT_TECHNOLOGY" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE

ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so

# Set the entry point to start Dynatrace OneAgent
ENTRYPOINT [ "java", "-jar", "spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar" ]
40 changes: 40 additions & 0 deletions examples/spring-dynatrace-oneagent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Spring MVC example app

Example to show how Java SDK can be used in a Spring Boot application with Dynatrace OneAgent monitoring.

## Requirements

- A Composable Commerce Project with a configured [API Client](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client).
Necessary scopes: `view_published_products`, `manage_orders`
- Your Project must have existing products containing variants with SKUs, and at least one customer, the storefront search endpoint must be active.
- If your Project is currently empty, you can install the [SUNRISE sample data](https://docs.commercetools.com/sdk/sunrise-data).

## Installation

1. Clone/Download the example folder.
2. Navigate to the path `spring-dynatrace-oneagent/`.
3. Register the client credentials in environment variables:
`CTP_CLIENT_ID`, `CTP_CLIENT_SECRET` and `CTP_PROJECT_KEY`

## Using the Spring MVC Example app

### Install Dynatrace OneAgent
Follow the instructions on the [Dynatrace OneAgent page](
https://docs.dynatrace.com/docs/setup-and-configuration/dynatrace-oneagent#tabgroup--technology-support--operating-systems) to install the OneAgent on your system.

#### Install Dynatrace OneAgent on Mac
Currently, it is NOT possible to install Dynatrace OneAgent on macOS. For this case a [Dockerfile](./Dockerfile) is provided.
Use this file to build the application with the OneAgent included on Docker.
1. Run `./gradlew bootJar` to build a JAR file. This JAR file is necessary to build the Docker image.
2. Update ENV variables in the [Dockerfile](./Dockerfile) with your Dynatrace and CTP credentials.
3. Run `docker build -t spring-dynatrace-oneagent .` to build the Docker image.
4. Run `docker run -p 8080:8080 spring-dynatrace-oneagent` to start the Docker container.

### Navigate the application

1. Open a new browser window/tab
2. Navigate to [http://localhost:8080/p](http://localhost:8080/p) and a list of products should appear.

## Using Dynatrace with OpenTelemetry

If you want to use Dynatrace with OpenTelemetry, we also provide [an example Spring Boot application](../spring-otel).
42 changes: 42 additions & 0 deletions examples/spring-dynatrace-oneagent/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.4'
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.commercetools.sdk.examples'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

repositories {
mavenLocal()
mavenCentral()
}

ext {
versions = [
commercetools: "17.3.0",
]
}

dependencies {
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-apachehttp-client:${versions.commercetools}"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
developmentOnly "org.springframework.boot:spring-boot-devtools"
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit ac895ad

Please sign in to comment.