Skip to content
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

Missing classes after upgrading from 11.0.24 to 12.0.14 #12490

Open
rorytorneymf opened this issue Nov 6, 2024 · 6 comments
Open

Missing classes after upgrading from 11.0.24 to 12.0.14 #12490

rorytorneymf opened this issue Nov 6, 2024 · 6 comments
Assignees
Labels

Comments

@rorytorneymf
Copy link

rorytorneymf commented Nov 6, 2024

Hello, I am updating jetty from 11.0.24 to 12.0.14 and am using EE 10.

I cannot find the following classes/methods, does anyone know if these classes has been moved to different packages, or have been replaced with something else? I think I found a few replacements but not sure:

Jetty 11.0.24 Class / Method Jetty 12.0.14 (EE 10) Class / Method
org.eclipse.jetty.security.DefaultUserIdentity org.eclipse.jetty.security.internal.DefaultUserIdentity?
org.eclipse.jetty.security.UserAuthentication org.eclipse.jetty.security.authentication.UserAuthenticationSucceeded?
org.eclipse.jetty.server.Authentication org.eclipse.jetty.security.AuthenticationState?
org.eclipse.jetty.server.Authentication.UNAUTHENTICATED Can't find anything matching in org.eclipse.jetty.security.AuthenticationState
org.eclipse.jetty.server.UserIdentity org.eclipse.jetty.security.UserIdentity?
org.eclipse.jetty.server.session.Session org.eclipse.jetty.server.Session?
org.eclipse.jetty.server.Request::setContentParameters
org.eclipse.jetty.server.Request::setContentType
org.eclipse.jetty.server.Request::setMethod
org.eclipse.jetty.server.Request::getAuthentication org.eclipse.jetty.server.Request.getAuthenticationState?
org.eclipse.jetty.server.Request::getBaseRequest I can inline the 11.0.24 code if no replacement in 12.0.14
org.eclipse.jetty.server.Request::getSessionHandler ServletApiRequest servletApiRequest = (ServletApiRequest)request; final ServletContext servletContext = servletApiRequest.getServletContext(); final ServletContextHandler servletContextHandler = ServletContextHandler.getServletContextHandler(servletContext, ""); final SessionHandler sessionHandler = servletContextHandler.getSessionHandler();
org.eclipse.jetty.server.Request::changeSessionId ((ServletApiRequest)request).changeSessionId()?

Many thanks!

@janbartel
Copy link
Contributor

First off, have you looked at the migration guide yet? https://jetty.org/docs/jetty/12/programming-guide/migration/11-to-12.html

@rorytorneymf
Copy link
Author

First off, have you looked at the migration guide yet? https://jetty.org/docs/jetty/12/programming-guide/migration/11-to-12.html

Yes thanks, I have went through the migration guide. I don't see any mention of where the above classes/methods have been moved to, or what they should be replaced by.

@janbartel
Copy link
Contributor

@rorytorneymf you didn't say which ee version you are moving to? ee8, ee9, ee10 ? This is critical to know and why we put it in the issue template. Some classes are in core jetty modules (eg org.eclipse.jetty.jetty-security jar) but others needed to be adapted to specific ee versions so can be found in ee specific jars.

@rorytorneymf
Copy link
Author

rorytorneymf commented Nov 7, 2024

@rorytorneymf you didn't say which ee version you are moving to? ee8, ee9, ee10 ? This is critical to know and why we put it in the issue template. Some classes are in core jetty modules (eg org.eclipse.jetty.jetty-security jar) but others needed to be adapted to specific ee versions so can be found in ee specific jars.

Thanks, apologies, I am using EE10. I updated the table above with some classes/methods that I think are the replacements I am looking for, there were a few remaining though I have not found yet.

@janbartel
Copy link
Contributor

@rorytorneymf jetty 12 has disentangled core apis from the servlet spec apis, whereas in previous versions of jetty there were co-mingled (as your list of apis shows). This separation allows jetty greater ease of implementing new servlet specs as a layer on top of the core. This also means you need to pick your paradigm: go with just jetty core apis or go with the servlet spec apis. So a lot of the answers to your api equivalence questions depend on which approach you're going to go with.

Also note that Requests are now immutable, and we use wrapping to vary the information we return rather than mutate the existing request so you're not going to find these extra jetty setters on any of the Request classes (core or servlet api).

BTW any class you see that has "internal" in the package name is not intended for external use, and are not exposed for osgi nor for jpms.

I would take a look at the unit tests in each of the org.eclipse.jetty.server and org.eclipse.jetty.session and org.eclipse.jetty.security modules to get a sense of how they may apply to your application. There is some documentation available on them as well, but I admit it's pretty patchy right now.

@rorytorneymf
Copy link
Author

rorytorneymf commented Nov 11, 2024

Thanks, for wrapping the request to modify the Content-Type header, replace the form params, and set the method, is this the general idea?

import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.FormFields;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.MultiMap;

import java.util.ListIterator;
import java.util.concurrent.CompletableFuture;

/**
 * The org.eclipse.jetty.server.Request object in Jetty 12 no longer has methods to set the method, content type, and parameters like
 * Jetty 11 did, so this class is a way achieving the same behaviour in Jetty 12.
 */
public final class RestoredRequest extends Request.Wrapper
{
    private String method;
    private final HttpFields fields;

    public WrappedRequest(
            final Request request,
            final String method,
            final String contentType,
            final MultiMap<String> formMap)
    {
        super(request);
        this.method = method;
        this.fields = setContentType(request, contentType);
        setFormFields(request, formMap);
    }

    private HttpFields setContentType(final Request request, final String contentType)
    {
        final HttpFields fields = request.getHeaders();
        final HttpFields.Mutable newFields = HttpFields.build(fields);

        for (ListIterator<HttpField> i = newFields.listIterator(); i.hasNext(); ) {
            final HttpField field = i.next();

            final HttpHeader header = field.getHeader();
            if (header == null) {
                continue;
            }

            if (header.equals(HttpHeader.CONTENT_TYPE)) {
                i.set(new HttpField(HttpHeader.CONTENT_TYPE, contentType));
            }
        }
        return newFields.asImmutable();
    }

    private void setFormFields(final Request request, final MultiMap<String> formMap)
    {
        final Fields fields = new Fields(formMap);
        FormFields.set(request, CompletableFuture.completedFuture(fields));
    }

    @Override
    public String getMethod()
    {
        return this.method;
    }

    @Override
    public HttpFields getHeaders()
    {
        return this.fields;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants