Skip to content

Commit d257cc8

Browse files
committed
Remove engine.adapter and map Netty messages directly
The Netty connectors now build Restlet requests and responses directly from Netty messages, without the ServerCall/ClientCall and ServerAdapter/ ClientAdapter layer. - NettyServerHelper extends ServerHelper, NettyClientHelper extends ClientHelper (two fewer inheritance levels, Sonar S110). - NettyServerCall and the new NettyRequest take over ServerCall, ServerAdapter and HttpRequest: lazy header parsing, headers and version attributes, TLS client info, entity rules per status and method, ConnectorService callbacks. - NettyClientCall takes over ClientCall and ClientAdapter. - Removed the org.restlet.engine.adapter package and the "adapter" connector parameter (breaking change, 3.0). - Added Response.getProtocol()/setProtocol(): the HTTP client connector records the protocol version the server replied with (1.1, 2.0, 3.0). WrapperResponse delegates it; Response.toString() shows it. Signed-off-by: Jerome Louvel <374450+jlouvel@users.noreply.github.com>
1 parent b5cabe2 commit d257cc8

26 files changed

Lines changed: 1346 additions & 3004 deletions

‎changes.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Changes log
4343
the connector for synchronous calls, without leaking credentials to other origins.
4444
- Removed `JettyServerHelper`, `JettyServerCall`, `JettyClientCall`, `JettyHandler`,
4545
`RestletSslContextFactoryClient` and `RestletSslContextFactoryServer`.
46+
- Removed the `org.restlet.engine.adapter` package (`Adapter`, `Call`, `ClientAdapter`,
47+
`ClientCall`, `HttpClientHelper`, `HttpRequest`, `HttpResponse`, `HttpServerHelper`,
48+
`ServerAdapter`, `ServerCall`) and the "adapter" connector parameter. The Netty
49+
connectors now map Netty messages directly to Restlet requests and responses, and
50+
`NettyServerHelper` and `NettyClientHelper` extend `ServerHelper` and `ClientHelper`.
51+
Custom HTTP connectors should extend those classes. Request headers remain available
52+
with `Message.getHeaders()`.
4653
- `MultiPartRepresentation` no longer exposes Jetty types: parts are instances of the new
4754
`MultiPartRepresentation.Part` class (name, file name, headers, content
4855
representation), parsing takes an optional storage directory instead of a Jetty
@@ -54,6 +61,11 @@ Changes log
5461
- Removed the `Protocol.WAR` constant ("war" scheme, Web Archive Access Protocol), a
5562
leftover of the Servlet mode, which is no longer supported. `Protocol.valueOf("war")`
5663
now returns a new, unknown protocol. Use CLAP or FILE references instead.
64+
- Enhancements
65+
- Added `Response.getProtocol()` and `setProtocol()`: the protocol, with its version,
66+
used by the server to reply (for example HTTP/1.1, HTTP/2.0 or HTTP/3.0), set by the HTTP
67+
client connector. When unknown, the protocol of the request is returned.
68+
`Response.toString()` now shows it.
5769
- Bugs fixed
5870
- Slf4j bridge reports wrong line number and caller class in log4j. Issue #233.
5971
- When GET is an allowed method of a server resource, HEAD is now also listed (e.g. in the Allow header of a 405 response). Issue #266.

‎org.restlet/src/main/java/module-info.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
exports org.restlet;
3434
exports org.restlet.data;
3535
exports org.restlet.engine;
36-
exports org.restlet.engine.adapter;
3736
exports org.restlet.engine.application;
3837
exports org.restlet.engine.component;
3938
exports org.restlet.engine.connector;

‎org.restlet/src/main/java/org/restlet/Response.java‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.restlet.data.CookieSetting;
2020
import org.restlet.data.Dimension;
2121
import org.restlet.data.Method;
22+
import org.restlet.data.Protocol;
2223
import org.restlet.data.Reference;
2324
import org.restlet.data.ServerInfo;
2425
import org.restlet.data.Status;
@@ -135,6 +136,9 @@ public static void setCurrent(Response response) {
135136
/** Indicates how long the service is expected to be unavailable to the requesting client. */
136137
private volatile Date retryAfter;
137138

139+
/** The protocol, with its version, used by the server to reply. */
140+
private volatile Protocol protocol;
141+
138142
/** The server-specific information. */
139143
private volatile ServerInfo serverInfo;
140144

@@ -162,6 +166,7 @@ public Response(Request request) {
162166
this.locationRef = null;
163167
this.proxyChallengeRequests = null;
164168
this.request = request;
169+
this.protocol = null;
165170
this.retryAfter = null;
166171
this.serverInfo = null;
167172
this.status = Status.SUCCESS_OK;
@@ -476,6 +481,18 @@ public Date getRetryAfter() {
476481
return retryAfter;
477482
}
478483

484+
/**
485+
* Returns the protocol, with its version, used by the server to reply, if known. For example,
486+
* the HTTP client connector sets "HTTP/1.1", "HTTP/2.0" or "HTTP/3.0" (secure exchanges use the
487+
* HTTPS protocol). When unknown, returns the protocol of the request.
488+
*
489+
* @return The protocol used by the server to reply.
490+
*/
491+
public Protocol getProtocol() {
492+
Protocol result = this.protocol;
493+
return (result == null && getRequest() != null) ? getRequest().getProtocol() : result;
494+
}
495+
479496
/**
480497
* Returns the server-specific information. Creates a new instance if no one has been set.
481498
*
@@ -932,6 +949,15 @@ public void setRetryAfter(Date retryAfter) {
932949
this.retryAfter = retryAfter;
933950
}
934951

952+
/**
953+
* Sets the protocol, with its version, used by the server to reply.
954+
*
955+
* @param protocol The protocol used by the server to reply.
956+
*/
957+
public void setProtocol(Protocol protocol) {
958+
this.protocol = protocol;
959+
}
960+
935961
/**
936962
* Sets the server-specific information.
937963
*
@@ -987,6 +1013,7 @@ public void setStatus(Status status, Throwable throwable, String message) {
9871013
* @return A synthesis of the response like an HTTP status line.
9881014
*/
9891015
public String toString() {
990-
return ((getRequest() == null) ? "?" : getRequest().getProtocol()) + " - " + getStatus();
1016+
Protocol p = getProtocol();
1017+
return ((p == null) ? "?" : p) + " - " + getStatus();
9911018
}
9921019
}

‎org.restlet/src/main/java/org/restlet/engine/adapter/Adapter.java‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)