Posts tagged REST
How To Get Resource Method Information With ResourceInfo In Jakarta REST
Published on 03 May 2023
by Luqman Saeed
Topics: REST, JakartaEE, Jakarta EE | 2 Comments
Oftentimes in a Jakarta REST application, you may need to access some metadata about a given resource method matched by the Jakarta REST runtime, outside of a resource class. This could be so as to dynamically alter the client's request based on some custom business requirement, or for informative purposes. For example, in a Jakarta REST component like an exception mapper, you might want to get the currently matched resource method and get its HTTP method.
Intercepting REST Requests With Jakarta REST Request Filters
Published on 14 Mar 2023
by Luqman Saeed
Topics: Java EE, REST, JakartaEE, Jakarta EE | 0 Comments
Oftentimes in web applications, there is the need to intercept a request from the client to resource methods. Sometimes this interception must take place even before the request is matched to a resource method. For such needs, Jakarta REST provides the jakarta.ws.rs.container.ContainerRequestFilter interface. This interface is a Jakarta REST extension that can be used to intercept requests to resource methods.
An implementation of this interface can decide if requests should be intercepted before they’re matched to resource methods through the @PreMatching annotation. A pre-matched request filter will be invoked by the container before the request is matched to its intended resource method.
For this blog post, let us look at two use cases for request filters. One is a situation where for security reasons, certain HTTP methods are not allowed. For example an organisation can have a security rule in its firewall that disallows HTTP PUT methods. In this case, either all methods have to be POST or request filters can be used to workaround the restriction.
The second situation is for the custom implementation of authentication. Of course you absolutely should NOT hand-roll your own security setup unless you know in detail exactly what you are doing. You are better off using tried and tested security frameworks and services out there. But for this blog post, assuming we need to implement custom security, we can use a pre matching request filter. The following code snippet below shows a ContainerRequestFilter implementation that implements the two scenarios above.
How to prevent runtime type erasure using GenericEntity in Jakarta REST in Jakarta EE 10
Published on 09 Mar 2023
by Luqman Saeed
Topics: REST, JakartaEE, Java, Jakarta EE | 0 Comments
Java generics is a great feature that allows you to have compile time checks for generics. However, due to historical reasons of backward compatibility, type information for generics is erased at runtime. A lot of the time this shouldn’t be of much concern. But there are a few cases where type information is needed at runtime for some kind of decision.
One such situation is in Jakarta REST when the jakarta.ws.rs.core.Response object is used to return a generic collection of a specific type. For example the code below shows the creation and return of a Response object that has a list of HelloEntity as the return payload to the client.
Returning Beautiful Validation Error Messages In Jakarta REST With Exception Mappers
Published on 07 Mar 2023
by Luqman Saeed
Topics: Java EE, REST, JakartaEE, Jakarta EE | 1 Comment
All non-trivial enterprise applications have some sort of constraints on the data the application processes. These constraints could range from the simplest to the most complex custom built types. The default validation API on theJakarta EEPlatform, Jakarta Bean Validation has excellent out of the box support for constraining bean fields. Then with its @Valid annotation, you can trigger automatic validation of constrained objects in certain points of an application.
What’s New in Jakarta REST 3.1 in Jakarta EE 10?
Published on 28 Nov 2022
by Luqman Saeed
Topics: REST, JakartaEE, Payara Cloud, Jakarta EE | 0 Comments
The Representational State Transfer or RESTful architecture is a stateless, HTTP based communication standard for modern applications. It was originally proposed by Dr. Roy Fielding in hisPhD thesis. It has, over the years, become the default, programming language-agnostic means of enabling machine-to-machine communication. An application written in the Django framework in Python can have REST resources that are consumed by another application written in Java with Jakarta EE. Similarly, a Jakarta EE application can create resources that can be consumed by a C# application.
Payara Server と NetBeans による RESTful Web サービスの作成
Published on 20 May 2020
by Kenji Hasunuma
Topics: REST, NetBeans, Japanese language | 0 Comments
Create a RESTful Web Service with Payara Server 5.194 & NetBeans
Published on 10 Feb 2020
by Andrew Pielage
Topics: Demo, REST, NetBeans | 3 Comments
Did You Know? Asynchronous REST Requests and Responses with Java EE and MicroProfile
Published on 04 Jan 2019
by Ondro Mihályi
Topics: Java EE, REST, MicroProfile | 2 Comments
Java EE 8 fully supports asynchronous handling of REST requests and responses, on both client and server side. This is useful to optimize throughput of an application or even when adopting reactive principles. MicroProfile type-safe REST client API also supports this concept to allow you to call REST services asynchronously with a much more straightforward way with plain Java interfaces.
Troubleshooting your Java EE Applications - Part 2
Published on 29 Dec 2018
by Gaurav Gupta
Topics: Microservices, REST, MicroProfile | 0 Comments
In the previous blog of this series, we learned different ways to troubleshoot Java EE application. This blog will continue to focus on different ways and techniques to catch potential issues in the early stages and how to find the root cause of application performance issues.
See Our Latest Webinar Based on the 184 Release
Published on 01 Dec 2018
by Jadon Ortlepp
Topics: Payara Micro, REST, Healthcheck, Payara Server, New Releases | 0 Comments