Skip to content

Commit a49358c

Browse files
michael-prattCalamarBicefalo
authored andcommitted
More server stuff; create client and test
1 parent 56c27f3 commit a49358c

11 files changed

Lines changed: 139 additions & 35 deletions

File tree

‎micronaut/hello-world-server/pom.xml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<artifactId>hello-world-server</artifactId>
55
<version>0.1</version>
66
<properties>
7-
<exec.mainClass>hello.world.server.Application</exec.mainClass>
7+
<exec.mainClass>com.baeldung.micronaut.server.ServerApplication</exec.mainClass>
88
<micronaut.version>1.0.0.M2</micronaut.version>
99
<jdk.version>9</jdk.version>
1010
</properties>
@@ -69,7 +69,12 @@
6969
<version>4.12</version>
7070
<scope>test</scope>
7171
</dependency>
72-
</dependencies>
72+
<dependency>
73+
<groupId>io.projectreactor</groupId>
74+
<artifactId>reactor-core</artifactId>
75+
<version>3.1.6.RELEASE</version>
76+
</dependency>
77+
</dependencies>
7378
<build>
7479
<plugins>
7580
<plugin>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.micronaut.client;
2+
3+
import io.micronaut.http.annotation.Get;
4+
import io.micronaut.http.client.Client;
5+
6+
@Client("/greet")
7+
public interface GreetingClient {
8+
@Get("/{name}")
9+
String greet(String name);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.micronaut.server;
2+
3+
import io.micronaut.runtime.Micronaut;
4+
5+
public class ServerApplication {
6+
7+
public static void main(String[] args) {
8+
Micronaut.run(ServerApplication.class);
9+
}
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.micronaut.server.controller;
2+
3+
import com.baeldung.micronaut.server.service.GreetingService;
4+
import io.micronaut.http.annotation.Controller;
5+
import io.micronaut.http.annotation.Get;
6+
import reactor.core.publisher.Mono;
7+
8+
import javax.inject.Inject;
9+
10+
@Controller("/async/greet")
11+
public class AsyncGreetController {
12+
13+
@Inject
14+
private GreetingService greetingService;
15+
16+
@Get("/{name}")
17+
public Mono<String> greet(String name) {
18+
return Mono.just(greetingService.getGreeting() + name);
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.micronaut.server.controller;
2+
3+
import com.baeldung.micronaut.server.service.GreetingService;
4+
import io.micronaut.http.MediaType;
5+
import io.micronaut.http.annotation.Body;
6+
import io.micronaut.http.annotation.Controller;
7+
import io.micronaut.http.annotation.Get;
8+
import io.micronaut.http.annotation.Post;
9+
10+
import javax.inject.Inject;
11+
12+
@Controller("/greet")
13+
public class GreetController {
14+
15+
@Inject
16+
private GreetingService greetingService;
17+
18+
@Get("/{name}")
19+
public String greet(String name) {
20+
return greetingService.getGreeting() + name;
21+
}
22+
23+
@Post(value = "/{name}", consumes = MediaType.TEXT_PLAIN)
24+
public String setGreeting(@Body String name)
25+
{
26+
return greetingService.getGreeting() + name;
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.micronaut.server.service;
2+
3+
import io.micronaut.context.annotation.Primary;
4+
5+
import javax.inject.Singleton;
6+
7+
@Primary
8+
@Singleton
9+
public class EnglishGreetingService implements GreetingService {
10+
@Override
11+
public String getGreeting() {
12+
return "Hello ";
13+
}
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.micronaut.server.service;
2+
3+
public interface GreetingService {
4+
5+
String getGreeting();
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.micronaut.server.service;
2+
3+
import javax.inject.Singleton;
4+
5+
@Singleton
6+
public class SpanishGreetingService implements GreetingService {
7+
@Override
8+
public String getGreeting() {
9+
return "Hola ";
10+
}
11+
}

‎micronaut/hello-world-server/src/main/java/hello/world/server/Application.java‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎micronaut/hello-world-server/src/main/java/hello/world/server/controller/GreetController.java‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)