-
Notifications
You must be signed in to change notification settings - Fork 103
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
[JENKINS-73258] Migrate Stapler from EE 8 to EE 9 #482
Changes from 3 commits
6830dd3
c3c8b63
6aad5e3
a8c6e02
3de077e
78cf874
8160998
1e2df1e
0287073
40f6ad8
499af8d
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 |
---|---|---|
@@ -0,0 +1,192 @@ | ||
package io.jenkins.servlet; | ||
basil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import io.jenkins.servlet.http.HttpServletRequestWrapper; | ||
import io.jenkins.servlet.http.HttpServletResponseWrapper; | ||
import java.util.Objects; | ||
import javax.servlet.AsyncContext; | ||
import javax.servlet.AsyncListener; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class AsyncContextWrapper { | ||
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. @basil Just curious why don't we have the documentation for any of the class here. At least 1-2 liner description would have given the clarity that the purpose of that class. 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 not hurt, but the most important aspect of Javadoc in this PR is linking to non-deprecated versions of newly-deprecated functionality, which I have done consistently. |
||
public static jakarta.servlet.AsyncContext toJakartaAsyncContext(AsyncContext from) { | ||
Objects.requireNonNull(from); | ||
return new jakarta.servlet.AsyncContext() { | ||
@Override | ||
public jakarta.servlet.ServletRequest getRequest() { | ||
ServletRequest request = from.getRequest(); | ||
return request instanceof HttpServletRequest | ||
? HttpServletRequestWrapper.toJakartaHttpServletRequest(((HttpServletRequest) request)) | ||
: io.jenkins.servlet.ServletRequestWrapper.toJakartaServletRequest(request); | ||
} | ||
|
||
@Override | ||
public jakarta.servlet.ServletResponse getResponse() { | ||
ServletResponse response = from.getResponse(); | ||
return response instanceof HttpServletResponse | ||
? HttpServletResponseWrapper.toJakartaHttpServletResponse(((HttpServletResponse) response)) | ||
: ServletResponseWrapper.toJakartaServletResponse(response); | ||
} | ||
|
||
@Override | ||
public boolean hasOriginalRequestAndResponse() { | ||
return from.hasOriginalRequestAndResponse(); | ||
} | ||
|
||
@Override | ||
public void dispatch() { | ||
from.dispatch(); | ||
} | ||
|
||
@Override | ||
public void dispatch(String path) { | ||
from.dispatch(path); | ||
} | ||
|
||
@Override | ||
public void dispatch(jakarta.servlet.ServletContext context, String path) { | ||
from.dispatch(ServletContextWrapper.fromJakartServletContext(context), path); | ||
} | ||
|
||
@Override | ||
public void complete() { | ||
from.complete(); | ||
} | ||
|
||
@Override | ||
public void start(Runnable run) { | ||
from.start(run); | ||
} | ||
|
||
@Override | ||
public void addListener(jakarta.servlet.AsyncListener listener) { | ||
from.addListener(AsyncListenerWrapper.fromJakartaAsyncListener(listener)); | ||
} | ||
|
||
@Override | ||
public void addListener( | ||
jakarta.servlet.AsyncListener listener, | ||
jakarta.servlet.ServletRequest servletRequest, | ||
jakarta.servlet.ServletResponse servletResponse) { | ||
from.addListener( | ||
AsyncListenerWrapper.fromJakartaAsyncListener(listener), | ||
servletRequest instanceof jakarta.servlet.http.HttpServletRequest | ||
? HttpServletRequestWrapper.fromJakartaHttpServletRequest( | ||
(jakarta.servlet.http.HttpServletRequest) servletRequest) | ||
: io.jenkins.servlet.ServletRequestWrapper.fromJakartaServletRequest(servletRequest), | ||
servletResponse instanceof jakarta.servlet.http.HttpServletResponse | ||
? HttpServletResponseWrapper.fromJakartaHttpServletResponse( | ||
(jakarta.servlet.http.HttpServletResponse) servletResponse) | ||
: ServletResponseWrapper.fromJakartaServletResponse(servletResponse)); | ||
} | ||
|
||
@Override | ||
public <T extends jakarta.servlet.AsyncListener> T createListener(Class<T> clazz) { | ||
// TODO implement this | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void setTimeout(long timeout) { | ||
from.setTimeout(timeout); | ||
} | ||
|
||
@Override | ||
public long getTimeout() { | ||
return from.getTimeout(); | ||
} | ||
}; | ||
} | ||
|
||
public static AsyncContext fromJakartaAsyncContext(jakarta.servlet.AsyncContext from) { | ||
Objects.requireNonNull(from); | ||
return new AsyncContext() { | ||
@Override | ||
public ServletRequest getRequest() { | ||
jakarta.servlet.ServletRequest request = from.getRequest(); | ||
return request instanceof jakarta.servlet.http.HttpServletRequest | ||
? HttpServletRequestWrapper.fromJakartaHttpServletRequest( | ||
(jakarta.servlet.http.HttpServletRequest) request) | ||
: ServletRequestWrapper.fromJakartaServletRequest(request); | ||
} | ||
|
||
@Override | ||
public ServletResponse getResponse() { | ||
jakarta.servlet.ServletResponse response = from.getResponse(); | ||
return response instanceof jakarta.servlet.http.HttpServletResponse | ||
? HttpServletResponseWrapper.fromJakartaHttpServletResponse( | ||
(jakarta.servlet.http.HttpServletResponse) response) | ||
: ServletResponseWrapper.fromJakartaServletResponse(response); | ||
} | ||
|
||
@Override | ||
public boolean hasOriginalRequestAndResponse() { | ||
return from.hasOriginalRequestAndResponse(); | ||
} | ||
|
||
@Override | ||
public void dispatch() { | ||
from.dispatch(); | ||
} | ||
|
||
@Override | ||
public void dispatch(String path) { | ||
from.dispatch(path); | ||
} | ||
|
||
@Override | ||
public void dispatch(ServletContext context, String path) { | ||
from.dispatch(ServletContextWrapper.toJakartaServletContext(context), path); | ||
} | ||
|
||
@Override | ||
public void complete() { | ||
from.complete(); | ||
} | ||
|
||
@Override | ||
public void start(Runnable run) { | ||
from.start(run); | ||
} | ||
|
||
@Override | ||
public void addListener(AsyncListener listener) { | ||
from.addListener(AsyncListenerWrapper.toJakartaAsyncListener(listener)); | ||
} | ||
|
||
@Override | ||
public void addListener( | ||
AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) { | ||
from.addListener( | ||
AsyncListenerWrapper.toJakartaAsyncListener(listener), | ||
servletRequest instanceof HttpServletRequest | ||
? HttpServletRequestWrapper.toJakartaHttpServletRequest( | ||
((HttpServletRequest) servletRequest)) | ||
: io.jenkins.servlet.ServletRequestWrapper.toJakartaServletRequest(servletRequest), | ||
servletResponse instanceof HttpServletResponse | ||
? HttpServletResponseWrapper.toJakartaHttpServletResponse( | ||
((HttpServletResponse) servletResponse)) | ||
: ServletResponseWrapper.toJakartaServletResponse(servletResponse)); | ||
} | ||
|
||
@Override | ||
public <T extends AsyncListener> T createListener(Class<T> clazz) { | ||
// TODO implement this | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void setTimeout(long timeout) { | ||
from.setTimeout(timeout); | ||
} | ||
|
||
@Override | ||
public long getTimeout() { | ||
return from.getTimeout(); | ||
} | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.jenkins.servlet; | ||
|
||
import java.util.Objects; | ||
import javax.servlet.AsyncEvent; | ||
|
||
public class AsyncEventWrapper { | ||
public static jakarta.servlet.AsyncEvent toJakartaServletHttpAsyncEvent(AsyncEvent from) { | ||
Objects.requireNonNull(from); | ||
return new jakarta.servlet.AsyncEvent( | ||
AsyncContextWrapper.toJakartaAsyncContext(from.getAsyncContext()), | ||
io.jenkins.servlet.ServletRequestWrapper.toJakartaServletRequest(from.getSuppliedRequest()), | ||
ServletResponseWrapper.toJakartaServletResponse(from.getSuppliedResponse()), | ||
from.getThrowable()); | ||
} | ||
|
||
public static AsyncEvent fromJakartaServletHttpAsyncEvent(jakarta.servlet.AsyncEvent from) { | ||
Objects.requireNonNull(from); | ||
return new AsyncEvent( | ||
AsyncContextWrapper.fromJakartaAsyncContext(from.getAsyncContext()), | ||
ServletRequestWrapper.fromJakartaServletRequest(from.getSuppliedRequest()), | ||
ServletResponseWrapper.fromJakartaServletResponse(from.getSuppliedResponse()), | ||
from.getThrowable()); | ||
} | ||
} |
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.
A dependency of the compatibility layer. Not part of the servlet container (Jetty) classpath, but part of the web application classpath in order to handle calls made from Jenkins plugins that were compiled against EE 8.