org.apache.johnzon.jaxrs.JohnzonProvider Java Examples
The following examples show how to use
org.apache.johnzon.jaxrs.JohnzonProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoviesTest.java From microservice-with-jwt-and-microprofile with Apache License 2.0 | 6 votes |
@Test public void sthg() throws Exception { final WebClient webClient = WebClient .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); webClient .reset() .path("/rest/greeting/") .get(String.class); final Collection<? extends Movie> movies = webClient .reset() .path("/rest/movies/") .header("Authorization", "Bearer " + token()) .getCollection(Movie.class); System.out.println(movies); }
Example #2
Source File: GreetingServiceTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void getJson() throws IOException { final String message = WebClient.create("http://localhost:" + port, asList(new JohnzonProvider<GreetingService.Greet>())).path("/test/greeting/") .accept(MediaType.APPLICATION_JSON_TYPE) .get(GreetingService.Greet.class).getMessage(); assertEquals("Hi REST!", message); }
Example #3
Source File: GreetingServiceTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void postJson() throws IOException { final String message = WebClient.create("http://localhost:" + port, asList(new JohnzonProvider<GreetingService.Greet>())).path("/test/greeting/") .accept(MediaType.APPLICATION_JSON_TYPE) .type(MediaType.APPLICATION_JSON_TYPE) .post(new Request("Hi REST!"), GreetingService.Greet.class).getMessage(); assertEquals("hi rest!", message); }
Example #4
Source File: MovieServiceTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #5
Source File: MoviesTest.java From tomee with Apache License 2.0 | 4 votes |
@Test public void movieRestTest() throws Exception { final WebClient webClient = WebClient .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); //Testing rest endpoint deployment (GET without security header) String responsePayload = webClient.reset().path("/rest/cinema/").get(String.class); LOGGER.info("responsePayload = " + responsePayload); assertTrue(responsePayload.equalsIgnoreCase("ok")); //POST (Using token1.json with group of claims: [CRUD]) Movie newMovie = new Movie(1, "David Dobkin", "Wedding Crashers"); Response response = webClient.reset() .path("/rest/cinema/movies") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(1)) .post(newMovie); LOGGER.info("responseCode = " + response.getStatus()); assertTrue(response.getStatus() == 204); //GET movies (Using token2.json with group of claims: [read-only]) Collection<? extends Movie> movies = webClient .reset() .path("/rest/cinema/movies") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(2)) .getCollection(Movie.class); LOGGER.info(movies.toString()); assertTrue(movies.size() == 1); //Should return a 403 since POST require group of claims: [crud] but Token 2 has only [read-only]. Movie secondNewMovie = new Movie(2, "Todd Phillips", "Starsky & Hutch"); Response responseWithError = webClient.reset() .path("/rest/cinema/movies") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(2)) .post(secondNewMovie); LOGGER.info("responseCode = " + responseWithError.getStatus()); assertTrue(responseWithError.getStatus() == 403); //Should return a 401 since the header Authorization is not part of the POST request. Response responseWith401Error = webClient.reset() .path("/rest/cinema/movies") .header("Content-Type", "application/json") .post(new Movie()); LOGGER.info("responseCode = " + responseWith401Error.getStatus()); assertTrue(responseWith401Error.getStatus() == 401); }
Example #6
Source File: BookstoreTest.java From tomee with Apache License 2.0 | 4 votes |
@Test public void movieRestTest() throws Exception { final WebClient webClient = WebClient .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); // Testing REST endpoint that returns the value of a JWT claim String responsePayload = webClient.reset() .path("/rest/bookstore/me") .header("Authorization", "Bearer " + token(true)) .get(String.class); LOGGER.info("responsePayload = " + responsePayload); assertEquals("alice", responsePayload); // Testing REST endpoint with group claims manager Book newBook = new Book(1, "The Lord of the Rings", "J.R.R.Tolkien"); Response response = webClient.reset() .path("/rest/bookstore") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(true)) .post(newBook); LOGGER.info("responseCode = " + response.getStatus()); assertEquals(204, response.getStatus()); // Testing REST endpoint with group claims reader Collection<? extends Book> books = webClient .reset() .path("/rest/bookstore") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(false)) .getCollection(Book.class); LOGGER.info(books.toString()); assertEquals(1, books.size()); // Should return a 403 since POST requires group claim manager but provided token has only reader. Book secondBook = new Book(2, "Mistborn: The Final Empire", "Brandon Sanderson"); Response responseWithError = webClient.reset() .path("/rest/bookstore") .header("Content-Type", "application/json") .header("Authorization", "Bearer " + token(false)) .post(secondBook); LOGGER.info("responseCode = " + responseWithError.getStatus()); assertEquals(403, responseWithError.getStatus()); // Should return a 401 since the POST request lacks the Authorization header Response responseWith401Error = webClient.reset() .path("/rest/bookstore") .header("Content-Type", "application/json") .post(new Book()); LOGGER.info("responseCode = " + responseWith401Error.getStatus()); assertEquals(401, responseWith401Error.getStatus()); }
Example #7
Source File: MovieServiceTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #8
Source File: MissingRequiredClaimsTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #9
Source File: MinimumRequiredClaimsTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #10
Source File: RsaKeySizesTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #11
Source File: InvalidSignatureTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }
Example #12
Source File: ShaHashSizesTest.java From tomee with Apache License 2.0 | 4 votes |
private static WebClient createWebClient(final URL base) { return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null); }