Scrivio Interview library

JAX-RS with Jersey and RESTEasy

41 questions in 14 subtopics.

Resources and path matching

InternalsFoundations6 min read
Two methods in the same resource are annotated @GET @Path("{name}") and @GET @Path("active"). Which one handles GET /users/active, and how does JAX-RS rank candidate paths when several templates match?
CodingFoundations6 min read
Write a Jakarta REST resource class for /orders that supports GET /orders/{id} where id must be numeric, GET /orders?status=OPEN&limit=20 with a default limit, and POST /orders that returns 201 with a Location header. Use jakarta.ws.rs annotations only.
DesignIntermediate6 min read
An API exposes /customers/{id}/accounts/{accountId}/transactions with many nested operations, all in one 2,000-line resource class. How would you restructure it using sub-resource locators, and what are the trade-offs versus separate root resources?

JSON providers

ConceptFoundations6 min read
How does a JAX-RS runtime turn a returned OrderDto into a JSON response body? Explain MessageBodyWriter, @Produces and what you need on the classpath for Jersey and for RESTEasy.
DebuggingIntermediate6 min read
After moving a service from WildFly to a Jersey-based runtime, dates in responses changed from "2026-03-01T10:00:00Z" to arrays like [2026,3,1,10,0], and unknown request fields now cause 400 errors. What happened and how do you fix it in one place?
LeadershipAdvanced6 min read
Your company runs 60 JAX-RS services, half with Jackson and half with JSON-B, and clients see different null handling, date formats and enum spellings between them. How do you set and roll out a standard?
LeadershipPrincipal7 min read
Java has seen many JSON libraries (Jackson, Gson, JSON-B, JSON-P, org.json) and several serious deserialization vulnerabilities. What long-term policy would you set for JSON libraries across a large company?

File upload and download

CodingFoundations6 min read
Write a JAX-RS endpoint that accepts a multipart/form-data upload with a file part named "file" and a text part named "description", using the standard Jakarta REST 3.1 API rather than Jersey- or RESTEasy-specific classes. What limits would you enforce?
CodingFoundations6 min read
Write a JAX-RS method GET /reports/{id}/file that downloads a large PDF stored on disk so the browser saves it as report-42.pdf, without loading the file into memory.
DesignIntermediate7 min read
Users upload files up to 5 GB through a JAX-RS service that currently receives the whole multipart body, stores it to a temp directory and then copies it to object storage. Pods run out of disk and uploads time out. Redesign it.

Exception mappers

CodingFoundations6 min read
Write an ExceptionMapper that turns an OrderNotFoundException into a 404 response with a JSON problem body, and explain how JAX-RS picks a mapper when you also have an ExceptionMapper<RuntimeException>.
DebuggingIntermediate6 min read
A resource throws new WebApplicationException(Response.status(409).entity(body).build()), but clients receive a 500 with a generic error from your ExceptionMapper<Throwable>. In another case, NotFoundException thrown by the runtime for unknown paths is also turned into 500. Explain and fix.
DesignAdvanced6 min read
Define an error-handling standard for a portfolio of JAX-RS and Spring MVC services so clients see the same error format, codes and correlation ids regardless of framework.

Client API

CodingFoundations6 min read
Using the JAX-RS client API, write code that calls GET https://inventory/api/items/{sku} with a bearer token, returns an Item, and treats 404 as Optional.empty(). What resources must you close and why?
DebuggingIntermediate7 min read
A service using a Jersey client starts timing out under load; thread dumps show many threads waiting to lease a connection, and the code creates ClientBuilder.newClient() inside each request handler. Explain the problems and the fix.
DesignAdvanced6 min read
Your teams call each other with a mix of the JAX-RS client, MicroProfile Rest Client, Spring RestClient and raw HttpClient. What would you standardise for service-to-service HTTP calls, and what would you leave to teams?
LeadershipPrincipal6 min read
MicroProfile Rest Client, Spring HTTP interfaces and the JAX-RS client all offer declarative or fluent HTTP clients. With hundreds of services, should your company build a single internal HTTP client SDK? Argue the build-versus-adopt decision.

Cookies and headers

CodingFoundations6 min read
Write a JAX-RS method that reads a header X-Request-Id and a cookie named session, and returns a response that sets a cookie theme=dark which is HttpOnly, Secure, SameSite=Lax and expires in 30 days.
ScenarioIntermediate7 min read
A JAX-RS service behind a load balancer generates absolute URLs with http:// and the wrong host, and its session cookie is sometimes not sent by browsers in cross-site iframes. What is going on and how do you fix both?

Request and response filters

