|
1 | 1 | package org.infinispan.quarkus.embedded;
|
2 | 2 |
|
| 3 | +import static org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM; |
| 4 | + |
3 | 5 | import java.io.IOException;
|
4 | 6 | import java.nio.charset.StandardCharsets;
|
5 | 7 | import java.util.ArrayList;
|
|
10 | 12 | import jakarta.inject.Inject;
|
11 | 13 | import jakarta.transaction.Transactional;
|
12 | 14 | import jakarta.ws.rs.GET;
|
| 15 | +import jakarta.ws.rs.POST; |
13 | 16 | import jakarta.ws.rs.Path;
|
14 | 17 | import jakarta.ws.rs.PathParam;
|
15 | 18 | import jakarta.ws.rs.Produces;
|
16 | 19 | import jakarta.ws.rs.QueryParam;
|
17 | 20 | import jakarta.ws.rs.core.MediaType;
|
18 | 21 |
|
19 | 22 | import org.infinispan.Cache;
|
| 23 | +import org.infinispan.commons.api.CacheContainerAdmin; |
20 | 24 | import org.infinispan.configuration.cache.CacheMode;
|
21 | 25 | import org.infinispan.configuration.cache.ConfigurationBuilder;
|
22 | 26 | import org.infinispan.manager.DefaultCacheManager;
|
@@ -117,4 +121,29 @@ public String simpleCluster() throws IOException {
|
117 | 121 | }
|
118 | 122 | return "Success";
|
119 | 123 | }
|
| 124 | + |
| 125 | + @Path("PROTO/GET/books/{id}") |
| 126 | + @GET |
| 127 | + @Produces(MediaType.APPLICATION_JSON) |
| 128 | + public Book get(@PathParam("id") String id) { |
| 129 | + Cache<String, Book> books = emc.administration() |
| 130 | + .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE) |
| 131 | + .getOrCreateCache("books", new ConfigurationBuilder() |
| 132 | + .encoding().mediaType(APPLICATION_PROTOSTREAM) |
| 133 | + .build()); |
| 134 | + return books.get(id); |
| 135 | + } |
| 136 | + |
| 137 | + @Path("PROTO/POST/books/{id}") |
| 138 | + @POST |
| 139 | + @Produces(MediaType.TEXT_PLAIN) |
| 140 | + public String create(@PathParam("id") String id, Book book) { |
| 141 | + Cache<String, Book> books = emc.administration() |
| 142 | + .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE) |
| 143 | + .getOrCreateCache("books", new ConfigurationBuilder() |
| 144 | + .encoding().mediaType(APPLICATION_PROTOSTREAM) |
| 145 | + .build()); |
| 146 | + books.put(id, book); |
| 147 | + return id; |
| 148 | + } |
120 | 149 | }
|
0 commit comments