Spring / Spring7 Intermediate to Advanced Interview questions
Explain the lifecycle of a request handled through an HTTP Interface client (@HttpExchange) in Spring 7?
An HTTP Interface client is a plain interface annotated with @HttpExchange-family annotations; at startup, HttpServiceProxyFactory generates a JDK dynamic proxy implementing that interface, so the application never writes an implementation by hand.
sequenceDiagram
participant App as Application code
participant Proxy as Generated proxy
participant Adapter as RestClientAdapter/WebClientAdapter
participant Client as RestClient/WebClient
App->>Proxy: call interface method
Proxy->>Proxy: build HttpRequestValues from args/annotations
Proxy->>Adapter: delegate exchange
Adapter->>Client: perform HTTP call
Client-->>Adapter: HTTP response
Adapter-->>Proxy: raw response
Proxy-->>App: converted return value
When application code calls an interface method, the proxy's invocation handler builds an HttpRequestValues object from the method's arguments and annotations - path variables, query params, headers, request body - and, if the method declares a version attribute, attaches that to the request through the configured API-versioning strategy. It then delegates to an adapter (RestClientAdapter wrapping a RestClient for synchronous use, or WebClientAdapter wrapping a WebClient for reactive use), which performs the actual HTTP exchange. The adapter's underlying client applies whatever interceptors, error handling, and observation/tracing instrumentation it's configured with, receives the response, and the proxy converts the response body into the method's declared return type via message converters before handing it back - synchronously as a plain object if backed by RestClient, or wrapped in a Mono/Flux if the interface method itself is declared reactively.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
