Skip to content

Commit 50f5aa5

Browse files
authored
Merge branch 'eugenp:master' into Bael-6477
2 parents 9f2f486 + f2ece83 commit 50f5aa5

File tree

155 files changed

+3280
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3280
-239
lines changed

apache-httpclient/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
<properties>
7474
<mockserver.version>5.6.1</mockserver.version>
75-
<wiremock.version>3.3.1</wiremock.version>
75+
<wiremock.version>3.9.1</wiremock.version>
7676
<!-- http client & core 5 -->
7777
<httpcore5.version>5.2.2</httpcore5.version>
7878
<httpclient5.version>5.2.2</httpclient5.version>

apache-httpclient4/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
<commons-codec.version>1.16.0</commons-codec.version>
233233
<httpasyncclient.version>4.1.5</httpasyncclient.version>
234234
<!-- testing -->
235-
<wiremock.version>3.3.1</wiremock.version>
235+
<wiremock.version>3.9.1</wiremock.version>
236236
<httpcore.version>4.4.16</httpcore.version>
237237
<httpclient.version>4.5.14</httpclient.version>
238238
<mockserver.version>5.11.2</mockserver.version>

apache-kafka/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@
185185
<flink.version>1.16.1</flink.version>
186186
<awaitility.version>3.0.0</awaitility.version>
187187
<org.apache.spark.spark-core.version>2.4.8</org.apache.spark.spark-core.version>
188-
<graphframes.version>0.8.1-spark3.0-s_2.12</graphframes.version>
189188
<com.datastax.spark.spark-cassandra-connector.version>2.5.2</com.datastax.spark.spark-cassandra-connector.version>
190189
<com.datastax.spark.spark-cassandra-connector-java.version>1.6.0-M1</com.datastax.spark.spark-cassandra-connector-java.version>
191190
</properties>

