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

[http] extract Multipart code into new ServletRequestMultipartWrapper #367

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

stbischof
Copy link
Contributor

Mostly in the usage of felix-jetty-light there is the cases where you do not need the multipart support and can remove the dependencies of common-fileupload and common-io. To be able to do this we could not load a instantiate a class that imports common-fileupload classes. So we have to free the old class ServletRequestWrapper of this imports and add a ServletRequestMultipartWrapper that still have the multipart support.

Mostly in the usage of felix-jetty-light there is the cases where you do
not need the multipart support and can remove the dependencies of
common-fileupload and common-io. To be able to do this we could not load
a instantiate a class that imports common-fileupload classes. So we have
to free the old class ServletRequestWrapper of this imports and add a
ServletRequestMultipartWrapper that still have the multipart support.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@paulrutter
Copy link
Contributor

I haven't checked the whole PR yet, but i would expect commons-fileupload to be marked optional in the pom.xml of the base bundle.
Otherwise the bundle wouldn't even start if those classes are not on the classpath, right?

@stbischof
Copy link
Contributor Author

stbischof commented Jan 10, 2025

yes the imports are is marked as optional. this way it could resolve and start without commons-fileupload.
And this is what i do,o i do not used the dependency on runtime.

But the class ServletRequestWrapper imports classes from commons-fileupload
https://github.com/apache/felix-dev/pull/367/files#diff-b1cfaf93f83551a9004116c63a435ac8e64b198c1e8ee68f4178d3b59073568dL51-L56

But in any case the ServletRequestWrapper must be instantiated. But this will fails because the classes are`t there

@paulrutter
Copy link
Contributor

I see, but wouldn't it make sense to mark the dependencies as optional as well, in

<dependency>
?

@laeubi
Copy link

laeubi commented Jan 10, 2025

but i would expect commons-fileupload to be marked optional in the pom.xml

Please note that "optional" means something totally different to maven, see https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

Optional is similar to "provided" but should not be included into runtime collections e.g. slf4-api will be compile and slf4-simple will be optional runtime because one might choose a different implementation of the API but it wont work without any provided!

Optional in OSGi mean it could work with or without this dependency, is really hard to get correct and almost never useful if not carefully crafted and tested. Especially in this case it might lead to hard to track runtime errors, so ClassNotFound Exceptions should be catched somewhere and output a meaningful message so the user understands how to resolve the issue.

@paulrutter
Copy link
Contributor

paulrutter commented Jan 10, 2025

Thanks for clarifying @laeubi, that makes sense 👍

It's already optional in the jetty12 bundle, is that considered a bug then?

<optional>true</optional>

According to the servlet spec, this method either throws a
ServletException if the request is not a multipart request or always
returns a collection. It never returns null. Throwing an exception seems
to be the right thing. (Karsten Ziegeler)

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
Copy link
Contributor Author

@cziegeler I now throw an ServletException on the 2 Messages. see my last commit.

@cziegeler
Copy link
Contributor

Thanks, looks good

@stbischof
Copy link
Contributor Author

also tested in my application.
Now works proper without file-upload and commons.io

@paulrutter okay with a merge?

@paulrutter
Copy link
Contributor

@stbischof Yes 👍🏻
The only thing i was wondering now is if the optional stated here (jetty12 bundle only)

<optional>true</optional>
is then correct.
From what i understood from @laeubi, that optional should not be there, right?

@stbischof stbischof merged commit 6c78c18 into apache:master Jan 13, 2025
1 check passed
@laeubi
Copy link

laeubi commented Jan 13, 2025

@paulrutter I think "optional" is sued semantically wrong here from maven point of view, but as the artifact is most likely never used as a maven dependency (but only as OSGi artifact it might not really matter, I would just remove all <optional> and let them be simple compile scope.

@paulrutter
Copy link
Contributor

I will make that change to the jetty12 bundle then.

@paulrutter
Copy link
Contributor

@laeubi See #368

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

Successfully merging this pull request may close these issues.

4 participants