Skip to content

Commit

Permalink
Move o.e.equinox.http.servlet to Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
akurtakov committed Oct 1, 2023
1 parent 7eb1b42 commit d12832b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 129 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.http.servlet/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -34,6 +34,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=error
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
Expand Down Expand Up @@ -87,6 +88,7 @@ org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=igno
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
Expand Down Expand Up @@ -120,8 +122,8 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=error
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.equinox.http.servlet
Bundle-Version: 1.7.400.qualifier
Bundle-Version: 1.8.0.qualifier
Bundle-Activator: org.eclipse.equinox.http.servlet.internal.Activator
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.equinox.http.servlet;version="1.2.0",
org.eclipse.equinox.http.servlet.context;version="1.0.0";x-internal:=true,
org.eclipse.equinox.http.servlet.session;version="1.0.0";x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ public synchronized void registerFilter(

final HttpContextHolder httpContextHolder = getHttpContextHolder(httpContext);
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() {
httpServiceRuntime.registerHttpServiceFilter(bundle, alias, filter, initparams, httpContextHolder);
return null;
}
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
httpServiceRuntime.registerHttpServiceFilter(bundle, alias, filter, initparams, httpContextHolder);
return null;
});
}
catch (PrivilegedActionException e) {
Expand Down Expand Up @@ -105,12 +102,9 @@ public synchronized void registerResources(
checkShutdown();
final HttpContextHolder httpContextHolder = getHttpContextHolder(httpContext);
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws NamespaceException {
httpServiceRuntime.registerHttpServiceResources(bundle, alias, name, httpContextHolder);
return null;
}
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
httpServiceRuntime.registerHttpServiceResources(bundle, alias, name, httpContextHolder);
return null;
});
} catch (PrivilegedActionException e) {
Throw.unchecked(e.getException());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,107 +70,103 @@ public void service(HttpServletRequest req, final HttpServletResponse resp) thro

private void writeResource(final HttpServletRequest req, final HttpServletResponse resp, final String resourcePath, final URL resourceURL) throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {

@Override
public Boolean run() throws Exception {
URLConnection connection = resourceURL.openConnection();
long lastModified = connection.getLastModified();
int contentLength = connection.getContentLength();

String etag = null;
if (lastModified != -1 && contentLength != -1)
etag = "W/\"" + contentLength + "-" + lastModified + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$

// Check for cache revalidation.
// We should prefer ETag validation as the guarantees are stronger and all HTTP 1.1 clients should be using it
String ifNoneMatch = req.getHeader(IF_NONE_MATCH);
if (ifNoneMatch != null && etag != null && ifNoneMatch.indexOf(etag) != -1) {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return Boolean.TRUE;
}
AccessController.doPrivileged((PrivilegedExceptionAction<Boolean>) () -> {
URLConnection connection = resourceURL.openConnection();
long lastModified = connection.getLastModified();
int contentLength = connection.getContentLength();

String etag = null;
if (lastModified != -1 && contentLength != -1)
etag = "W/\"" + contentLength + "-" + lastModified + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$

// Check for cache revalidation.
// We should prefer ETag validation as the guarantees are stronger and all HTTP 1.1 clients should be using it
String ifNoneMatch = req.getHeader(IF_NONE_MATCH);
if (ifNoneMatch != null && etag != null && ifNoneMatch.indexOf(etag) != -1) {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return Boolean.TRUE;
}

long ifModifiedSince = req.getDateHeader(IF_MODIFIED_SINCE);
// for purposes of comparison we add 999 to ifModifiedSince since the fidelity
// of the IMS header generally doesn't include milli-seconds
if (ifModifiedSince > -1 && lastModified > 0 && lastModified <= (ifModifiedSince + 999)) {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return Boolean.TRUE;
}
long ifModifiedSince = req.getDateHeader(IF_MODIFIED_SINCE);
// for purposes of comparison we add 999 to ifModifiedSince since the fidelity
// of the IMS header generally doesn't include milli-seconds
if (ifModifiedSince > -1 && lastModified > 0 && lastModified <= (ifModifiedSince + 999)) {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return Boolean.TRUE;
}

String rangeHeader = req.getHeader(RANGE);
Range range = null;
if (rangeHeader != null) {
range = Range.createFromRangeHeader(rangeHeader);
range.completeLength = contentLength;
range.updateBytePos();

if (!range.isValid()) {
resp.setHeader(ACCEPT_RANGES, RANGE_UNIT_BYTES);
resp.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return Boolean.TRUE;
}
String rangeHeader = req.getHeader(RANGE);
Range range = null;
if (rangeHeader != null) {
range = Range.createFromRangeHeader(rangeHeader);
range.completeLength = contentLength;
range.updateBytePos();

if (!range.isValid()) {
resp.setHeader(ACCEPT_RANGES, RANGE_UNIT_BYTES);
resp.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return Boolean.TRUE;
}
}

// return the full contents regularly
if (contentLength != -1)
resp.setContentLength(contentLength);
// return the full contents regularly
if (contentLength != -1)
resp.setContentLength(contentLength);

String filename = new File(resourcePath).getName();
String contentType = servletContextHelper.getMimeType(filename);
if (contentType == null)
contentType = getServletConfig().getServletContext().getMimeType(filename);
String filename = new File(resourcePath).getName();
String contentType = servletContextHelper.getMimeType(filename);
if (contentType == null)
contentType = getServletConfig().getServletContext().getMimeType(filename);

if (contentType != null)
resp.setContentType(contentType);
if (contentType != null)
resp.setContentType(contentType);

if (lastModified > 0)
resp.setDateHeader(LAST_MODIFIED, lastModified);
if (lastModified > 0)
resp.setDateHeader(LAST_MODIFIED, lastModified);

if (etag != null)
resp.setHeader(ETAG, etag);
if (etag != null)
resp.setHeader(ETAG, etag);

if (range == null &&
(servletContextHelper instanceof RangeAwareServletContextHelper) &&
((RangeAwareServletContextHelper)servletContextHelper).rangeableContentType(contentType, req.getHeader("User-Agent"))) { //$NON-NLS-1$
if (range == null &&
(servletContextHelper instanceof RangeAwareServletContextHelper) &&
((RangeAwareServletContextHelper)servletContextHelper).rangeableContentType(contentType, req.getHeader("User-Agent"))) { //$NON-NLS-1$

range = new Range();
range.firstBytePos = 0;
range.completeLength = contentLength;
range.updateBytePos();
}
range = new Range();
range.firstBytePos = 0;
range.completeLength = contentLength;
range.updateBytePos();
}

if (range != null) {
resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
resp.setHeader(ACCEPT_RANGES, RANGE_UNIT_BYTES);
resp.setContentLength(range.contentLength());
resp.setHeader(CONTENT_RANGE, RANGE_UNIT_BYTES + " " + range.firstBytePos + "-" + range.lastBytePos + "/" + range.completeLength); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
if (range != null) {
resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
resp.setHeader(ACCEPT_RANGES, RANGE_UNIT_BYTES);
resp.setContentLength(range.contentLength());
resp.setHeader(CONTENT_RANGE, RANGE_UNIT_BYTES + " " + range.firstBytePos + "-" + range.lastBytePos + "/" + range.completeLength); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

if (contentLength != 0) {
// open the input stream
try (InputStream is = connection.getInputStream()) {
// write the resource
try {
OutputStream os = resp.getOutputStream();
int writtenContentLength = writeResourceToOutputStream(is, os, range);
if (contentLength == -1 || contentLength != writtenContentLength)
resp.setContentLength(writtenContentLength);
} catch (IllegalStateException e) { // can occur if the response output is already open as a Writer
Writer writer = resp.getWriter();
writeResourceToWriter(is, writer, range);
// Since ContentLength is a measure of the number of bytes contained in the body
// of a message when we use a Writer we lose control of the exact byte count and
// defer the problem to the Servlet Engine's Writer implementation.
}
} catch (FileNotFoundException | SecurityException e) {
// SecurityException may indicate the following scenarios
// - url is not accessible
sendError(resp, HttpServletResponse.SC_FORBIDDEN);
if (contentLength != 0) {
// open the input stream
try (InputStream is = connection.getInputStream()) {
// write the resource
try {
OutputStream os = resp.getOutputStream();
int writtenContentLength = writeResourceToOutputStream(is, os, range);
if (contentLength == -1 || contentLength != writtenContentLength)
resp.setContentLength(writtenContentLength);
} catch (IllegalStateException e) { // can occur if the response output is already open as a Writer
Writer writer = resp.getWriter();
writeResourceToWriter(is, writer, range);
// Since ContentLength is a measure of the number of bytes contained in the body
// of a message when we use a Writer we lose control of the exact byte count and
// defer the problem to the Servlet Engine's Writer implementation.
}
} catch (FileNotFoundException | SecurityException e) {
// SecurityException may indicate the following scenarios
// - url is not accessible
sendError(resp, HttpServletResponse.SC_FORBIDDEN);
}
return Boolean.TRUE;
}
return Boolean.TRUE;
}, acc);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ public String getMimeType(final String name) {

try {
mimeType = AccessController.doPrivileged(
new PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
return servletContextHelper.getMimeType(name);
}
}, acc
(PrivilegedExceptionAction<String>) () -> servletContextHelper.getMimeType(name), acc
);
}
catch (PrivilegedActionException e) {
Expand All @@ -187,12 +182,7 @@ public RequestDispatcher getNamedDispatcher(String servletName) {
public String getRealPath(final String path) {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
return servletContextHelper.getRealPath(path);
}
}, acc
(PrivilegedExceptionAction<String>) () -> servletContextHelper.getRealPath(path), acc
);
}
catch (PrivilegedActionException e) {
Expand Down Expand Up @@ -224,12 +214,7 @@ public RequestDispatcher getRequestDispatcher(String path) {
public URL getResource(final String name) {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<URL>() {
@Override
public URL run() throws Exception {
return servletContextHelper.getResource(name);
}
}, acc
(PrivilegedExceptionAction<URL>) () -> servletContextHelper.getResource(name), acc
);
}
catch (PrivilegedActionException e) {
Expand Down Expand Up @@ -263,12 +248,7 @@ public Set<String> getResourcePaths(final String name) {

try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Set<String>>() {
@Override
public Set<String> run() throws Exception {
return servletContextHelper.getResourcePaths(name);
}
}, acc
(PrivilegedExceptionAction<Set<String>>) () -> servletContextHelper.getResourcePaths(name), acc
);
}
catch (PrivilegedActionException e) {
Expand Down

0 comments on commit d12832b

Please sign in to comment.