You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/04/26 07:19:00 UTC
svn commit: r532614 - in
/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples:
ServerHostNameAndTimeFilter.java linkomatic/LinkomaticApplication.java
Author: ehillenius
Date: Wed Apr 25 22:18:59 2007
New Revision: 532614
URL: http://svn.apache.org/viewvc?view=rev&rev=532614
Log: (empty)
Added:
incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java
Modified:
incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/LinkomaticApplication.java
Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java?view=auto&rev=532614
==============================================================================
--- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java (added)
+++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/ServerHostNameAndTimeFilter.java Wed Apr 25 22:18:59 2007
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.examples;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.wicket.IResponseFilter;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.util.string.AppendingStringBuffer;
+import org.apache.wicket.util.string.JavascriptUtils;
+import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.time.Duration;
+
+
+/**
+ * Displays server host name (combination of name, ipaddress and unique id,
+ * which is either based) and time it took to handle the request in the
+ * browser's status bar like this:
+ * <code>window.defaultStatus = 'Host: myhost/192.168.1.66/someid, handled in: 0.01s'</code>
+ *
+ * @author eelco hillenius
+ */
+public class ServerHostNameAndTimeFilter implements IResponseFilter
+{
+ private String host;
+
+ /**
+ * Construct, trying system property 'examples.hostname' for the server id
+ * or else current time milis.
+ */
+ public ServerHostNameAndTimeFilter()
+ {
+ String hostId = null;
+ try
+ {
+ hostId = System.getProperty("examples.hostname");
+ }
+ catch (SecurityException e)
+ {
+ }
+ if (Strings.isEmpty(hostId))
+ {
+ hostId = String.valueOf(System.currentTimeMillis());
+ }
+
+ setHostName(hostId);
+ }
+
+ /**
+ * Construct with an id.
+ *
+ * @param hostId
+ * a unique id indentifying this server instance
+ */
+ public ServerHostNameAndTimeFilter(String hostId)
+ {
+ if (hostId == null)
+ {
+ throw new IllegalArgumentException("hostId may not be null");
+ }
+
+ setHostName(hostId);
+ }
+
+ /**
+ * @see org.apache.wicket.IResponseFilter#filter(AppendingStringBuffer)
+ */
+ public AppendingStringBuffer filter(AppendingStringBuffer responseBuffer)
+ {
+ int index = responseBuffer.indexOf("<head>");
+ long timeTaken = System.currentTimeMillis() - RequestCycle.get().getStartTime();
+ if (index != -1)
+ {
+ AppendingStringBuffer script = new AppendingStringBuffer(75);
+ script.append("\n");
+ script.append(JavascriptUtils.SCRIPT_OPEN_TAG);
+ script.append("\n\twindow.defaultStatus='");
+ script.append("Host: ");
+ script.append(host);
+ script.append(", handled in: ");
+ script.append(Duration.milliseconds(timeTaken));
+ script.append("';\n");
+ script.append(JavascriptUtils.SCRIPT_CLOSE_TAG);
+ script.append("\n");
+ responseBuffer.insert(index + 6, script);
+ }
+ return responseBuffer;
+ }
+
+ /**
+ * Fill host name property.
+ *
+ * @param hostId
+ */
+ private void setHostName(String hostId)
+ {
+ try
+ {
+ InetAddress localMachine = InetAddress.getLocalHost();
+ String hostName = localMachine.getHostName();
+ String address = localMachine.getHostAddress();
+ host = ((!Strings.isEmpty(hostName)) ? hostName + "/" + address : address) + "/"
+ + hostId;
+ }
+ catch (UnknownHostException e)
+ {
+ }
+
+ if (Strings.isEmpty(host))
+ {
+ host = "<unknown>";
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/LinkomaticApplication.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/LinkomaticApplication.java?view=diff&rev=532614&r1=532613&r2=532614
==============================================================================
--- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/LinkomaticApplication.java (original)
+++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/linkomatic/LinkomaticApplication.java Wed Apr 25 22:18:59 2007
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.examples.linkomatic;
+import org.apache.wicket.examples.ServerHostNameAndTimeFilter;
import org.apache.wicket.examples.WicketExampleApplication;
import org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource;
@@ -43,4 +44,12 @@
return Home.class;
}
+ /**
+ * @see org.apache.wicket.protocol.http.WebApplication#init()
+ */
+ protected void init()
+ {
+ // log host name and server time in the browser's status bar
+ getRequestCycleSettings().addResponseFilter(new ServerHostNameAndTimeFilter());
+ }
}