Posts Tagged ‘Java’

HowTo: Setup GWT remote logging

Posted: February 26, 2013 in howto, Java, Technology
Tags: , , ,

I find the official documentation on remote logging wasn’t complete. Here are my notes based on various web sites I visited (here, here, and here). Hope this helps!

App.gwt.xml

You should add the inherits statement below. You should be able to adjust the log level to any of the following: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE. I find the popup log console in the browser annoying, so I disabled it.

<inherits name=”com.google.gwt.logging.Logging”/>
<set-property name=”gwt.logging.simpleRemoteHandler” value=”ENABLED” />
<set-property name=”gwt.logging.logLevel” value=”FINEST”/>
<set-property name=”gwt.logging.enabled” value=”TRUE”/>
<set-property name=”gwt.logging.consoleHandler” value=”ENABLED” />
<set-property name=”gwt.logging.popupHandler” value=”DISABLED” />

web.xml

The following code is necessary for the server to receive log information and redirect to server log file.

<servlet>
<servlet-name>remoteLogging</servlet-name>
<servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogging</servlet-name>
<url-pattern>/YOUR_MODULE/remote_logging</url-pattern>
</servlet-mapping>

java

Here is the example code you can use in GWT client-side.

import com.google.gwt.logging.client.SimpleRemoteLogHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

SimpleRemoteLogHandler remoteLog = new SimpleRemoteLogHandler();
remoteLog.publish(new LogRecord(Level.INFO, “log message”));

Enable print: I was able to add print feature to a GWT app by using gwt-print-it library. I used last example in the documentation to get the printing to work (see included code fragment below).

Print.it(“<!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 4.01//EN’ ‘http://www.w3.org/TR/html4/strict.dtd’>&#8221;, “<link rel=StyleSheet type=text/css media=paper href=/paperStyle.css>”, RootPanel.get(“myId”));

I had to use absolute URLs instead of relative paths for CSS href attributes. Although this library can potentially help me to eliminate the need to create a separate print friendly display code, this created several challenges:

CSS link difference: After attempted to print using several browsers, I discovered that different browsers will interpret href attribute for the CSS links differently. To avoid the need to create browser specific code, I tried the following workaround:

Element body = RootPanel.getBodyElement();
Print.it((Element) body.getParentElement());

This will print the whole page, which includes all the CSS references that are already working for the browsers and eliminate the need to define separate CSS links that does not work across browsers.  :)

Image link difference: I also discovered that the image links are also broken when attempt to print. This is a known “feature” according to gwt-print-it documentation. So, instead of defining images using <img> tags, I used background-image definition in my CSS file and use a div tag with an ID to associate with the CSS definition. See answer #7 in this page for code example. This effectively unified how browsers reference images, which always relative from where CSS file is located. This means I no longer need to create print specific URLs for images. :)

Background image printing: Once I started to use background images, Chrome stopped printing the images. A search on Internet led me to this solution, which worked great. :) For Mozilla, users can enable printing of background images by select Options tab in the Print window and check “Print Background Images”.

I found a need to debug JBoss with Eclipse. A search on google led me to ths page. I had to tweak a bit to get my local instance to work.

For example, I had to change the quote character from ” to “.

JAVA_OPTS="-Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n $JAVA_OPTS"

After that, JBOSS was able to load the new parameters correctly.

The post also have slightly different UI screen than what I see on my version of Eclipse. I did the following:

  1. Go to Run –> Debug Configurations … in the menu
  2. Rick click on Remote Java Application and choose New
  3. Choose the project of your choice. Change the address to 8787 to match the parameter specified for JBoss earlier. Change host name if necessary.
  4. Click Apply and then Debug

I was able to connect to the server and start debug the application. :)

History and tab panel in GWT

Posted: August 4, 2011 in howto, Technology
Tags: , , ,

I came across this tutorial and found it useful! :)

While trying to setup JMS code, I encountered a few small issues and resolved them. Here are my notes:

Where in the world is ChapterExRepository? Here it is.

According to the following thread, one way to include log4j xml config file is to include the path to the file in the classpath.

SSO enable a web app

Posted: June 29, 2011 in Technology
Tags: , , ,

Yesterday, I finally SSO enabled a second web application using CAS (specifically CAS Java client) The process was relatively similar to the steps documented in the client page.

I found a need to retrieve a configuration value in web.xml and found the following post useful.

After I was so spoiled by GWT/Eclipse’s streamlined way of deploying a GWT application to the embedded server or Google App Engine, I was annoyed by how little support it has for other application servers. Fortunately, I was able to semi-automatically generate a WAR file for manual deployment on a remote server by following this tutorial :)

Back when I was working with Netbeans, deployment to a remote server was as simple as a single mouse click. On Eclipse, deployment to a remote server appears to be discouraged.

GWT SimplePager

Posted: June 9, 2011 in howto, Technology
Tags: , , , ,

It’s unfortunate that my initial experience with GWT’s SimplePager wasn’t very positive. The paging behaviour toward end of the list showed the following:

  1. For the last page, pager would attempt to request record count at last index + page size. This would cause pager to go index array out of bound. i.e. Let’s say you have 95 records with a page size of 10. The last page’s record index should be 90. If you add page size to it, you get 100. Requesting records between 90 and 100 caused the index array out of bound exception.
  2. If you use next page button navigate to the last page, it would display the last page in a way that the pager would fill the last page with a number of records the same as page size, no matter how many total records are. This created a very weird user experience. i.e For the same parameters above, you would see records #80-90 on the second to last page and then #85-95 on the last page.

After looking on-line for answers, I came across this thread and it helped me to resolve the issues that I observed above. :)

GWT dev mode remote access

Posted: June 1, 2011 in howto
Tags: , , ,

I needed to access the GWT build-in server for Eclipse from another machine. A search on-line led me to this tutorial. It worked! :)