Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from eugenp/master
Update
- Loading branch information
Showing
3,411 changed files
with
110,310 additions
and
15,575 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
2 changes: 2 additions & 0 deletions
2
JGit/src/test/java/com/baeldung/jgit/JGitBugIntegrationTest.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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
<?xml version="1.0"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>akka-http</artifactId> | ||
<name>akka-http</name> | ||
|
||
<parent> | ||
<artifactId>parent-modules</artifactId> | ||
<groupId>com.baeldung</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-http_2.12</artifactId> | ||
<version>${akka.http.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-stream_2.12</artifactId> | ||
<version>2.5.11</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-http-jackson_2.12</artifactId> | ||
<version>${akka.http.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-http-testkit_2.12</artifactId> | ||
<version>${akka.http.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<akka.http.version>10.0.11</akka.http.version> | ||
<akka.stream.version>2.5.11</akka.stream.version> | ||
</properties> | ||
</project> |
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,26 @@ | ||
package com.baeldung.akkahttp; | ||
|
||
public class User { | ||
|
||
private final Long id; | ||
|
||
private final String name; | ||
|
||
public User() { | ||
this.name = ""; | ||
this.id = null; | ||
} | ||
|
||
public User(Long id, String name) { | ||
this.name = name; | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
akka-http/src/main/java/com/baeldung/akkahttp/UserActor.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,41 @@ | ||
package com.baeldung.akkahttp; | ||
|
||
import akka.actor.AbstractActor; | ||
import akka.actor.Props; | ||
import akka.japi.pf.FI; | ||
import com.baeldung.akkahttp.UserMessages.ActionPerformed; | ||
import com.baeldung.akkahttp.UserMessages.CreateUserMessage; | ||
import com.baeldung.akkahttp.UserMessages.GetUserMessage; | ||
|
||
|
||
class UserActor extends AbstractActor { | ||
|
||
private UserService userService = new UserService(); | ||
|
||
static Props props() { | ||
return Props.create(UserActor.class); | ||
} | ||
|
||
@Override | ||
public Receive createReceive() { | ||
return receiveBuilder() | ||
.match(CreateUserMessage.class, handleCreateUser()) | ||
.match(GetUserMessage.class, handleGetUser()) | ||
.build(); | ||
} | ||
|
||
private FI.UnitApply<CreateUserMessage> handleCreateUser() { | ||
return createUserMessageMessage -> { | ||
userService.createUser(createUserMessageMessage.getUser()); | ||
sender().tell(new ActionPerformed(String.format("User %s created.", createUserMessageMessage.getUser() | ||
.getName())), getSelf()); | ||
}; | ||
} | ||
|
||
private FI.UnitApply<GetUserMessage> handleGetUser() { | ||
return getUserMessageMessage -> { | ||
sender().tell(userService.getUser(getUserMessageMessage.getUserId()), getSelf()); | ||
}; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
akka-http/src/main/java/com/baeldung/akkahttp/UserMessages.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 @@ | ||
package com.baeldung.akkahttp; | ||
|
||
import java.io.Serializable; | ||
|
||
public interface UserMessages { | ||
|
||
class ActionPerformed implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final String description; | ||
|
||
public ActionPerformed(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} | ||
|
||
class CreateUserMessage implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private final User user; | ||
|
||
public CreateUserMessage(User user) { | ||
this.user = user; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
} | ||
|
||
class GetUserMessage implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private final Long userId; | ||
|
||
public GetUserMessage(Long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Long getUserId() { | ||
return userId; | ||
} | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
akka-http/src/main/java/com/baeldung/akkahttp/UserServer.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,70 @@ | ||
package com.baeldung.akkahttp; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import akka.actor.ActorRef; | ||
import akka.actor.ActorSystem; | ||
import akka.http.javadsl.marshallers.jackson.Jackson; | ||
import akka.http.javadsl.model.StatusCodes; | ||
import akka.http.javadsl.server.HttpApp; | ||
import akka.http.javadsl.server.Route; | ||
import akka.pattern.PatternsCS; | ||
import akka.util.Timeout; | ||
import com.baeldung.akkahttp.UserMessages.ActionPerformed; | ||
import com.baeldung.akkahttp.UserMessages.CreateUserMessage; | ||
import com.baeldung.akkahttp.UserMessages.GetUserMessage; | ||
import scala.concurrent.duration.Duration; | ||
import static akka.http.javadsl.server.PathMatchers.*; | ||
|
||
class UserServer extends HttpApp { | ||
|
||
private final ActorRef userActor; | ||
|
||
Timeout timeout = new Timeout(Duration.create(5, TimeUnit.SECONDS)); | ||
|
||
UserServer(ActorRef userActor) { | ||
this.userActor = userActor; | ||
} | ||
|
||
@Override | ||
public Route routes() { | ||
return path("users", this::postUser) | ||
.orElse(path(segment("users").slash(longSegment()), id -> | ||
route(getUser(id)))); | ||
} | ||
|
||
private Route getUser(Long id) { | ||
return get(() -> { | ||
CompletionStage<Optional<User>> user = PatternsCS.ask(userActor, new GetUserMessage(id), timeout) | ||
.thenApply(obj -> (Optional<User>) obj); | ||
|
||
return onSuccess(() -> user, performed -> { | ||
if (performed.isPresent()) | ||
return complete(StatusCodes.OK, performed.get(), Jackson.marshaller()); | ||
else | ||
return complete(StatusCodes.NOT_FOUND); | ||
}); | ||
}); | ||
} | ||
|
||
private Route postUser() { | ||
return route(post(() -> entity(Jackson.unmarshaller(User.class), user -> { | ||
CompletionStage<ActionPerformed> userCreated = PatternsCS.ask(userActor, new CreateUserMessage(user), timeout) | ||
.thenApply(obj -> (ActionPerformed) obj); | ||
|
||
return onSuccess(() -> userCreated, performed -> { | ||
return complete(StatusCodes.CREATED, performed, Jackson.marshaller()); | ||
}); | ||
}))); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
ActorSystem system = ActorSystem.create("userServer"); | ||
ActorRef userActor = system.actorOf(UserActor.props(), "userActor"); | ||
UserServer server = new UserServer(userActor); | ||
server.startServer("localhost", 8080, system); | ||
} | ||
|
||
} |
Oops, something went wrong.