Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -35,7 +35,12 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
|
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
|
||||||
<outputDirectory>target/docs/asciidoc</outputDirectory>
|
<outputDirectory>target/docs/asciidoc</outputDirectory>
|
||||||
|
<attributes>
|
||||||
|
<pdf-stylesdir>${project.basedir}/src/themes</pdf-stylesdir>
|
||||||
|
<pdf-style>custom</pdf-style>
|
||||||
|
</attributes>
|
||||||
<backend>pdf</backend>
|
<backend>pdf</backend>
|
||||||
|
<doctype>book</doctype>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
== Introduction Section
|
:icons: font
|
||||||
|
|
||||||
Hi. I'm a simple test to see if this Maven build is working. If you see me in a nice PDF, then it means everything is [red]#working#.
|
|
||||||
|
= Generating book with AsciiDoctorj
|
||||||
|
Baeldung
|
||||||
|
|
||||||
|
[abstract]
|
||||||
|
This is the actual content.
|
||||||
|
|
||||||
|
== First Section
|
||||||
|
|
||||||
|
This is first section of the book where you can include some nice icons like icon:comment[].
|
||||||
|
You can also create http://www.baeldung.com[links]
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
title_page:
|
||||||
|
align: left
|
||||||
|
|
||||||
|
page:
|
||||||
|
layout: portrait
|
||||||
|
margin: [0.75in, 1in, 0.75in, 1in]
|
||||||
|
size: A4
|
||||||
|
base:
|
||||||
|
font_color: #333333
|
||||||
|
line_height_length: 17
|
||||||
|
line_height: $base_line_height_length / $base_font_size
|
||||||
|
link:
|
||||||
|
font_color: #009900
|
||||||
|
|
||||||
|
header:
|
||||||
|
height: 0.5in
|
||||||
|
line_height: 1
|
||||||
|
recto_content:
|
||||||
|
center: '{document-title}'
|
||||||
|
verso_content:
|
||||||
|
center: '{document-title}'
|
||||||
|
|
||||||
|
footer:
|
||||||
|
height: 0.5in
|
||||||
|
line_height: 1
|
||||||
|
recto_content:
|
||||||
|
right: '{chapter-title} | *{page-number}*'
|
||||||
|
verso_content:
|
||||||
|
left: '*{page-number}* | {chapter-title}'
|
||||||
+2
-2
@@ -391,7 +391,7 @@
|
|||||||
<logback.version>1.1.7</logback.version>
|
<logback.version>1.1.7</logback.version>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>21.0</guava.version>
|
<guava.version>22.0</guava.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<bouncycastle.version>1.55</bouncycastle.version>
|
<bouncycastle.version>1.55</bouncycastle.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
@@ -408,7 +408,7 @@
|
|||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<mockito.version>1.10.19</mockito.version>
|
<mockito.version>2.8.9</mockito.version>
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
|
|||||||
+1
@@ -21,3 +21,4 @@ public class CyclicBarrierExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.application;
|
||||||
|
|
||||||
|
import com.baeldung.entities.User;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Map<User, User> users = new HashMap<>();
|
||||||
|
User user1 = new User(1L, "John", "[email protected]");
|
||||||
|
User user2 = new User(2L, "Jennifer", "[email protected]");
|
||||||
|
User user3 = new User(3L, "Mary", "[email protected]");
|
||||||
|
|
||||||
|
users.put(user1, user1);
|
||||||
|
users.put(user2, user2);
|
||||||
|
users.put(user3, user3);
|
||||||
|
|
||||||
|
if (users.containsKey(user1)) {
|
||||||
|
System.out.print("User found in the collection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.baeldung.entities;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(User.class);
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public User(long id, String name, String email) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null) return false;
|
||||||
|
if (this.getClass() != o.getClass()) return false;
|
||||||
|
User user = (User) o;
|
||||||
|
return id != user.id && (!name.equals(user.name) && !email.equals(user.email));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 31 * hash + (int) id;
|
||||||
|
hash = 31 * hash + (name == null ? 0 : name.hashCode());
|
||||||
|
hash = 31 * hash + (email == null ? 0 : email.hashCode());
|
||||||
|
logger.info("hashCode() method called - Computed hash: " + hash);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
// getters and setters here
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.application;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ApplicationTest {
|
||||||
|
|
||||||
|
private ByteArrayOutputStream outContent;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpPrintStreamInstance() throws Exception {
|
||||||
|
this.outContent = new ByteArrayOutputStream();
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDownByteArrayOutputStream() throws Exception {
|
||||||
|
outContent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void main_NoInputState_TextPrintedToConsole() throws Exception {
|
||||||
|
Application.main(new String[]{});
|
||||||
|
assertEquals("User found in the collection", outContent.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.entities;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class UserTest {
|
||||||
|
|
||||||
|
private User user;
|
||||||
|
private User comparisonUser;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpUserInstances() {
|
||||||
|
this.user = new User(1L, "test", "[email protected]");
|
||||||
|
this.comparisonUser = this.user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDownUserInstances() {
|
||||||
|
user = null;
|
||||||
|
comparisonUser = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equals_EqualUserInstance_TrueAssertion(){
|
||||||
|
Assert.assertTrue(user.equals(comparisonUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hashCode_UserHash_TrueAssertion() {
|
||||||
|
Assert.assertEquals(1792276941, user.hashCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,6 +63,6 @@ public class MappedByteBufferUnitTest {
|
|||||||
|
|
||||||
private Path getFileURIFromResources(String fileName) throws Exception {
|
private Path getFileURIFromResources(String fileName) throws Exception {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
return Paths.get(classLoader.getResource(fileName).getPath());
|
return Paths.get(classLoader.getResource(fileName).toURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class JavaMoneyUnitTest {
|
public class JavaMoneyUnitManualTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCurrencyCode_whenString_thanExist() {
|
public void givenCurrencyCode_whenString_thanExist() {
|
||||||
@@ -179,7 +179,7 @@ public class JavaMoneyUnitTest {
|
|||||||
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder
|
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder
|
||||||
.of(Locale.US)
|
.of(Locale.US)
|
||||||
.set(CurrencyStyle.NAME)
|
.set(CurrencyStyle.NAME)
|
||||||
.set("pattern", "00000.00 ¤")
|
.set("pattern", "00000.00 �")
|
||||||
.build());
|
.build());
|
||||||
String customFormatted = customFormat.format(oneDollar);
|
String customFormatted = customFormat.format(oneDollar);
|
||||||
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.baeldung.stream;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.collectingAndThen;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.stream.mycollectors.MyImmutableListCollector;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
public class StreamToImmutableTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingCollectingToImmutableSet_thenSuccess() {
|
||||||
|
List<String> givenList = Arrays.asList("a", "b", "c");
|
||||||
|
List<String> result = givenList.stream()
|
||||||
|
.collect(collectingAndThen(toSet(), ImmutableList::copyOf));
|
||||||
|
|
||||||
|
System.out.println(result.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingCollectingToUnmodifiableList_thenSuccess() {
|
||||||
|
List<String> givenList = new ArrayList<>(Arrays.asList("a", "b", "c"));
|
||||||
|
List<String> result = givenList.stream()
|
||||||
|
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
|
||||||
|
|
||||||
|
System.out.println(result.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCollectToImmutableList_thenSuccess() {
|
||||||
|
List<Integer> list = IntStream.range(0, 9)
|
||||||
|
.boxed()
|
||||||
|
.collect(ImmutableList.toImmutableList());
|
||||||
|
|
||||||
|
System.out.println(list.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCollectToMyImmutableListCollector_thenSuccess() {
|
||||||
|
List<String> givenList = Arrays.asList("a", "b", "c", "d");
|
||||||
|
List<String> result = givenList.stream()
|
||||||
|
.collect(MyImmutableListCollector.toImmutableList());
|
||||||
|
|
||||||
|
System.out.println(result.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenPassingSupplier_thenSuccess() {
|
||||||
|
List<String> givenList = Arrays.asList("a", "b", "c", "d");
|
||||||
|
List<String> result = givenList.stream()
|
||||||
|
.collect(MyImmutableListCollector.toImmutableList(LinkedList::new));
|
||||||
|
|
||||||
|
System.out.println(result.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.baeldung.stream.mycollectors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Collector;
|
||||||
|
|
||||||
|
public class MyImmutableListCollector {
|
||||||
|
|
||||||
|
public static <T, A extends List<T>> Collector<T, A, List<T>> toImmutableList(Supplier<A> supplier) {
|
||||||
|
return Collector.of(supplier, List::add, (left, right) -> {
|
||||||
|
left.addAll(right);
|
||||||
|
return left;
|
||||||
|
}, Collections::unmodifiableList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Collector<T, List<T>, List<T>> toImmutableList() {
|
||||||
|
return toImmutableList(ArrayList::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -105,6 +106,7 @@ public class JavaScannerUnitTest {
|
|||||||
public void whenScanString_thenCorrect() throws IOException {
|
public void whenScanString_thenCorrect() throws IOException {
|
||||||
final String input = "Hello 1 F 3.5";
|
final String input = "Hello 1 F 3.5";
|
||||||
final Scanner scanner = new Scanner(input);
|
final Scanner scanner = new Scanner(input);
|
||||||
|
scanner.useLocale(Locale.US);
|
||||||
|
|
||||||
assertEquals("Hello", scanner.next());
|
assertEquals("Hello", scanner.next());
|
||||||
assertEquals(1, scanner.nextInt());
|
assertEquals(1, scanner.nextInt());
|
||||||
|
|||||||
+1
-1
@@ -4,5 +4,5 @@ This is the implementation of a [spring-hypermedia-api][1] client using Feign.
|
|||||||
|
|
||||||
[1]: https://github.com/eugenp/spring-hypermedia-api
|
[1]: https://github.com/eugenp/spring-hypermedia-api
|
||||||
|
|
||||||
###Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Intro to Feign](http://www.baeldung.com/intro-to-feign)
|
- [Intro to Feign](http://www.baeldung.com/intro-to-feign)
|
||||||
|
|||||||
+1
-4
@@ -1,12 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung.feign</groupId>
|
<groupId>com.baeldung.feign</groupId>
|
||||||
<artifactId>feign-client</artifactId>
|
<artifactId>feign-client</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>grpc</groupId>
|
||||||
|
<artifactId>grpc-demo</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>grpc-demo</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<io.grpc.version>1.5.0</io.grpc.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.grpc</groupId>
|
||||||
|
<artifactId>grpc-netty</artifactId>
|
||||||
|
<version>${io.grpc.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.grpc</groupId>
|
||||||
|
<artifactId>grpc-protobuf</artifactId>
|
||||||
|
<version>${io.grpc.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.grpc</groupId>
|
||||||
|
<artifactId>grpc-stub</artifactId>
|
||||||
|
<version>${io.grpc.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<extensions>
|
||||||
|
<extension>
|
||||||
|
<groupId>kr.motd.maven</groupId>
|
||||||
|
<artifactId>os-maven-plugin</artifactId>
|
||||||
|
<version>1.5.0.Final</version>
|
||||||
|
</extension>
|
||||||
|
</extensions>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.xolstice.maven.plugins</groupId>
|
||||||
|
<artifactId>protobuf-maven-plugin</artifactId>
|
||||||
|
<version>0.5.0</version>
|
||||||
|
<configuration>
|
||||||
|
<protocArtifact>
|
||||||
|
com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
|
||||||
|
</protocArtifact>
|
||||||
|
<pluginId>grpc-java</pluginId>
|
||||||
|
<pluginArtifact>
|
||||||
|
io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
|
||||||
|
</pluginArtifact>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
<goal>compile-custom</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.baeldung.grpc.client;
|
||||||
|
|
||||||
|
import org.baeldung.grpc.HelloRequest;
|
||||||
|
import org.baeldung.grpc.HelloResponse;
|
||||||
|
import org.baeldung.grpc.HelloServiceGrpc;
|
||||||
|
|
||||||
|
import io.grpc.ManagedChannel;
|
||||||
|
import io.grpc.ManagedChannelBuilder;
|
||||||
|
|
||||||
|
public class GrpcClient {
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
|
||||||
|
.usePlaintext(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HelloServiceGrpc.HelloServiceBlockingStub stub
|
||||||
|
= HelloServiceGrpc.newBlockingStub(channel);
|
||||||
|
|
||||||
|
HelloResponse helloResponse = stub.hello(HelloRequest.newBuilder()
|
||||||
|
.setFirstName("Baeldung")
|
||||||
|
.setLastName("gRPC")
|
||||||
|
.build());
|
||||||
|
|
||||||
|
System.out.println("Response received from server:\n" + helloResponse);
|
||||||
|
|
||||||
|
channel.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.baeldung.grpc.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import io.grpc.Server;
|
||||||
|
import io.grpc.ServerBuilder;
|
||||||
|
|
||||||
|
public class GrpcServer {
|
||||||
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
Server server = ServerBuilder.forPort(8080)
|
||||||
|
.addService(new HelloServiceImpl()).build();
|
||||||
|
|
||||||
|
System.out.println("Starting server...");
|
||||||
|
server.start();
|
||||||
|
System.out.println("Server started!");
|
||||||
|
server.awaitTermination();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.baeldung.grpc.server;
|
||||||
|
|
||||||
|
import org.baeldung.grpc.HelloRequest;
|
||||||
|
import org.baeldung.grpc.HelloResponse;
|
||||||
|
import org.baeldung.grpc.HelloServiceGrpc.HelloServiceImplBase;
|
||||||
|
|
||||||
|
import io.grpc.stub.StreamObserver;
|
||||||
|
|
||||||
|
public class HelloServiceImpl extends HelloServiceImplBase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hello(
|
||||||
|
HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
|
||||||
|
System.out.println("Request received from client:\n" + request);
|
||||||
|
|
||||||
|
String greeting = new StringBuilder().append("Hello, ")
|
||||||
|
.append(request.getFirstName())
|
||||||
|
.append(" ")
|
||||||
|
.append(request.getLastName())
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
HelloResponse response = HelloResponse.newBuilder()
|
||||||
|
.setGreeting(greeting)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
responseObserver.onNext(response);
|
||||||
|
responseObserver.onCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
package org.baeldung.grpc;
|
||||||
|
|
||||||
|
message HelloRequest {
|
||||||
|
string firstName = 1;
|
||||||
|
string lastName = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message HelloResponse {
|
||||||
|
string greeting = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
service HelloService {
|
||||||
|
rpc hello(HelloRequest) returns (HelloResponse);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#application.secret = 2o128940921eo298e21
|
||||||
|
#db = /url/to/the/datastore
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>log/jooby.log</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>log/jooby.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<totalSizeCap>1mb</totalSizeCap>
|
||||||
|
<maxHistory>7</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>log/access.log</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>log/access.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<totalSizeCap>1mb</totalSizeCap>
|
||||||
|
<maxHistory>7</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<encoder>
|
||||||
|
<pattern>%msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.jooby.RequestLogger" additivity="false">
|
||||||
|
<appender-ref ref="ACCESS" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>jooby</artifactId>
|
||||||
|
<groupId>com.baeldung.jooby</groupId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>jooby</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jooby</groupId>
|
||||||
|
<artifactId>modules</artifactId>
|
||||||
|
<version>1.1.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jooby.version>1.1.3</jooby.version>
|
||||||
|
<application.class>com.baeldung.jooby.App</application.class>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jooby</groupId>
|
||||||
|
<artifactId>jooby-netty</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jooby</groupId>
|
||||||
|
<artifactId>jooby-jedis</artifactId>
|
||||||
|
<version>1.1.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.rest-assured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Insert title here</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form enctype="application/x-www-form-urlencoded" action="/submitForm" method="post">
|
||||||
|
<input name="id" />
|
||||||
|
<input name="name" />
|
||||||
|
<input name="email" />
|
||||||
|
<input name="phone" />
|
||||||
|
<input name="address" />
|
||||||
|
<input type="submit" value="Submit"/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Insert title here</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
i m welcomed
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Name of application (make sure it has no spaces)
|
||||||
|
name: "${project.artifactId}"
|
||||||
|
|
||||||
|
# Display name of application (can have spaces)
|
||||||
|
display_name: "${project.name}"
|
||||||
|
|
||||||
|
# Type of launcher (CONSOLE or DAEMON)
|
||||||
|
type: DAEMON
|
||||||
|
|
||||||
|
# Java class to run
|
||||||
|
main_class: "${application.class}"
|
||||||
|
|
||||||
|
domain: "${project.groupId}"
|
||||||
|
|
||||||
|
short_description: "${project.artifactId}"
|
||||||
|
|
||||||
|
# Platform launchers to generate (WINDOWS, LINUX, MAC_OSX)
|
||||||
|
# Linux launcher is suitable for Bourne shells (e.g. Linux/BSD)
|
||||||
|
platforms: [ LINUX ]
|
||||||
|
|
||||||
|
# Working directory for app
|
||||||
|
# RETAIN will not change the working directory
|
||||||
|
# APP_HOME will change the working directory to the home of the app
|
||||||
|
# (where it was intalled) before running the main class
|
||||||
|
working_dir_mode: RETAIN
|
||||||
|
|
||||||
|
# Minimum version of java required (system will be searched for acceptable jvm)
|
||||||
|
min_java_version: "1.8"
|
||||||
|
|
||||||
|
# Min/max fixed memory (measured in MB)
|
||||||
|
min_java_memory: 512
|
||||||
|
max_java_memory: 512
|
||||||
|
|
||||||
|
# Min/max memory by percentage of system
|
||||||
|
#min_java_memory_pct: 10
|
||||||
|
#max_java_memory_pct: 20
|
||||||
|
|
||||||
|
# Try to create a symbolic link to java executable in <app_home>/run with
|
||||||
|
# the name of "<app_name>-java" so that commands like "ps" will make it
|
||||||
|
# easier to find your app
|
||||||
|
symlink_java: true
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.baeldung.jooby;
|
||||||
|
|
||||||
|
import org.jooby.Jooby;
|
||||||
|
import org.jooby.Mutant;
|
||||||
|
import org.jooby.Session;
|
||||||
|
import org.jooby.jedis.Redis;
|
||||||
|
import org.jooby.jedis.RedisSessionStore;
|
||||||
|
|
||||||
|
import com.baeldung.jooby.bean.Employee;
|
||||||
|
|
||||||
|
public class App extends Jooby {
|
||||||
|
|
||||||
|
{
|
||||||
|
port(8080);
|
||||||
|
securePort(8443);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
get("/", () -> "Hello World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
get("/user/{id}", req -> "Hello user : " + req.param("id").value());
|
||||||
|
get("/user/:id", req -> "Hello user: " + req.param("id").value());
|
||||||
|
get("/uid:{id}", req -> "Hello User with id : uid" + req.param("id").value());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
onStart(() -> {
|
||||||
|
System.out.println("starting app");
|
||||||
|
});
|
||||||
|
|
||||||
|
onStop(() -> {
|
||||||
|
System.out.println("stopping app");
|
||||||
|
});
|
||||||
|
|
||||||
|
onStarted(() -> {
|
||||||
|
System.out.println("app started");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
get("/login", () -> "Hello from Baeldung");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
post("/save", req -> {
|
||||||
|
Mutant token = req.param("token");
|
||||||
|
return token.intValue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
{
|
||||||
|
assets("/employee", "form.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/submitForm", req -> {
|
||||||
|
Employee employee = req.params(Employee.class);
|
||||||
|
// TODO
|
||||||
|
return "empoyee data saved successfullly";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
get("/filter", (req, resp, chain) -> {
|
||||||
|
// TODO
|
||||||
|
// resp.send(...);
|
||||||
|
chain.next(req, resp);
|
||||||
|
});
|
||||||
|
get("/filter", (req, resp) -> {
|
||||||
|
resp.send("filter response");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// cookieSession();
|
||||||
|
|
||||||
|
// use(new Redis());
|
||||||
|
//
|
||||||
|
// session(RedisSessionStore.class);
|
||||||
|
|
||||||
|
get("/session", req -> {
|
||||||
|
Session session = req.session();
|
||||||
|
session.set("token", "value");
|
||||||
|
return session.get("token").value();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
|
||||||
|
run(App::new, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.jooby.bean;
|
||||||
|
|
||||||
|
public class Employee {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
String name;
|
||||||
|
String email;
|
||||||
|
|
||||||
|
public Employee(String id, String name, String email) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.baeldung.jooby.mvc;
|
||||||
|
|
||||||
|
import org.jooby.Result;
|
||||||
|
import org.jooby.Results;
|
||||||
|
import org.jooby.mvc.GET;
|
||||||
|
import org.jooby.mvc.Path;
|
||||||
|
|
||||||
|
@Path("/hello")
|
||||||
|
public class GetController {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public String hello() {
|
||||||
|
return "Hello Baeldung";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/home")
|
||||||
|
public Result home() {
|
||||||
|
return Results.html("welcome").put("model", new Object());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user