CodingFoundations7 min read
Write a ContainerRequestFilter and ContainerResponseFilter pair that assigns a request id (from X-Request-Id or a new UUID), puts it in the MDC, and adds it to the response headers. When must the request filter be @PreMatching?
InternalsIntermediate6 min read
Explain how to apply a filter only to some resource methods in JAX-RS using @NameBinding and DynamicFeature, and how abortWith works in a ContainerRequestFilter.

Setup and deployment

ConceptFoundations6 min read
List the ways to bootstrap a Jakarta REST application: on an application server, on a servlet container with Jersey or RESTEasy, in Spring Boot, and standalone with the Java SE bootstrap API. What does @ApplicationPath do?
DebuggingIntermediate6 min read
After upgrading a WAR from javax.ws.rs (Jersey 2) to Jakarta REST on Tomcat 10.1, all endpoints return 404 and the logs show no resources registered. What do you check?
LeadershipPrincipal6 min read
Your company has 120 JAX-RS services across WebLogic, WildFly, Tomcat with Jersey, and Spring Boot with Jersey. A platform team proposes converging on one runtime over five years. How do you make and govern that decision?

Security and authentication

ConceptFoundations5 min read
How do you protect JAX-RS resource methods with roles? Explain SecurityContext, @RolesAllowed, @PermitAll and @DenyAll, and what Jersey needs before @RolesAllowed is enforced.
CodingIntermediate7 min read
Write a ContainerRequestFilter that validates a JWT bearer token and sets a SecurityContext with the user's roles, and list the mistakes that make such filters insecure.
DesignAdvanced6 min read
Design authentication and authorization for a set of JAX-RS services that are called by browsers, mobile apps, partner systems and other internal services.
LeadershipPrincipal6 min read
After a breach traced to an unprotected JAX-RS admin endpoint that was added without the security filter, the board asks how you will prevent this class of failure. What do you change at company level?

Streaming output

CodingFoundations7 min read
Write a JAX-RS endpoint that streams 2 million rows as CSV from a database without building the whole file in memory. What happens if the client disconnects halfway?
DesignIntermediate7 min read
A dashboard needs live order updates from a JAX-RS service. Compare server-sent events using Sse and SseEventSink, long polling with AsyncResponse, and WebSockets, and describe how you would scale the chosen option to 50,000 open connections.

Bean validation in JAX-RS

CodingFoundations6 min read
Add Jakarta Bean Validation to a JAX-RS POST /customers method and a GET /customers?page= parameter that must be at least 1. What status code does the client get for each kind of violation by default?
ScenarioIntermediate7 min read
The same CustomerRequest DTO is used for create and partial update. Required-field constraints break PATCH requests, and a cross-field rule (endDate after startDate) is not checked. How would you design validation?

HTTP caching with ETag

CodingFoundations6 min read
Implement GET /products/{id} in JAX-RS so it returns 304 Not Modified when the client's If-None-Match matches the product's current version, and sets Cache-Control for private caching for 60 seconds.
DesignIntermediate6 min read
Use ETags to prevent lost updates when two users edit the same product through PUT /products/{id}. Show the request flow and the server checks, including what status codes you return.
LeadershipPrincipal6 min read
Your API platform serves 2 billion GET requests per day, mostly for data that changes rarely, and the database and egress costs are a top-five infrastructure cost. How would you lead a company-wide HTTP caching strategy?

Content encoding and compression

ConceptFoundations6 min read
How do you enable gzip compression of JAX-RS responses in Jersey and in RESTEasy, and how do Accept-Encoding, Content-Encoding and Vary work together?
ScenarioIntermediate7 min read
A JAX-RS service accepts gzip-compressed request bodies. A security review flags a decompression bomb risk, and another review mentions BREACH for compressed HTTPS responses containing a CSRF token. Explain both risks and the mitigations.
DesignAdvanced7 min read
Your services exchange large JSON payloads internally and network cost between regions is high. Teams propose gzip, Brotli or zstd at the proxy, in the JAX-RS layer, or a switch to a binary format. How do you decide?

Context injection

ConceptFoundations8 min read
What can you inject with @Context in a JAX-RS resource, and what is the difference between injecting into a per-request resource and into a singleton provider?
DebuggingIntermediate8 min read
A JAX-RS resource injects UriInfo with @Context and passes it to a CompletableFuture running on a separate executor. Under load, some responses contain links with another user's request path. Explain the cause and the fix.
DesignPrincipal7 min read
Jakarta REST is gradually replacing its own @Context injection with CDI. As the person responsible for the Java platform standard, what does this history teach about framework-specific injection, and how should teams write resources today to stay portable?