-
Notifications
You must be signed in to change notification settings - Fork 8
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
PLUGINAPI-42 Migrate javax -> jakarta (backward compatibility) #92
Changes from all commits
98c911e
afdd169
945a314
f5e6e85
8c10020
3e275a1
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 |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
|
||
import javax.annotation.Nullable; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.sonar.api.server.http.HttpRequest; | ||
import org.sonar.api.server.http.JavaxHttpRequest; | ||
|
||
/** | ||
* Note that prefix "do" for names of methods is reserved for future enhancements, thus should not be used in subclasses. | ||
|
@@ -42,19 +44,46 @@ public UserDetails doGetUserDetails(Context context) { | |
|
||
public static final class Context { | ||
private String username; | ||
/** | ||
* @deprecated since 9.16 use {@link #httpRequest} instead | ||
*/ | ||
@Deprecated(since = "9.16", forRemoval = true) | ||
private HttpServletRequest request; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a private field, not really an API that needs to be deprecated. It's not like we can replace its use. |
||
private HttpRequest httpRequest; | ||
|
||
/** | ||
* @deprecated since 9.16 use {@link #Context(String, HttpRequest)} instead | ||
*/ | ||
@Deprecated(since = "9.16", forRemoval = true) | ||
public Context(@Nullable String username, HttpServletRequest request) { | ||
this.username = username; | ||
this.request = request; | ||
this.httpRequest = new JavaxHttpRequest(request); | ||
} | ||
|
||
public Context(@Nullable String username, HttpRequest httpRequest) { | ||
this.username = username; | ||
this.httpRequest = httpRequest; | ||
this.request = (HttpServletRequest) httpRequest.getRawRequest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would imply that the Object returned by I'd suggest we add the constructor Note that the constructors of this class should only be used by the products implementing the API in production code, so compliance with the deprecation policy is not critical (plugins might use it in tests though, but that's only broken once they upgrade the API). We could add a javadoc comment warning that it's not intended for plugins to instantiate this class, except in tests. If we wanted to be super strict about the deprecation policy, the only solutions would be to go through 2 deprecation periods, or to introduce a completely new interface and deprecate this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that make sense |
||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
/** | ||
* @deprecated since 9.16. Use {@link #getHttpRequest()} instead. | ||
*/ | ||
@Deprecated(since = "9.16", forRemoval = true) | ||
public HttpServletRequest getRequest() { | ||
return request; | ||
} | ||
|
||
/** | ||
* @since 9.16 | ||
*/ | ||
public HttpRequest getHttpRequest() { | ||
return httpRequest; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Sonar Plugin API | ||
* Copyright (C) 2009-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.api.server.http; | ||
|
||
import java.util.Enumeration; | ||
|
||
/** | ||
* Framework-agnostic definition of an HTTP request. | ||
* | ||
* @since 9.16 | ||
*/ | ||
public interface HttpRequest { | ||
|
||
/** | ||
* Returns the port number to which the request was sent. | ||
*/ | ||
int getServerPort(); | ||
|
||
/** | ||
* Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. | ||
*/ | ||
boolean isSecure(); | ||
|
||
/** | ||
* Returns the name of the scheme used to make this request, for example, http, https, or ftp. | ||
*/ | ||
String getScheme(); | ||
|
||
/** | ||
* Returns the host name of the server to which the request was sent. | ||
*/ | ||
String getServerName(); | ||
|
||
/** | ||
* Returns the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, | ||
* but it does not include query string parameters. | ||
*/ | ||
String getRequestURL(); | ||
|
||
/** | ||
* Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. | ||
*/ | ||
String getRequestURI(); | ||
|
||
/** | ||
* Returns the query string that is contained in the request URL after the path. This method returns null if the URL does not have a | ||
* query string. | ||
*/ | ||
String getQueryString(); | ||
|
||
/** | ||
* Returns the portion of the request URI that indicates the context of the request. The context path always comes first | ||
* in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the | ||
* default (root) context, this method returns "". The container does not decode this string. | ||
*/ | ||
String getContextPath(); | ||
|
||
/** | ||
* Returns the value of a request parameter as a String, or null if the parameter does not exist. | ||
* You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, | ||
* use {@link #getParameterValues}. | ||
*/ | ||
String getParameter(String name); | ||
|
||
/** | ||
* Returns an array containing all the values the given request parameter has, or null if the parameter does not exist. | ||
*/ | ||
String[] getParameterValues(String name); | ||
|
||
/** | ||
* Returns the value of the specified request header as a String. If the request did not include a header of the specified name, this | ||
* method returns null. If there are multiple headers with the same name, this method returns the first head in the request. | ||
*/ | ||
String getHeader(String name); | ||
|
||
/** | ||
* Returns all the values of the specified request header as an Enumeration of String objects. | ||
*/ | ||
Enumeration<String> getHeaders(String name); | ||
|
||
/** | ||
* Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. | ||
*/ | ||
String getMethod(); | ||
|
||
/** | ||
* Returns the raw request object from the Servlet API that matches this request. | ||
*/ | ||
Object getRawRequest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to defeat the purpose of having our own objects that represent HTTP requests and responses. If the goal is for this to be used only by the products implementing the API, we should cast classes instead, since they are in control of the implementations at runtime. For example, if a given version of SonarQube is creating filter contexts with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so we wanted to return "raw" requests objects as we wanted to avoid creating more classes that mimic Also, SAML library which we use requires us to pass |
||
} |
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.
it'd probably be better for products to pass both
HttpRequest
andHttpServletRequest
.