Author: jdonnerstag
Date: Fri Jun 10 21:42:21 2011
New Revision: 1134450

URL: http://svn.apache.org/viewvc?rev=1134450&view=rev
Log:
fixed: MarkupException appends the markup stream to the message
Issue: WICKET-3614

Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupException.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/WebPage.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AccessDeniedPage.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/ExceptionErrorPage.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/InternalErrorPage.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/PageExpiredErrorPage.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/PageA.java
    
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/encodings/Home.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupException.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupException.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupException.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupException.java
 Fri Jun 10 21:42:21 2011
@@ -78,7 +78,7 @@ public final class MarkupException exten
         */
        public MarkupException(final MarkupStream markupStream, final String 
message)
        {
-               super(message + "\n" + markupStream.toString());
+               super(message);
                this.markupStream = markupStream;
        }
 
@@ -93,7 +93,7 @@ public final class MarkupException exten
        public MarkupException(final MarkupStream markupStream, final String 
message,
                final Throwable cause)
        {
-               super(message + "\n" + markupStream.toString(), cause);
+               super(message, cause);
                this.markupStream = markupStream;
        }
 
@@ -126,4 +126,11 @@ public final class MarkupException exten
        {
                this.markupStream = markupStream;
        }
+
+       @Override
+       public String toString()
+       {
+               return getMessage() + "\n MarkupStream: " +
+                       (markupStream == null ? "[unknown]" : 
markupStream.toString());
+       }
 }

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/WebPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/WebPage.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/WebPage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/WebPage.java
 Fri Jun 10 21:42:21 2011
