Discussion:
Overriding MultiPartConfig
Mark A. Claassen
2018-11-26 17:11:23 UTC
Permalink
I am having trouble finding a way to override my MultiPart config. I have a servlet with a configuration in the web.xml.
<servlet>
...
<multipart-config>
...
</multipart-config>
</servlet>

However, I would like to be able to be able to configure this outside of the web.xml file so it can be changed outside of the webapp directory. Is there a way to do this from the "context" in the conf/Catalina/localhost directory?
Doing it programmatically would be ok for me as well, but I can't find anyway to access the multi-part config through the standard APIs.

I don't think I can use the annotation @MultipartConfig since I am writing something that extends javax.ws.rs.core.Application and I need to be able to configure this at startup time.

I am just using Jersey, running inside of Tomcat.

Thanks!

Mark Claassen
Senior Software Engineer

Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN 46601
E-mail: mailto:***@ocie.net
Voice: (574)232-3784
Fax: (574)232-4014

Disclaimer:
The opinions provided herein do not necessarily state or reflect
those of Donnell Systems, Inc.(DSI). DSI makes no warranty for and
assumes no legal liability or responsibility for the posting.
Mark Thomas
2018-11-26 17:41:33 UTC
Permalink
Post by Mark A. Claassen
I am having trouble finding a way to override my MultiPart config. I have a servlet with a configuration in the web.xml.
<servlet>
...
<multipart-config>
...
</multipart-config>
</servlet>
However, I would like to be able to be able to configure this outside of the web.xml file so it can be changed outside of the webapp directory. Is there a way to do this from the "context" in the conf/Catalina/localhost directory?
No.
Post by Mark A. Claassen
Doing it programmatically would be ok for me as well, but I can't find anyway to access the multi-part config through the standard APIs.
You can only do this if you remove the entry from web.xml.

You'd need to register the servlet in a ServletContextListener and then
use ServletContext#addServlet() and then ServletRegistration.Dynamic#
setMultipartConfig()

(along with ading any other configuration / mapping required by the servlet)
@MultipartConfig has to be added to a Servlet class and can only be
changed by recompilation - which is more work than changing web.xml.
Post by Mark A. Claassen
I am just using Jersey, running inside of Tomcat.
Thanks!
Mark Claassen
Senior Software Engineer
Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN 46601
Voice: (574)232-3784
Fax: (574)232-4014
The opinions provided herein do not necessarily state or reflect
those of Donnell Systems, Inc.(DSI). DSI makes no warranty for and
assumes no legal liability or responsibility for the posting.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Mark A. Claassen
2018-11-26 21:57:55 UTC
Permalink
Thanks for the reply!

I have been working this for a while and having been failing. There is so much going on here that I don't understand that I feel like such a newby.

First, when the multi-part config is in my local web.xml, everything works. However, if I remove that whole servlet from my web.xml, I see that Jersey initializes my servlet on its own first, and then my context listener tries to add it again and the registration object I get back from addServlet is null.

I assume that Jersey is doing this auto-configuration based on the annotations I use, but if this is true, why does it work when the configuration is in my web.xml? The org.apache.catalina.Wrapper created in the Application has an Overridable property, but it is false here.

Any help would be appreciated. Is this more of a Jersey question?

Mark Claassen
Senior Software Engineer

Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN  46601
E-mail: mailto:***@ocie.net
Voice: (574)232-3784
Fax: (574)232-4014
 
-------------------------------------------
Confidentiality Notice: OCIESERVICE
-------------------------------------------
The contents of this e-mail message and any attachments are intended solely for the addressee(s) named in this message. This communication is intended to be and to remain confidential. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message and its attachments. Do not deliver, distribute, copy, disclose the contents or take any action in reliance upon the information contained in the communication or any attachments.

-----Original Message-----
From: Mark Thomas <***@apache.org>
Sent: Monday, November 26, 2018 12:42 PM
To: Tomcat Users List <***@tomcat.apache.org>
Subject: Re: Overriding MultiPartConfig
Post by Mark A. Claassen
I am having trouble finding a way to override my MultiPart config. I have a servlet with a configuration in the web.xml.
<servlet>
...
<multipart-config>
...
</multipart-config>
</servlet>
However, I would like to be able to be able to configure this outside of the web.xml file so it can be changed outside of the webapp directory. Is there a way to do this from the "context" in the conf/Catalina/localhost directory?
No.
Post by Mark A. Claassen
Doing it programmatically would be ok for me as well, but I can't find anyway to access the multi-part config through the standard APIs.
You can only do this if you remove the entry from web.xml.

