You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Mark A. Claassen" <MC...@ocie.net> on 2018/11/26 17:11:23 UTC

Overriding MultiPartConfig

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:mclaassen@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.


Re: Overriding MultiPartConfig

Posted by Mark Thomas <ma...@apache.org>.
On 26/11/2018 21:57, Mark A. Claassen wrote:
> 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


> 
> 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:mclaassen@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 <ma...@apache.org> 
> Sent: Monday, November 26, 2018 12:42 PM
> To: Tomcat Users List <us...@tomcat.apache.org>
> Subject: Re: Overriding MultiPartConfig
> 
> On 26/11/2018 17:11, Mark A. Claassen wrote:
>> 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.
> 
>> 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)
> 
>> 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.
> 
> @MultipartConfig has to be added to a Servlet class and can only be changed by recompilation - which is more work than changing web.xml.
> 
>> 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:mclaassen@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.
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Overriding MultiPartConfig

Posted by "Mark A. Claassen" <MC...@ocie.net>.
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:mclaassen@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 <ma...@apache.org> 
Sent: Monday, November 26, 2018 12:42 PM
To: Tomcat Users List <us...@tomcat.apache.org>
Subject: Re: Overriding MultiPartConfig

On 26/11/2018 17:11, Mark A. Claassen wrote:
> 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.

> 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)

> 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.

@MultipartConfig has to be added to a Servlet class and can only be changed by recompilation - which is more work than changing web.xml.

> 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:mclaassen@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.
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Overriding MultiPartConfig

Posted by Mark Thomas <ma...@apache.org>.
On 26/11/2018 17:11, Mark A. Claassen wrote:
> 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.

> 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)

> 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.

@MultipartConfig has to be added to a Servlet class and can only be
changed by recompilation - which is more work than changing web.xml.

> 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:mclaassen@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.
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org