From ae47edb8a785aedc469482667d1aacdf2aefeae2 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 23 Jan 2015 13:58:42 +0100 Subject: [PATCH] 458175 multipart annotation on lazily loaded servlet does not work --- .../eclipse/jetty/servlet/ServletHolder.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index cbd13dd291f..07636d7bc23 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -745,10 +745,27 @@ public class ServletHolder extends Holder implements UserIdentity.Scope protected void prepare (Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableException { + ensureInstance(); MultipartConfigElement mpce = ((Registration)getRegistration()).getMultipartConfig(); if (mpce != null) baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, mpce); } + + public synchronized Servlet ensureInstance() + throws ServletException, UnavailableException + { + if (_class==null) + throw new UnavailableException("Servlet Not Initialized"); + Servlet servlet=_servlet; + if (!isStarted()) + throw new UnavailableException("Servlet not initialized", -1); + if (_unavailable!=0 || (!_initOnStartup && servlet==null)) + servlet=getServlet(); + if (servlet==null) + throw new UnavailableException("Could not instantiate "+_class); + + return servlet; + } /* ------------------------------------------------------------ */ /** Service a request with this servlet. @@ -769,16 +786,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope if (_class==null) throw new UnavailableException("Servlet Not Initialized"); - Servlet servlet=_servlet; - synchronized(this) - { - if (!isStarted()) - throw new UnavailableException("Servlet not initialized", -1); - if (_unavailable!=0 || (!_initOnStartup && servlet==null)) - servlet=getServlet(); - if (servlet==null) - throw new UnavailableException("Could not instantiate "+_class); - } + Servlet servlet = ensureInstance(); // Service the request boolean servlet_error=true;