You'd need to register the servlet in a ServletContextListener and then use ServletContext#addServlet() and then ServletRegistration.Dynamic#
setMultipartConfig()

(along with ading any other configuration / mapping required by the servlet)
@MultipartConfig has to be added to a Servlet class and can only be changed by recompilation - which is more work than changing web.xml.
Post by Mark A. Claassen
I am just using Jersey, running inside of Tomcat.
Thanks!
Mark Claassen
Senior Software Engineer
Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN 46601
Voice: (574)232-3784
Fax: (574)232-4014
The opinions provided herein do not necessarily state or reflect those
of Donnell Systems, Inc.(DSI). DSI makes no warranty for and assumes
no legal liability or responsibility for the posting.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Mark Thomas
2018-11-27 10:15:29 UTC
Permalink
Post by Mark A. Claassen
Thanks for the reply!
I have been working this for a while and having been failing. There is so much going on here that I don't understand that I feel like such a newby.
First, when the multi-part config is in my local web.xml, everything works. However, if I remove that whole servlet from my web.xml, I see that Jersey initializes my servlet on its own first, and then my context listener tries to add it again and the registration object I get back from addServlet is null.
I assume that Jersey is doing this auto-configuration based on the annotations I use, but if this is true, why does it work when the configuration is in my web.xml? The org.apache.catalina.Wrapper created in the Application has an Overridable property, but it is false here.
web.xml takes precedence over web-fragment.xml files and annotations
(Servlet spec rules for merging configuration settings).

I suspect Jersey sees there is no Servlet and defines a default.

Maybe try this and if this doesn't work ask the Jersey folks.

- Define the Servlet in web.xml

- In your ServletContextListener use
ServletContext#getServletRegistrations() and find the Servlet in
question

- Modify the MultiPartConfig for that Servlet as required.

HTH,

Mark
Post by Mark A. Claassen
Any help would be appreciated. Is this more of a Jersey question?
Mark Claassen
Senior Software Engineer
Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN  46601
Voice: (574)232-3784
Fax: (574)232-4014
 
-------------------------------------------
Confidentiality Notice: OCIESERVICE
-------------------------------------------
The contents of this e-mail message and any attachments are intended solely for the addressee(s) named in this message. This communication is intended to be and to remain confidential. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message and its attachments. Do not deliver, distribute, copy, disclose the contents or take any action in reliance upon the information contained in the communication or any attachments.
-----Original Message-----
Sent: Monday, November 26, 2018 12:42 PM
Subject: Re: Overriding MultiPartConfig
Post by Mark A. Claassen
I am having trouble finding a way to override my MultiPart config. I have a servlet with a configuration in the web.xml.
<servlet>
...
<multipart-config>
...
</multipart-config>
</servlet>
However, I would like to be able to be able to configure this outside of the web.xml file so it can be changed outside of the webapp directory. Is there a way to do this from the "context" in the conf/Catalina/localhost directory?
No.
Post by Mark A. Claassen
Doing it programmatically would be ok for me as well, but I can't find anyway to access the multi-part config through the standard APIs.
You can only do this if you remove the entry from web.xml.
You'd need to register the servlet in a ServletContextListener and then use ServletContext#addServlet() and then ServletRegistration.Dynamic#
setMultipartConfig()
(along with ading any other configuration / mapping required by the servlet)
@MultipartConfig has to be added to a Servlet class and can only be changed by recompilation - which is more work than changing web.xml.
Post by Mark A. Claassen
I am just using Jersey, running inside of Tomcat.
Thanks!
Mark Claassen
Senior Software Engineer
Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN 46601
Voice: (574)232-3784
Fax: (574)232-4014
The opinions provided herein do not necessarily state or reflect those
of Donnell Systems, Inc.(DSI). DSI makes no warranty for and assumes
no legal liability or responsibility for the posting.
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org

Loading...