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

WICKET-7121: Make it possible to disable the noisy logs by RequestCycle #928

Merged
merged 10 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.apache.wicket.core.request.handler;
renoth marked this conversation as resolved.
Show resolved Hide resolved

import static org.assertj.core.api.Assertions.assertThat;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.mock.MockApplication;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.jupiter.api.Test;

class ListenerInvocationNotAllowedExceptionTest
{
@Test
void smokeTest()
{
var tester = new WicketTester(new MockApplication());
// Arrange
var label = new Label("id", "Label");
var cut = new ListenerInvocationNotAllowedException(label,
new AttributeModifier("class", "test"), "no no no");
// Act

//Assert
assertThat(cut.getMessage()).startsWith("no no noComponent: [Component id = id], Path: id, Behavior:");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ public ListenerInvocationNotAllowedException(Component component, Behavior behav
this.behavior = behavior;
}

private static String detail(Component component,
Behavior behavior)
private static String detail(Component component, Behavior behavior)
{
StringBuilder detail = new StringBuilder("Component: ").append(component.toString(false));
detail.append(", Path: ").append(component.getPath());

if (behavior != null)
{
detail.append(" Behavior: ").append(behavior.toString());
detail.append(", Behavior: ").append(behavior);

}
return detail.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
* During {@link IRequestHandler} execution the handler can schedule another {@link IRequestHandler}
* to run after it is done, or replace all {@link IRequestHandler}s on stack with another
* {@link IRequestHandler}.
*
*
* @see #scheduleRequestHandlerAfterCurrent(IRequestHandler)
* @see #replaceAllRequestHandlers(IRequestHandler)
*
*
* @author Matej Knopp
* @author igor.vaynberg
*/
Expand All @@ -85,7 +85,7 @@ public class RequestCycle implements IRequestCycle, IEventSink, IMetadataContext

/**
* Returns request cycle associated with current thread.
*
*
* @return request cycle instance or <code>null</code> if no request cycle is associated with
* current thread.
*/
Expand All @@ -95,7 +95,7 @@ public static RequestCycle get()
}

/**
*
*
* @param requestCycle
*/
private static void set(RequestCycle requestCycle)
Expand Down Expand Up @@ -127,7 +127,7 @@ private static void set(RequestCycle requestCycle)

/**
* Construct.
*
*
* @param context
*/
public RequestCycle(RequestCycleContext context)
Expand All @@ -149,7 +149,7 @@ public RequestCycle(RequestCycleContext context)
}

/**
*
*
* @return a new url renderer
*/
protected UrlRenderer newUrlRenderer()
Expand All @@ -162,7 +162,7 @@ protected UrlRenderer newUrlRenderer()
* Get the original response the request was created with. Access to the original response may
* be necessary if the response has been temporarily replaced but the components require methods
* from original response (i.e. cookie methods of WebResponse, etc).
*
*
* @return The original response object.
*/
public Response getOriginalResponse()
Expand All @@ -172,7 +172,7 @@ public Response getOriginalResponse()

/**
* Returns {@link UrlRenderer} for this {@link RequestCycle}.
*
*
* @return UrlRenderer instance.
*/
@Override
Expand All @@ -187,7 +187,7 @@ public final UrlRenderer getUrlRenderer()

/**
* Resolves current request to a {@link IRequestHandler}.
*
*
* @return RequestHandler instance
*/
protected IRequestHandler resolveRequestHandler()
Expand All @@ -211,7 +211,7 @@ protected int getExceptionRetryCount()

/**
* Convenience method that processes the request and detaches the {@link RequestCycle}.
*
*
* @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
* otherwise.
*/
Expand All @@ -231,7 +231,7 @@ public boolean processRequestAndDetach()

/**
* Processes the request.
*
*
* @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
* otherwise.
*/
Expand Down Expand Up @@ -280,7 +280,7 @@ public boolean processRequest()

/**
* Execute a request handler and notify registered {@link IRequestCycleListener}s.
*
*
* @param handler
*/
private void execute(IRequestHandler handler)
Expand All @@ -293,7 +293,7 @@ private void execute(IRequestHandler handler)
listeners.onRequestHandlerResolved(this, handler);
IRequestHandler next = requestHandlerExecutor.execute(handler);
listeners.onRequestHandlerExecuted(this, handler);

handler = next;
}
catch (RuntimeException e)
Expand All @@ -317,7 +317,7 @@ private void execute(IRequestHandler handler)

/**
* Process the given exception.
*
*
* @param exception
* @param retryCount
*/
Expand All @@ -337,7 +337,7 @@ private boolean executeExceptionRequestHandler(Exception exception, int retryCou
listeners.onExceptionRequestHandlerResolved(this, handler, exception);

execute(handler);

return true;
}
catch (Exception e)
Expand All @@ -356,7 +356,7 @@ private boolean executeExceptionRequestHandler(Exception exception, int retryCou

/**
* Return {@link IRequestHandler} for the given exception.
*
*
* @param e exception to handle
* @return RequestHandler instance
*
Expand All @@ -368,13 +368,16 @@ protected IRequestHandler handleException(final Exception e)

if (Application.exists() && Application.get().usesDevelopmentConfig())
{
/*
* Call out the fact that we are processing an exception in a loud way, helps to notice
* them when developing even if they get wrapped or processed in a custom handler.
*/
logExtra.warn("********************************");
var loudExceptionLogging = Application.get().getExceptionSettings().isLoudExceptionLogging();
if (loudExceptionLogging) {
logExtra.warn("********************************");
}

logExtra.warn("Handling the following exception", e);
logExtra.warn("********************************");

if (loudExceptionLogging) {
logExtra.warn("********************************");
}
}

