From: Artur Signell Date: Tue, 4 Jun 2013 19:29:26 +0000 (+0300) Subject: Send connector debug (highlight) using RPC (#11536) X-Git-Tag: 7.1.0~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa99259;p=vaadin-framework.git Send connector debug (highlight) using RPC (#11536) Change-Id: I8995e9affd371543457f16568f1245f7467e0804 --- diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 2f5401a75b..4dd68cc24f 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -691,12 +691,12 @@ public class ApplicationConnection { * source code. * * @param serverConnector + * @deprecated as of 7.1. Replaced by + * {@link UIConnector#showServerDebugInfo(ServerConnector)} */ + @Deprecated void highlightConnector(ServerConnector serverConnector) { - String params = getRepaintAllParameters() + "&" - + ApplicationConstants.PARAM_HIGHLIGHT_CONNECTOR + "=" - + serverConnector.getConnectorId(); - makeUidlRequest("", params); + getUIConnector().showServerDebugInfo(serverConnector); } /** diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index bba9252d47..38c26a77e6 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -50,6 +50,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.ConnectorMap; import com.vaadin.client.Focusable; import com.vaadin.client.Paintable; +import com.vaadin.client.ServerConnector; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; import com.vaadin.client.communication.StateChangeEvent; @@ -68,6 +69,7 @@ import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; +import com.vaadin.shared.ui.ui.DebugWindowServerRpc; import com.vaadin.shared.ui.ui.PageClientRpc; import com.vaadin.shared.ui.ui.PageState; import com.vaadin.shared.ui.ui.ScrollClientRpc; @@ -659,4 +661,18 @@ public class UIConnector extends AbstractSingleComponentContainerConnector .getName(), "poll")); } } + + /** + * Sends a request to the server to print details to console that will help + * the developer to locate the corresponding server-side connector in the + * source code. + * + * @since 7.1 + * @param serverConnector + * the connector to locate + */ + public void showServerDebugInfo(ServerConnector serverConnector) { + getRpcProxy(DebugWindowServerRpc.class).showServerDebugInfo( + serverConnector); + } } diff --git a/server/src/com/vaadin/server/communication/MetadataWriter.java b/server/src/com/vaadin/server/communication/MetadataWriter.java index 1a3f0e946a..9993ef1e44 100644 --- a/server/src/com/vaadin/server/communication/MetadataWriter.java +++ b/server/src/com/vaadin/server/communication/MetadataWriter.java @@ -22,7 +22,6 @@ import java.io.Serializable; import java.io.Writer; import java.util.List; -import com.vaadin.server.ClientConnector; import com.vaadin.server.ComponentSizeValidator; import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.SystemMessages; @@ -54,9 +53,6 @@ public class MetadataWriter implements Serializable { * @param async * True if this message is sent by the server asynchronously, * false if it is a response to a client message. - * @param hilightedConnector - * The connector that should be highlighted on the client or null - * if none. * @param messages * a {@link SystemMessages} containing client-side error * messages. @@ -65,8 +61,7 @@ public class MetadataWriter implements Serializable { * */ public void write(UI ui, Writer writer, boolean repaintAll, - boolean analyzeLayouts, boolean async, - ClientConnector hilightedConnector, SystemMessages messages) + boolean analyzeLayouts, boolean async, SystemMessages messages) throws IOException { List invalidComponentRelativeSizes = null; @@ -109,11 +104,6 @@ public class MetadataWriter implements Serializable { } writer.write("]"); } - if (hilightedConnector != null) { - writer.write(", \"hl\":\""); - writer.write(hilightedConnector.getConnectorId()); - writer.write("\""); - } } if (async) { diff --git a/server/src/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/com/vaadin/server/communication/UidlRequestHandler.java index 73ff92f8bd..55fb473998 100644 --- a/server/src/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/com/vaadin/server/communication/UidlRequestHandler.java @@ -19,13 +19,11 @@ package com.vaadin.server.communication; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.LinkedList; import java.util.logging.Level; import java.util.logging.Logger; import org.json.JSONException; -import com.vaadin.server.ClientConnector; import com.vaadin.server.Constants; import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException; import com.vaadin.server.ServletPortletHelper; @@ -39,7 +37,6 @@ import com.vaadin.server.VaadinSession; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.JsonConstants; import com.vaadin.shared.Version; -import com.vaadin.ui.Component; import com.vaadin.ui.UI; /** @@ -79,11 +76,10 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements checkWidgetsetVersion(request); String requestThemeName = request.getParameter("theme"); - ClientConnector highlightedConnector; // repaint requested or session has timed out and new one is created boolean repaintAll; - // TODO PUSH repaintAll, analyzeLayouts, highlightConnector should be + // TODO PUSH repaintAll, analyzeLayouts should be // part of the message payload to make the functionality transport // agnostic @@ -95,14 +91,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements // analyzing can be done only with repaintAll analyzeLayouts = (request .getParameter(ApplicationConstants.PARAM_ANALYZE_LAYOUTS) != null); - - String pid = request - .getParameter(ApplicationConstants.PARAM_HIGHLIGHT_CONNECTOR); - if (pid != null) { - highlightedConnector = uI.getConnectorTracker().getConnector( - pid); - highlightConnector(highlightedConnector); - } } StringWriter stringWriter = new StringWriter(); @@ -190,63 +178,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements outWriter.write("for(;;);[{"); } - // TODO Does this belong here? - protected void highlightConnector(ClientConnector highlightedConnector) { - StringBuilder sb = new StringBuilder(); - sb.append("*** Debug details of a connector: *** \n"); - sb.append("Type: "); - sb.append(highlightedConnector.getClass().getName()); - sb.append("\nId:"); - sb.append(highlightedConnector.getConnectorId()); - if (highlightedConnector instanceof Component) { - Component component = (Component) highlightedConnector; - if (component.getCaption() != null) { - sb.append("\nCaption:"); - sb.append(component.getCaption()); - } - } - printHighlightedConnectorHierarchy(sb, highlightedConnector); - getLogger().info(sb.toString()); - } - - // TODO Does this belong here? - protected void printHighlightedConnectorHierarchy(StringBuilder sb, - ClientConnector connector) { - LinkedList h = new LinkedList(); - h.add(connector); - ClientConnector parent = connector.getParent(); - while (parent != null) { - h.addFirst(parent); - parent = parent.getParent(); - } - - sb.append("\nConnector hierarchy:\n"); - VaadinSession session2 = connector.getUI().getSession(); - sb.append(session2.getClass().getName()); - sb.append("("); - sb.append(session2.getClass().getSimpleName()); - sb.append(".java"); - sb.append(":1)"); - int l = 1; - for (ClientConnector connector2 : h) { - sb.append("\n"); - for (int i = 0; i < l; i++) { - sb.append(" "); - } - l++; - Class connectorClass = connector2 - .getClass(); - Class topClass = connectorClass; - while (topClass.getEnclosingClass() != null) { - topClass = topClass.getEnclosingClass(); - } - sb.append(connectorClass.getName()); - sb.append("("); - sb.append(topClass.getSimpleName()); - sb.append(".java:1)"); - } - } - private static final Logger getLogger() { return Logger.getLogger(UidlRequestHandler.class.getName()); } diff --git a/server/src/com/vaadin/server/communication/UidlWriter.java b/server/src/com/vaadin/server/communication/UidlWriter.java index 9c736d8dd9..a915501056 100644 --- a/server/src/com/vaadin/server/communication/UidlWriter.java +++ b/server/src/com/vaadin/server/communication/UidlWriter.java @@ -162,7 +162,7 @@ public class UidlWriter implements Serializable { .getSystemMessages(ui.getLocale(), null); // TODO hilightedConnector new MetadataWriter().write(ui, writer, repaintAll, analyzeLayouts, - async, null, messages); + async, messages); writer.write(", "); writer.write("\"resources\" : "); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d4ac156787..3194786431 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.concurrent.Future; +import java.util.logging.Logger; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; @@ -30,6 +31,7 @@ import com.vaadin.event.ActionManager; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.navigator.Navigator; +import com.vaadin.server.ClientConnector; import com.vaadin.server.LocaleService; import com.vaadin.server.Page; import com.vaadin.server.PaintException; @@ -40,15 +42,18 @@ import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinServlet; import com.vaadin.server.VaadinSession; import com.vaadin.server.communication.PushConnection; +import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.communication.PushMode; +import com.vaadin.shared.ui.ui.DebugWindowServerRpc; import com.vaadin.shared.ui.ui.ScrollClientRpc; import com.vaadin.shared.ui.ui.UIClientRpc; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.shared.ui.ui.UIServerRpc; import com.vaadin.shared.ui.ui.UIState; import com.vaadin.ui.Component.Focusable; +import com.vaadin.util.ConnectorHelper; import com.vaadin.util.CurrentInstance; /** @@ -161,6 +166,14 @@ public abstract class UI extends AbstractSingleComponentContainer implements */ } }; + private DebugWindowServerRpc debugRpc = new DebugWindowServerRpc() { + @Override + public void showServerDebugInfo(Connector connector) { + String info = ConnectorHelper + .getDebugInformation((ClientConnector) connector); + getLogger().info(info); + } + }; /** * Timestamp keeping track of the last heartbeat of this UI. Updated to the @@ -193,6 +206,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements */ public UI(Component content) { registerRpc(rpc); + registerRpc(debugRpc); setSizeFull(); setContent(content); } @@ -1441,4 +1455,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements return localeService; } + private static Logger getLogger() { + return Logger.getLogger(UI.class.getName()); + } } diff --git a/server/src/com/vaadin/util/ConnectorHelper.java b/server/src/com/vaadin/util/ConnectorHelper.java new file mode 100644 index 0000000000..e698e9222a --- /dev/null +++ b/server/src/com/vaadin/util/ConnectorHelper.java @@ -0,0 +1,101 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.util; + +import java.util.LinkedList; + +import com.vaadin.server.ClientConnector; +import com.vaadin.ui.Component; + +/** + * Provides various helper methods for connectors. Meant for internal use. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public class ConnectorHelper { + + /** + * Creates a string containing debug info for the connector + * + * @since 7.1 + * @param connector + * The connector to print debug info about + * @return A string with debug information + */ + public static String getDebugInformation(ClientConnector connector) { + StringBuilder sb = new StringBuilder(); + sb.append("*** Debug details of a connector: *** \n"); + sb.append("Type: "); + sb.append(connector.getClass().getName()); + sb.append("\nId:"); + sb.append(connector.getConnectorId()); + if (connector instanceof Component) { + Component component = (Component) connector; + if (component.getCaption() != null) { + sb.append("\nCaption:"); + sb.append(component.getCaption()); + } + } + writeHierarchyInformation(connector, sb); + return sb.toString(); + } + + /** + * Creates a string containing hierarchy information for the connector + * + * @since 7.1 + * @param connector + * The connector to get hierarchy information for + * @param builder + * The StringBuilder where the information should be written + */ + public static void writeHierarchyInformation(ClientConnector connector, + StringBuilder builder) { + LinkedList h = new LinkedList(); + h.add(connector); + ClientConnector parent = connector.getParent(); + while (parent != null) { + h.addFirst(parent); + parent = parent.getParent(); + } + + builder.append("\nConnector hierarchy:\n"); + + int l = 0; + for (ClientConnector connector2 : h) { + if (l != 0) { + builder.append("\n"); + for (int i = 0; i < l; i++) { + builder.append(" "); + } + } + l++; + Class connectorClass = connector2 + .getClass(); + Class topClass = connectorClass; + while (topClass.getEnclosingClass() != null) { + topClass = topClass.getEnclosingClass(); + } + builder.append(connectorClass.getName()); + builder.append("("); + builder.append(topClass.getSimpleName()); + builder.append(".java:1)"); + } + } + +} diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index 04cba79c0c..6124b71d34 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -40,7 +40,6 @@ public class ApplicationConstants implements Serializable { public static final String UIDL_SECURITY_TOKEN_ID = "Vaadin-Security-Key"; public static final String PARAM_ANALYZE_LAYOUTS = "analyzeLayouts"; - public static final String PARAM_HIGHLIGHT_CONNECTOR = "highlightConnector"; @Deprecated public static final String UPDATE_VARIABLE_INTERFACE = "v"; diff --git a/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java b/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java new file mode 100644 index 0000000000..ec8bc45b81 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * + */ +package com.vaadin.shared.ui.ui; + +import com.vaadin.shared.Connector; +import com.vaadin.shared.communication.ServerRpc; + +/** + * Server RPC methods for the Debug Window. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public interface DebugWindowServerRpc extends ServerRpc { + /** + * Sends a request to the server to print details to console that will help + * the developer to locate the corresponding server-side connector in the + * source code. + * + * @since 7.1 + * @param connector + * the connector to locate + **/ + public void showServerDebugInfo(Connector connector); + +}