org.jboss.resteasy.annotations.jaxrs.PathParam Java Examples
The following examples show how to use
org.jboss.resteasy.annotations.jaxrs.PathParam.
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: ResourceUsingWebClient.java From quarkus-quickstarts with Apache License 2.0 | 6 votes |
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}") public Uni<JsonObject> getFruitData(@PathParam("name") String name) { return client.get("/api/fruit/" + name) .send() .map(resp -> { if (resp.statusCode() == 200) { return resp.bodyAsJsonObject(); } else { return new JsonObject() .put("code", resp.statusCode()) .put("message", resp.bodyAsString()); } }); }
Example #2
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 6 votes |
@PUT @Path("{id}") @Transactional public Fruit update(@PathParam Long id, Fruit fruit) { if (fruit.name == null) { throw new WebApplicationException("Fruit Name was not set on request.", 422); } Fruit entity = Fruit.findById(id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.name = fruit.name; return entity; }
Example #3
Source File: FruitResource.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
@PUT @Path("{id}") @Transactional public Fruit update(@PathParam Integer id, Fruit fruit) { if (fruit.getName() == null) { throw new WebApplicationException("Fruit Name was not set on request.", 422); } Fruit entity = entityManager.find(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.setName(fruit.getName()); return entity; }
Example #4
Source File: CoffeeResource.java From quarkus-quickstarts with Apache License 2.0 | 6 votes |
@GET @Path("/{id}/recommendations") @Timeout(250) @Fallback(fallbackMethod = "fallbackRecommendations") public List<Coffee> recommendations(@PathParam int id) { long started = System.currentTimeMillis(); final long invocationNumber = counter.getAndIncrement(); try { randomDelay(); LOGGER.infof("CoffeeResource#recommendations() invocation #%d returning successfully", invocationNumber); return coffeeRepository.getRecommendations(id); } catch (InterruptedException e) { LOGGER.errorf("CoffeeResource#recommendations() invocation #%d timed out after %d ms", invocationNumber, System.currentTimeMillis() - started); return null; } }
Example #5
Source File: CoffeeResource.java From quarkus-quickstarts with Apache License 2.0 | 6 votes |
/** * Provides information about a coffee with given id. * * Same as the {@link #coffees()} method, this method fails about 50% of time. However, because this method doesn't * have any {@link Retry} policy, a user is exposed to the failures every time they happen. */ @Path("/{id}") @GET public Response coffeeDetail(@PathParam int id) { final Long invocationNumber = counter.getAndIncrement(); maybeFail(String.format("CoffeeResource#coffees() invocation #%d failed", invocationNumber)); LOGGER.infof("CoffeeResource#coffees() invocation #%d returning successfully", invocationNumber); Coffee coffee = coffeeRepository.getCoffeeById(id); // if coffee with given id not found, return 404 if (coffee == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(coffee).build(); }
Example #6
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 6 votes |
@PUT @Path("{id}") @Transactional public Fruit update(@PathParam Integer id, Fruit fruit) { if (fruit.getName() == null) { throw new WebApplicationException("Fruit Name was not set on request.", 422); } Fruit entity = entityManager.find(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.setName(fruit.getName()); return entity; }
Example #7
Source File: FruitResource.java From quarkus with Apache License 2.0 | 5 votes |
private Fruit update(@NotNull @PathParam("id") int id, @NotNull Fruit fruit) { if (fruit.getName() == null) { throw new WebApplicationException("Fruit Name was not set on request.", 422); } Fruit entity = entityManager.find(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.setName(fruit.getName()); LOG.debugv("Update #{0} {1}", fruit.getId(), fruit.getName()); return entity; }
Example #8
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@PUT @Path("{id}") public Uni<Response> update(@PathParam Long id, Fruit fruit) { return fruit.update(client) .onItem().apply(updated -> updated ? Status.OK : Status.NOT_FOUND) .onItem().apply(status -> Response.status(status).build()); }
Example #9
Source File: MyTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public MyEntity get(@PathParam long id) { MyEntity ret = MyEntity.findById(id); if (ret == null) throw new WebApplicationException(Response.Status.NOT_FOUND); return ret; }
Example #10
Source File: TreeResource.java From quarkus with Apache License 2.0 | 5 votes |
@GET @Path("{id}") @Transactional // This annotation is here for testing purposes. @CacheResult(cacheName = "forest") public Tree get(@PathParam("id") Long id) { return Tree.findById(id); }
Example #11
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@DELETE @Path("{id}") @Transactional public Response delete(@PathParam Long id) { Fruit entity = Fruit.findById(id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.delete(); return Response.status(204).build(); }
Example #12
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("{id}") public Fruit getSingle(@PathParam Long id) { Fruit entity = Fruit.findById(id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } return entity; }
Example #13
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@PUT @Path("/id/{id}/color/{color}") @Produces("application/json") public Fruit changeColor(@PathParam Long id, @PathParam String color) { Optional<Fruit> optional = fruitRepository.findById(id); if (optional.isPresent()) { Fruit fruit = optional.get(); fruit.setColor(color); return fruitRepository.save(fruit); } throw new IllegalArgumentException("No Fruit with id " + id + " exists"); }
Example #14
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
public Fruit update(@PathParam Integer id, Fruit fruit) { if (fruit.getName() == null) { throw new WebApplicationException("Fruit Name was not set on request.", 422); } Fruit entity = entityManager.find(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entity.setName(fruit.getName()); LOG.debugv("Update #{0} {1}", fruit.getId(), fruit.getName()); return entity; }
Example #15
Source File: LibraryResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@DELETE @Path("author/{id}") @Transactional public void deleteAuthor(@PathParam Long id) { Author author = Author.findById(id); if (author != null) { author.delete(); } }
Example #16
Source File: LibraryResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@DELETE @Path("book/{id}") @Transactional public void deleteBook(@PathParam Long id) { Book book = Book.findById(id); if (book != null) { book.author.books.remove(book); book.delete(); } }
Example #17
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("{id}") public Fruit getSingle(@PathParam Integer id) { Fruit entity = entityManager.find(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } return entity; }
Example #18
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@DELETE @Path("{id}") @Transactional public Response delete(@PathParam Integer id) { Fruit entity = entityManager.getReference(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); } entityManager.remove(entity); return Response.status(204).build(); }
Example #19
Source File: MutinyResource.java From quarkus with Apache License 2.0 | 5 votes |
@Path("response/conditional/{test}") @GET public Uni<Response> conditional(@PathParam("test") boolean test) { return Uni.createFrom().item(test) .map(b -> b ? Response.accepted() : Response.noContent()) .map(Response.ResponseBuilder::build); }
Example #20
Source File: MyOtherTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public MyOtherEntity get(@PathParam long id) { MyOtherEntity ret = MyOtherEntity.findById(id); if (ret == null) throw new WebApplicationException(Response.Status.NOT_FOUND); return ret; }
Example #21
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@DELETE @Path("{id}") public Uni<Response> delete(@PathParam Long id) { return Fruit.delete(client, id) .onItem().apply(deleted -> deleted ? Status.NO_CONTENT : Status.NOT_FOUND) .onItem().apply(status -> Response.status(status).build()); }
Example #22
Source File: LibraryResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@POST @Path("author/{id}") @Transactional @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void updateAuthor(@PathParam Long id, @FormParam String firstName, @FormParam String lastName) { Author author = Author.findById(id); if (author == null) { return; } author.firstName = firstName; author.lastName = lastName; author.persist(); }
Example #23
Source File: FruitResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("{id}") public Uni<Response> getSingle(@PathParam Long id) { return Fruit.findById(client, id) .onItem().apply(fruit -> fruit != null ? Response.ok(fruit) : Response.status(Status.NOT_FOUND)) .onItem().apply(ResponseBuilder::build); }
Example #24
Source File: S3AsyncClientResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("download/{objectKey}") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Uni<Response> downloadFile(@PathParam("objectKey") String objectKey) throws Exception { File tempFile = tempFilePath(); return Uni.createFrom() .completionStage(() -> s3.getObject(buildGetRequest(objectKey), AsyncResponseTransformer.toFile(tempFile))) .onItem() .apply(object -> Response.ok(tempFile) .header("Content-Disposition", "attachment;filename=" + objectKey) .header("Content-Type", object.contentType()).build()); }
Example #25
Source File: S3SyncClientResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("download/{objectKey}") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response downloadFile(@PathParam("objectKey") String objectKey) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GetObjectResponse object = s3.getObject(buildGetRequest(objectKey), ResponseTransformer.toOutputStream(baos)); ResponseBuilder response = Response.ok((StreamingOutput) output -> baos.writeTo(output)); response.header("Content-Disposition", "attachment;filename=" + objectKey); response.header("Content-Type", object.contentType()); return response.build(); }
Example #26
Source File: PrimeNumberChecker.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("/{number}") @Produces("text/plain") @Counted(name = "performedChecks", description = "How many primality checks have been performed.") @Timed(name = "checksTimer", description = "A measure how long it takes to perform the primality test.", unit = MetricUnits.MILLISECONDS) public String checkIfPrime(@PathParam long number) { if (number < 1) { return "Only natural numbers can be prime numbers."; } if (number == 1) { return "1 is not prime."; } if (number == 2) { return "2 is prime."; } if (number % 2 == 0) { return number + " is not prime, it is divisible by 2."; } for (int i = 3; i < Math.floor(Math.sqrt(number)) + 1; i = i + 2) { if (number % i == 0) { return number + " is not prime, is divisible by " + i + "."; } } if (number > highestPrimeNumberSoFar) { highestPrimeNumberSoFar = number; } return number + " is prime."; }
Example #27
Source File: LegumeApi.java From quarkus-in-prod with Apache License 2.0 | 5 votes |
@DELETE @Path("{id}") @Operation( operationId = "DeleteLegume", summary = "Delete a Legume" ) @APIResponse( responseCode = "204", description = "Empty response" ) @APIResponse( name = "notFound", responseCode = "404", description = "Legume not found" ) @APIResponse( name = "internalError", responseCode = "500", description = "Internal Server Error" ) Response delete( @Parameter(name = "id", description = "Id of the Legume to delete", required = true, example = "81471222-5798-11e9-ae24-57fa13b361e1", schema = @Schema(description = "uuid", required = true)) @PathParam("id") @NotEmpty final String legumeId);
Example #28
Source File: ReactiveGreetingResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.SERVER_SENT_EVENTS) @SseElementType(MediaType.TEXT_PLAIN) @Path("/stream/{count}/{name}") public Multi<String> greetingsAsStream(@PathParam int count, @PathParam String name) { return service.greetings(count, name); }
Example #29
Source File: EventResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.TEXT_PLAIN) @Path("{name}") public Uni<String> greeting(@PathParam String name) { return bus.<String> request("greeting", name) .onItem().apply(Message::body); }
Example #30
Source File: StreamingResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.SERVER_SENT_EVENTS) @Path("{name}/streaming") public Multi<String> greeting(@PathParam String name) { return Multi.createFrom().publisher(vertx.periodicStream(2000).toPublisher()) .map(l -> String.format("Hello %s! (%s)%n", name, new Date())); }