-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add TimeZone header support to REST API (#17344) #17387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| import javax.ws.rs.ext.Provider; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.DateTimeException; | ||
| import java.time.ZoneId; | ||
| import java.util.Base64; | ||
| import java.util.UUID; | ||
|
|
@@ -88,6 +89,12 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc | |
| if (user == null) { | ||
| return; | ||
| } | ||
|
|
||
| ZoneId zoneId = resolveTimeZone(containerRequestContext); | ||
| if (zoneId == null) { | ||
| return; | ||
| } | ||
|
|
||
| String sessionid = UUID.randomUUID().toString(); | ||
| if (SESSION_MANAGER.getCurrSession() == null) { | ||
| RestClientSession restClientSession = new RestClientSession(sessionid); | ||
|
|
@@ -97,7 +104,7 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc | |
| SESSION_MANAGER.getCurrSession(), | ||
| user.getUserId(), | ||
| user.getUsername(), | ||
| ZoneId.systemDefault(), | ||
| zoneId, | ||
| IoTDBConstant.ClientVersion.V_1_0); | ||
| } | ||
| BasicSecurityContext basicSecurityContext = | ||
|
|
@@ -147,6 +154,33 @@ private User checkLogin( | |
| return user; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the Time-Zone header from the request. | ||
| * | ||
| * @param requestContext the incoming HTTP request | ||
| * @return the resolved ZoneId, or {@code null} if the header is invalid (the request is aborted) | ||
| */ | ||
| private ZoneId resolveTimeZone(ContainerRequestContext requestContext) { | ||
| String timeZoneHeader = requestContext.getHeaderString("Time-Zone"); | ||
| if (timeZoneHeader == null || timeZoneHeader.isEmpty()) { | ||
| return ZoneId.systemDefault(); | ||
| } | ||
HTHou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| return ZoneId.of(timeZoneHeader); | ||
| } catch (DateTimeException e) { | ||
|
Comment on lines
+164
to
+170
|
||
| Response resp = | ||
| Response.status(Status.BAD_REQUEST) | ||
| .type(MediaType.APPLICATION_JSON) | ||
| .entity( | ||
| new ExecutionStatus() | ||
| .code(TSStatusCode.ILLEGAL_PARAMETER.getStatusCode()) | ||
| .message("Invalid time zone: " + timeZoneHeader)) | ||
| .build(); | ||
| requestContext.abortWith(resp); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void filter( | ||
| ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryWithTimeZone()doesn’t actually send the Time-Zone header (unlike the HTTPS and table examples). As written, this method behaves the same asquery()and won’t demonstrate the feature. Add theTime-Zone(or intended header name) to this request so the example matches the method name and the PR’s new behavior.