@@ -129,7 +129,7 @@ public class WebPage extends Page
        protected void onRender()
        {
                // Configure the response such as headers etc.
-               configureResponse();
+               
configureResponse((WebResponse)RequestCycle.get().getResponse());
 
                // The rules if and when to insert an xml decl in the response 
are a it tricky. Allow the
                // user to replace the default per page and per application.
@@ -153,12 +153,14 @@ public class WebPage extends Page
         * (@see #getMarkupType()) and the encoding. The response (and request) 
encoding is determined
         * by an application setting (@see 
ApplicationSettings#getResponseRequestEncoding()). If null,
         * no xml decl will be written.
+        * 
+        * @param response
+        *            The WebResponse object
         */
-       protected void configureResponse()
+       protected void configureResponse(final WebResponse response)
        {
                final RequestCycle cycle = getRequestCycle();
                final WebApplication application = WebApplication.get();
-               final WebResponse response = (WebResponse)cycle.getResponse();
 
                // Users may sublcass setHeader() to set there own headers
                setHeaders(response);

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AccessDeniedPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AccessDeniedPage.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AccessDeniedPage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AccessDeniedPage.java
 Fri Jun 10 21:42:21 2011
@@ -18,7 +18,6 @@ package org.apache.wicket.markup.html.pa
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.http.WebResponse;
 
 
@@ -39,15 +38,9 @@ public class AccessDeniedPage extends Ab
                add(homePageLink("homePageLink"));
        }
 
-       /**
-        * @see org.apache.wicket.markup.html.WebPage#configureResponse()
-        */
        @Override
-       protected void configureResponse()
+       protected void setHeaders(final WebResponse response)
        {
-               super.configureResponse();
-               WebResponse response = 
(WebResponse)RequestCycle.get().getResponse();
                response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }
-
 }
\ No newline at end of file

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/ExceptionErrorPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/ExceptionErrorPage.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/ExceptionErrorPage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/ExceptionErrorPage.java
 Fri Jun 10 21:42:21 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.wicket.markup.html.pages;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import javax.servlet.http.HttpServletResponse;
@@ -31,7 +30,7 @@ import org.apache.wicket.markup.html.bas
 import org.apache.wicket.markup.html.debug.PageView;
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.request.http.WebResponse;
-import org.apache.wicket.util.string.AppendingStringBuffer;
+import org.apache.wicket.util.lang.Generics;
 
 
 /**
@@ -120,7 +119,7 @@ public class ExceptionErrorPage extends 
        {
                if (throwable != null)
                {
-                       AppendingStringBuffer sb = new 
AppendingStringBuffer(256);
+                       StringBuilder sb = new StringBuilder(256);
 
                        // first print the last cause
                        List<Throwable> al = convertToList(throwable);
@@ -130,22 +129,25 @@ public class ExceptionErrorPage extends 
                        if (throwable instanceof WicketRuntimeException)
                        {
                                String msg = throwable.getMessage();
-                               if (throwable instanceof MarkupException)
+                               if ((msg != null) && 
(msg.equals(cause.getMessage()) == false))
                                {
-                                       MarkupStream stream = 
((MarkupException)throwable).getMarkupStream();
-                                       if (stream != null)
+                                       if (throwable instanceof 
MarkupException)
                                        {
-                                               String text = "\n" + 
stream.toString();
-                                               if (msg.endsWith(text))
+                                               MarkupStream stream = 
((MarkupException)throwable).getMarkupStream();
+                                               if (stream != null)
                                                {
-                                                       msg = msg.substring(0, 
msg.length() - text.length());
+                                                       String text = "\n" + 
stream.toString();
+                                                       if (msg.endsWith(text))
+                                                       {
+                                                               msg = 
msg.substring(0, msg.length() - text.length());
+                                                       }
                                                }
                                        }
-                               }
 
-                               sb.append("WicketMessage: ");
-                               sb.append(msg);
-                               sb.append("\n\n");
+                                       sb.append("WicketMessage: ");
+                                       sb.append(msg);
+                                       sb.append("\n\n");
+                               }
                        }
                        return sb.toString();
                }
@@ -168,7 +170,7 @@ public class ExceptionErrorPage extends 
                {
                        List<Throwable> al = convertToList(throwable);
 
-                       AppendingStringBuffer sb = new 
AppendingStringBuffer(256);
+                       StringBuilder sb = new StringBuilder(256);
 
                        // first print the last cause
                        int length = al.size() - 1;
@@ -200,10 +202,10 @@ public class ExceptionErrorPage extends 
         */
        private List<Throwable> convertToList(final Throwable throwable)
        {
-               List<Throwable> al = new ArrayList<Throwable>();
+               List<Throwable> al = Generics.newArrayList();
                Throwable cause = throwable;
                al.add(cause);
-               while (cause.getCause() != null && cause != cause.getCause())
+               while ((cause.getCause() != null) && (cause != 
cause.getCause()))
                {
                        cause = cause.getCause();
                        al.add(cause);
@@ -220,8 +222,7 @@ public class ExceptionErrorPage extends 
         * @param sb
         * @param stopAtWicketServlet
         */
-       private void outputThrowable(Throwable cause, AppendingStringBuffer sb,
-               boolean stopAtWicketServlet)
+       private void outputThrowable(Throwable cause, StringBuilder sb, boolean 
stopAtWicketServlet)
        {
                sb.append(cause);
                sb.append("\n");
@@ -243,19 +244,10 @@ public class ExceptionErrorPage extends 
                }
        }
 
-       /**
-        * @see org.apache.wicket.markup.html.WebPage#configureResponse()
-        */
        @Override
-       protected void configureResponse()
+       protected void setHeaders(final WebResponse response)
        {
-               super.configureResponse();
-
-               if (getRequestCycle().getResponse() instanceof WebResponse)
-               {
-                       WebResponse response = 
(WebResponse)getRequestCycle().getResponse();
-                       
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-               }
+               
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
 
        /**
@@ -267,5 +259,4 @@ public class ExceptionErrorPage extends 
        {
                return throwable;
        }
-
 }

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/InternalErrorPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/InternalErrorPage.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/InternalErrorPage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/InternalErrorPage.java
 Fri Jun 10 21:42:21 2011
@@ -18,7 +18,6 @@ package org.apache.wicket.markup.html.pa
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.http.WebResponse;
 
 
@@ -39,14 +38,9 @@ public class InternalErrorPage extends A
                add(homePageLink("homePageLink"));
        }
 
-       /**
-        * @see org.apache.wicket.markup.html.WebPage#configureResponse()
-        */
        @Override
-       protected void configureResponse()
+       protected void setHeaders(final WebResponse response)
        {
-               super.configureResponse();
-               WebResponse response = 
(WebResponse)RequestCycle.get().getResponse();
                
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
 }
\ No newline at end of file

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/PageExpiredErrorPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/PageExpiredErrorPage.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/PageExpiredErrorPage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/PageExpiredErrorPage.java
 Fri Jun 10 21:42:21 2011
@@ -18,7 +18,6 @@ package org.apache.wicket.markup.html.pa
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.http.WebResponse;
 
 
@@ -39,14 +38,9 @@ public class PageExpiredErrorPage extend
                add(homePageLink("homePageLink"));
        }
 
-       /**
-        * @see org.apache.wicket.markup.html.WebPage#configureResponse()
-        */
        @Override
-       protected void configureResponse()
+       protected void setHeaders(final WebResponse response)
        {
-               super.configureResponse();
-               WebResponse response = 
(WebResponse)RequestCycle.get().getResponse();
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
 }
\ No newline at end of file

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java
 Fri Jun 10 21:42:21 2011
@@ -229,7 +229,7 @@ public class SimplePageTest extends Wick
 
                        assertNotNull(mex.getMarkupStream());
                        assertTrue(mex.getMessage().contains("<span>"));
-                       
assertTrue(mex.getMessage().contains("SimplePage_4.html"));
+                       
assertTrue(mex.toString().contains("SimplePage_4.html"));
                }
                assertTrue("Did expect a MarkupException", hit);
        }

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java
 Fri Jun 10 21:42:21 2011
@@ -59,7 +59,7 @@ public class PanelTest extends WicketTes
 
                        assertNotNull(mex.getMarkupStream());
                        assertTrue(mex.getMessage().contains("Tag does not have 
a close tag"));
-                       
assertTrue(mex.getMessage().contains("SimplePanel_1.html"));
+                       
assertTrue(mex.toString().contains("SimplePanel_1.html"));
                }
                assertTrue("Did expect a MarkupException", hit);
        }

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/PageA.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/PageA.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/PageA.java 
(original)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/io/PageA.java 
Fri Jun 10 21:42:21 2011
@@ -17,6 +17,7 @@
 package org.apache.wicket.util.io;
 
 import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.http.WebResponse;
 
 /**
  * @author jcompagner
@@ -42,9 +43,9 @@ public class PageA extends WebPage
        }
 
        @Override
-       protected void configureResponse()
+       protected void configureResponse(final WebResponse response)
        {
-               super.configureResponse();
+               super.configureResponse(response);
        }
 
        /**

Modified: 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/encodings/Home.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/encodings/Home.java?rev=1134450&r1=1134449&r2=1134450&view=diff
==============================================================================
--- 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/encodings/Home.java
 (original)
+++ 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/encodings/Home.java
 Fri Jun 10 21:42:21 2011
@@ -20,6 +20,7 @@ import java.util.Locale;
 
 import org.apache.wicket.examples.WicketExamplePage;
 import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.request.http.WebResponse;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 
 
@@ -47,12 +48,12 @@ public class Home extends WicketExampleP
         * descriptors, this is a workaround for servlet 2.3
         */
        @Override
-       protected void configureResponse()
+       protected void configureResponse(final WebResponse response)
        {
                final Locale originalLocale = getSession().getLocale();
                getSession().setLocale(Locale.GERMANY);
 
-               super.configureResponse();
+               super.configureResponse(response);
 
                // This is no longer useful in many cases, since we now forward 
the
                // <?xml ..encoding=".." ?> from the Page's markup and use it 
explicitly


Reply via email to