apache-libraries-2/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>camel-jackson</artifactId>
4141
<version>${camel.version}</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.apache.camel</groupId>
45+
<artifactId>camel-http</artifactId>
46+
<version>${camel.version}</version>
47+
</dependency>
4348
<dependency>
4449
<groupId>org.apache.avro</groupId>
4550
<artifactId>avro</artifactId>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.apachecamelpostrequest;
2+
3+
public class Post {
4+
5+
private int userId;
6+
private String title;
7+
private String body;
8+
9+
public Post() {
10+
}
11+
12+
public Post(int userId, String title, String body) {
13+
this.userId = userId;
14+
this.title = title;
15+
this.body = body;
16+
}
17+
18+
public int getUserId() {
19+
return userId;
20+
}
21+
22+
public void setUserId(int userId) {
23+
this.userId = userId;
24+
}
25+
26+
public String getTitle() {
27+
return title;
28+
}
29+
30+
public void setTitle(String title) {
31+
this.title = title;
32+
}
33+
34+
public String getBody() {
35+
return body;
36+
}
37+
38+
public void setBody(String body) {
39+
this.body = body;
40+
}
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.apachecamelpostrequest;
2+
3+
import org.apache.camel.Exchange;
4+
import org.apache.camel.builder.RouteBuilder;
5+
import org.apache.camel.model.dataformat.JsonLibrary;
6+
7+
public class PostRequestRoute extends RouteBuilder {
8+
9+
@Override
10+
public void configure() throws Exception {
11+
12+
from("direct:start").process(exchange -> exchange.getIn()
13+
.setBody(new Post(1, "Java 21", "Virtual Thread")))
14+
.marshal()
15+
.json(JsonLibrary.Jackson)
16+
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
17+
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
18+
.to("https://jsonplaceholder.typicode.com/posts")
19+
.process(exchange -> log.info("The HTTP response code is: {}", exchange.getIn()
20+
.getHeader(Exchange.HTTP_RESPONSE_CODE)))
21+
.process(exchange -> log.info("The response body is: {}", exchange.getIn()
22+
.getBody(String.class)))
23+
.to("mock:result");
24+
25+
from("direct:post").process(exchange -> exchange.getIn()
26+
.setBody("{\"title\":\"Java 21\",\"body\":\"Virtual Thread\",\"userId\":\"1\"}"))
27+
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
28+
.to("https://jsonplaceholder.typicode.com/posts?httpMethod=POST")
29+
.to("mock:post");
30+
}
31+
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.apachecamelpostrequest;
2+
3+
import org.apache.camel.EndpointInject;
4+
import org.apache.camel.Exchange;
5+
import org.apache.camel.Produce;
6+
import org.apache.camel.ProducerTemplate;
7+
import org.apache.camel.builder.RouteBuilder;
8+
import org.apache.camel.component.mock.MockEndpoint;
9+
import org.apache.camel.test.junit5.CamelTestSupport;
10+
import org.junit.jupiter.api.Test;
11+
12+
class PostRequestRouteUnitTest extends CamelTestSupport {
13+
14+
@EndpointInject("mock:result")
15+
protected MockEndpoint resultEndpoint;
16+
17+
@Produce("direct:start")
18+
protected ProducerTemplate template;
19+
20+
@Test
21+
public void givenCamelPostRequestRoute_whenMakingAPostRequestToDummyServer_thenAscertainTheMockEndpointReceiveOneMessage() throws Exception {
22+
resultEndpoint.expectedMessageCount(1);
23+
resultEndpoint.message(0)
24+
.header(Exchange.HTTP_RESPONSE_CODE)
25+
.isEqualTo(201);
26+
resultEndpoint.message(0)
27+
.body()
28+
.isNotNull();
29+
30+
template.sendBody(new Post(1, "Java 21", "Virtual Thread"));
31+
32+
resultEndpoint.assertIsSatisfied();
33+
}
34+
35+
@Override
36+
protected RouteBuilder createRouteBuilder() {
37+
return new PostRequestRoute();
38+
}
39+
40+
}

azure-functions/pom.xml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>azure-functions</artifactId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<name>Azure Java Functions</name>
10+
11+
12+
<parent>
13+
<groupId>com.baeldung</groupId>
14+
<artifactId>parent-modules</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
</parent>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>17</java.version>
21+
<azure.functions.maven.plugin.version>1.24.0</azure.functions.maven.plugin.version>
22+
<azure.functions.java.library.version>3.0.0</azure.functions.java.library.version>
23+
<functionAppName>azure-functions-1722835137455</functionAppName>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>com.microsoft.azure.functions</groupId>
29+
<artifactId>azure-functions-java-library</artifactId>
30+
<version>${azure.functions.java.library.version}</version>
31+
</dependency>
32+
33+
</dependencies>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>3.8.1</version>
41+
<configuration>
42+
<source>${java.version}</source>
43+
<target>${java.version}</target>
44+
<encoding>${project.build.sourceEncoding}</encoding>
45+
</configuration>
46+
</plugin>
47+
<plugin>
48+
<groupId>com.microsoft.azure</groupId>
49+
<artifactId>azure-functions-maven-plugin</artifactId>
50+
<version>${azure.functions.maven.plugin.version}</version>
51+
<configuration>
52+
<!-- function app name -->
53+
<appName>${functionAppName}</appName>
54+
<!-- function app resource group -->
55+
<resourceGroup>java-functions-group</resourceGroup>
56+
<!-- function app service plan name -->
57+
<appServicePlanName>java-functions-app-service-plan</appServicePlanName>
58+
<!-- function app region-->
59+
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-regions for all valid values -->
60+
<region>westus</region>
61+
<!-- function pricingTier, default to be consumption if not specified -->
62+
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-pricing-tiers for all valid values -->
63+
<!-- <pricingTier></pricingTier> -->
64+
65+
<!-- Whether to disable application insights, default is false -->
66+
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details for all valid configurations for application insights-->
67+
<!-- <disableAppInsights></disableAppInsights> -->
68+
<runtime>
69+
<!-- runtime os, could be windows, linux or docker-->
70+
<os>windows</os>
71+
<javaVersion>17</javaVersion>
72+
<!-- for docker function, please set the following parameters -->
73+
<!-- <image>[hub-user/]repo-name[:tag]</image> -->
74+
<!-- <serverId></serverId> -->
75+
<!-- <registryUrl></registryUrl> -->
76+
</runtime>
77+
<appSettings>
78+
<property>
79+
<name>FUNCTIONS_EXTENSION_VERSION</name>
80+
<value>~4</value>
81+
</property>
82+
<property>
83+
<name>AZURE_STORAGE</name>
84+
<value>DefaultEndpointsProtocol=https;AccountName=databasesas;AccountKey=J1yyyyb0m/XXXXXXXXXXXXXXmk9b3kQ0uZeLJHeivQzw+AStT++dUw==;EndpointSuffix=core.windows.net</value>
85+
</property>
86+
<property>
87+
<name>COSMOS_DB</name>
88+
<value>AccountEndpoint=https://baeldungcosmosdbdemo.documents.azure.com:443/;AccountKey=GXPD2zqqpYYYYYYYYKv4sFa66jE2W5XXXXXXXXXXXf33mInPKGxmLuLn6mivocLCACDbbIlhDQ==;</value>
89+
</property>
90+
91+
</appSettings>
92+
</configuration>
93+
<executions>
94+
<execution>
95+
<id>package-functions</id>
96+
<goals>
97+
<goal>package</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<!--Remove obj folder generated by .NET SDK in maven clean-->
103+
<plugin>
104+
<artifactId>maven-clean-plugin</artifactId>
105+
<version>3.1.0</version>
106+
<configuration>
107+
<filesets>
108+
<fileset>
109+
<directory>obj</directory>
110+
</fileset>
111+
</filesets>
112+
</configuration>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.baeldung.azure.functions;
2+
3+
import java.io.BufferedReader;
4+
import java.io.ByteArrayInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import com.baeldung.azure.functions.blob.entity.Employee;
10+
import com.microsoft.azure.functions.annotation.*;
11+
import com.microsoft.azure.functions.*;
12+
13+
/**
14+
* Azure Functions with Azure Blob trigger.
15+
*/
16+
public class BlobTriggerJava {
17+
/**
18+
* This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.
19+
*/
20+
@FunctionName("BlobTriggerJava")
21+
@StorageAccount("AZURE_STORAGE")
22+
public void run(
23+
@BlobTrigger(name = "content", path = "feeds/{name}.csv", dataType = "binary") byte[] content,
24+
@BindingName("name") String fileName,
25+
@CosmosDBOutput(name = "output",
26+
databaseName = "organization",
27+
connection = "COSMOS_DB",
28+
containerName = "employee") OutputBinding<List<Employee>> employeeOutputBinding,
29+
final ExecutionContext context
30+
) {
31+
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + fileName + "\n Size: " + content.length + " Bytes");
32+
employeeOutputBinding.setValue(getEmployeeList(content));
33+
context.getLogger().info("Processing finished");
34+
}
35+
36+
private static List<Employee> getEmployeeList(byte[] content) {
37+
List<Employee> employees = new ArrayList<>();
38+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(content)))) {
39+
String line;
40+
while ((line = reader.readLine()) != null) {
41+
String[] record = line.split(",");
42+
employees.add(new Employee(record[0], record[1], record[2], record[3]));
43+
}
44+
} catch (Exception e) {
45+
throw new RuntimeException(e);
46+
}
47+
return employees;
48+
}
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.azure.functions;
2+
3+
import java.util.*;
4+
5+
import com.baeldung.azure.functions.http.entity.Employee;
6+
import com.microsoft.azure.functions.annotation.*;
7+
import com.microsoft.azure.functions.*;
8+
9+
/**
10+
* Azure Functions with HTTP Trigger.
11+
*/
12+
public class HttpTriggerJava {
13+
/**
14+
* This function listens at endpoint "/api/employee/{paritionKey/{rowKey}?code={Auth code}".
15+
* Way to invoke it using "curl" command in bash:
16+
* 1. curl -d "HTTP Body" /api/employee/{paritionKey/{rowKey}?code={Auth code}
17+
*/
18+
@FunctionName("addEmployee")
19+
@StorageAccount("AZURE_STORAGE")
20+
public HttpResponseMessage run(@HttpTrigger(name = "req", methods = { HttpMethod.POST }, route = "employee/{partitionKey}/{rowKey}",
21+
authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<Employee>> empRequest,
22+
@BindingName("partitionKey") String partitionKey,
23+
@BindingName("rowKey") String rowKey,
24+
@TableOutput(name = "data", tableName = "employee") OutputBinding<Employee> employeeOutputBinding,
25+
final ExecutionContext context) {
26+
context.getLogger().info("Received a http request: " + empRequest.getBody().toString());
27+
28+
Employee employee = new Employee(empRequest.getBody().get().getName(),
29+
empRequest.getBody().get().getDepartment(),
30+
empRequest.getBody().get().getSex(),
31+
partitionKey, rowKey);
32+
employeeOutputBinding.setValue(employee);
33+
34+
return empRequest.createResponseBuilder(HttpStatus.OK)
35+
.body("Employee Inserted")
36+
.build();
37+
}
38+
}

0 commit comments

Comments
 (0)