IRequestHandler handler = listeners.onException(this, e);
Expand All @@ -397,7 +400,7 @@ public Request getRequest()
/**
* INTERNAL This method is for internal Wicket use. Do not call it yourself unless you know what
* you are doing.
*
*
* @param request
*/
public void setRequest(Request request)
Expand All @@ -414,7 +417,7 @@ public void setRequest(Request request)
* Sets the metadata for this request cycle using the given key. If the metadata object is not
* of the correct type for the metadata key, an IllegalArgumentException will be thrown. For
* information on creating MetaDataKeys, see {@link MetaDataKey}.
*
*
* @param key
* The singleton key for the metadata
* @param object
Expand All @@ -432,10 +435,10 @@ public final <T> RequestCycle setMetaData(final MetaDataKey<T> key, final T obje

/**
* Gets metadata for this request cycle using the given key.
*
*
* @param <T>
* The type of the metadata
*
*
* @param key
* The key for the data
* @return The metadata or null if no metadata was found for the given key
Expand All @@ -455,7 +458,7 @@ public final <T> T getMetaData(final MetaDataKey<T> key)
* probably need URL relative to the currently used page, for this use
* {@linkplain #urlFor(org.apache.wicket.request.IRequestHandler)}
* </p>
*
*
* @param handler
* the {@link IRequestHandler request handler} for which to create a callback url
* @return Url instance or <code>null</code>
Expand All @@ -474,7 +477,7 @@ public Url mapUrlFor(IRequestHandler handler)
* probably need URL relative to the currently used page, for this use
* {@linkplain #urlFor(org.apache.wicket.request.resource.ResourceReference, org.apache.wicket.request.mapper.parameter.PageParameters)}
* </p>
*
*
* @param reference
* resource reference
* @param params
Expand All @@ -495,7 +498,7 @@ public Url mapUrlFor(ResourceReference reference, PageParameters params)
* probably need URL relative to the currently used page, for this use
* {@linkplain #urlFor(Class, org.apache.wicket.request.mapper.parameter.PageParameters)}
* </p>
*
*
* @param <C>
* The type of the page
* @param pageClass
Expand All @@ -514,7 +517,7 @@ public final <C extends Page> Url mapUrlFor(final Class<C> pageClass,

/**
* Returns a rendered {@link Url} for the resource reference
*
*
* @param reference
* resource reference
* @param params
Expand All @@ -532,9 +535,9 @@ public final CharSequence urlFor(ResourceReference reference, PageParameters par
* Returns a rendered bookmarkable URL that references a given page class using a given set of
* page parameters. Since the URL which is returned contains all information necessary to
* instantiate and render the page, it can be stored in a user's browser as a stable bookmark.
*
*
* @param <C>
*
*
* @param pageClass
* Class of page
* @param parameters
Expand All @@ -554,7 +557,7 @@ public final <C extends Page> CharSequence urlFor(final Class<C> pageClass,
* have been rendered.
* <p>
* The resulting URL will be relative to current page.
*
*
* @param handler
* @return Url String or <code>null</code>
*/
Expand Down Expand Up @@ -678,12 +681,12 @@ public void onDetach()
}

/**
* Called to handle a {@link java.lang.RuntimeException} that might be
* thrown during detaching phase.
*
* Called to handle a {@link java.lang.RuntimeException} that might be
* thrown during detaching phase.
*
* @param exception
*/
private void handleDetachException(RuntimeException exception)
private void handleDetachException(RuntimeException exception)
{
if (!(exception instanceof IWicketInternalException))
{
Expand All @@ -693,7 +696,7 @@ private void handleDetachException(RuntimeException exception)

/**
* Convenience method for setting next page to be rendered.
*
*
* @param page
*/
public void setResponsePage(IRequestablePage page)
Expand All @@ -709,7 +712,7 @@ public void setResponsePage(IRequestablePage page)

/**
* Convenience method for setting next page to be rendered.
*
*
* @param pageClass
* The class of the page to render
*/
Expand All @@ -733,7 +736,7 @@ public void setResponsePage(Class<? extends IRequestablePage> pageClass, RenderP

/**
* Convenience method for setting next page to be rendered.
*
*
* @param pageClass
* The class of the page to render
* @param parameters
Expand Down Expand Up @@ -867,7 +870,7 @@ public void replaceAllRequestHandlers(final IRequestHandler handler)
/**
* Finds a IRequestHandler which is either the currently executing handler or is scheduled to be
* executed.
*
*
* @return the found IRequestHandler or {@link Optional#empty()}
*/
@SuppressWarnings("unchecked")
Expand All @@ -883,7 +886,7 @@ public <T extends IRequestHandler> Optional<T> find(final Class<T> type)
{
return (Optional<T>)Optional.of(result);
}

result = getRequestHandlerScheduledAfterCurrent();
if (type.isInstance(result))
{
Expand All @@ -895,7 +898,7 @@ public <T extends IRequestHandler> Optional<T> find(final Class<T> type)

/**
* Adapts {@link RequestHandlerExecutor} to this {@link RequestCycle}
*
*
* @author Igor Vaynberg
*/
private class HandlerExecutor extends RequestHandlerExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,20 @@ public boolean isDevelopmentUtilitiesEnabled()
{
return developmentUtilitiesEnabled;
}

/**
* Strategy for outputting the Java class name of a markup container
*/
public enum ClassOutputStrategy
public enum ClassOutputStrategy
{
/**
* Output the container's class name in an HTML comment
*/
HTML_COMMENT,
HTML_COMMENT,
/**
* Output the container's class name in a tag attribute
*/
TAG_ATTRIBUTE,
TAG_ATTRIBUTE,
/**
* Do not output the container's class name
*/
Expand Down
Loading
Loading