GWT logging to file - gwt

I am writing my first GWT and i confess i have no idea how to set up loggers.
I am deploying the application to tomcat and want to be able to set up a logger so that i can log to a file in $catalina.home. Gwt came with logging.properties for a java util style log and log4j.properties; i have looked at documentation for the gwt java util logger and it seems to just write to console so it must be log4j i need?
In the past ive seen org.apache.log4j.Logger used, is this what i want?
Could somebody please point me to somewhere where this is documented?
Thanks.

The documentation is here. You can't use file appenders directly because the GWT code runs as Javascript in the browser (when not in development mode). If you want to log to a file you need to enable remote logging.
If there is a server side part logging works as normal. But then it has not much to do with GWT, except for being in the same project and providing services (via a custom protocol).

What do you want to log? rpc service servlets or client logic?
Log4j is just for java not javascript. So it is intended to log your classes in your /server/ package that will be deployed in your server.
Your /client/ package classes will be translated to javascript and will run in the client browser. So, no Java at all!
You can use log4j "emulated" to javascript with http://code.google.com/p/gwt-log/ which will send your client logs using a RemoteLogger to the server via rpc and then you can log them to a file.

Related

How can I let Tomcat run a command after it finishes deploying web application's .war files

We know that during Tomcat startup, it will deploy the .war files of its web applications. My question is after the deployment I need to run a command to modify a file inside WEB-INF/ of the web application which is generated after deployment, and I need to let Tomcat do this automatically for me, is this possible to achieve ? Something like post_run command after deployment.
I found that CustomEventHookListener can probably do this How to run script on Tomcat startup?, but this involves in making a new Java class, and I'm not allowed to do so. I have to figure out way to modify the existing Tomcat configs like server.xml or tomcat.conf in TOMCAT_HOME/conf to do so.
The main issue about not using a Event Hook Listener is that there's no reliable way to tell if the application is ready or not, as Catalina implements it's own lifecycle for each of their components (as seen in https://tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/Lifecycle.html).
Your best shot is to use tail or some external program infer the component's state, but AFAIK there's no way to implement listeners directly in the configuration files.

Location of Websphere Application Server config files

I have a Websphere Application Server v8.0, and my job requires me to change the location of my JDBC data source to different values to test in different environments. I traditionally would do this via the admin console and change the settings via the Resources > JDBC > Data sources section, but I'd like to write a script to change these settings. When I run the admin console, where do the settings get stored? I can run the console vis-a-vis the Servers tab in Eclipse (Rational Application Developer) or by navigating to localhost:9044, but I don't know where the settings are stored - which I'd need to write said script.
Can anybody help me out?
From what I remember of WebSphere Application Server, the settings are ultimately persisted to the file system - however you shouldn't be changing them this way because application server config is a messy and complicated business and by directly changing settings you risk destroying your app server.
I'd recommend checking out this redbook, particularly Chapter 8 which describes how you can configure your app server with scripts. Also I seem to recall plans to display the equivalent scripting commands in the admin console.
If it helps, I had a quick look locally and found a reference to my JDBC data source in "resources.xml" located within the websphere directory at...
<server profile root>\config\cells\<aNodeCell>\nodes\<aNode>\servers\<aServer>
In the past I've used xml config to read values for convenience, but not often to update. Instead I have made use of some of the jython script options available and can echo Jim's response to check out the options there in case there is something that would be a viable alternative.
Edit:
There is another link that may be of interest Configuring data access with wsadmin scripting. I've not used this particular feature of wsadmin myself but it does appear to show promise at first glance.
If you want to write a script, then rather than looking at file system write a proper jython script, which will do your modifications in the similar way as you would do it via console.
To make writing script easier you can use:
Command assistance in the console - the Help portlet on the right shows last invoked command in jython
Script library, which already provides some scripts - Automating data access resource configuration using wsadmin scripting
And basic scripting commands - Configuring data access with wsadmin scripting

GWT app does not work properly when deployed to Tomcat server

I have a litte web app which works properly when deployed to the App Engine in Eclipse.
However, I get an error when I want to deploy my app to my Tomcat server.
I copied the content of my war folder directly to the default ROOT folder of Tomcat.
Then I run my app on an external server inside Eclipse.
Everything works fine to that point - the app is loaded straight from the browser's cache.
Here comes the problem:
The google chrome development console says "Uncaught ReferenceError: function is not defined" when I click on some features of my app that are realized through JSNI on GWT side.
I understand that the error comes from a JS caller inside external JS code. The caller invokes a GWT client-side method/function (that's why it is not defined in the ext. JS code).
Any suggestions on how to solve this problem?
Do you have any extra modules that require external js files? Some modules require the js files to be included in the war and included in your root .html file. It could be the case that you are using a library that doesn't have the base js functions.
You can add this to your .gwt.xml file to turn on the stack trace.
<set-property name="compiler.stackMode" value="emulated"/>
<set-configuration-property name="compiler.emulatedStack.recordLineNumbers" value="true"/>
<set-configuration-property name="compiler.emulatedStack.recordFileNames" value="true"/>
You could also try the setUncaughtException handler to see exceptions that are being thrown in production mode. With the emulated stack trace turned on you should be able to get a backtrace that has line numbers for your code. It is not as good as development mode but very useful for debugging.
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler()) {
#Override
public void onUncaughtException(Throwable cause) {
logger.log(Level.SEVERE, "OOPS", cause);
}
}
Note Make sure your logger is configured to use something you can access. Like firebug or remote logging servlet.
I currently use tomcat 7 in production and development mode using eclipse. You can configure a tomcat instance of the server in eclipse and use the "Run as WebApplication on External Server". This will allow you to see the exception in development mode.
Also make sure you don't have the ?gwt.codesvr=127.0.0.1:9997 if you are in production mode. This will cause problems too unless you have the development code server running.

Logging with SuperDevMode. System.out.println not working

Why?
When use System.out.println in client - nothing is output in console of CodeServer.
Now I'm logging in browser console, but how to log in system console?
p.s. I know that best way for logging in gwt is using com.google.gwt.logging.Logging module. It's also now working with system console.
The super dev mode is basically the same than a production compile (it just does not optimize)
In production (compiled javascript) System.out does not print anything into your java server side process. Your code runs in the Javascript VM and it would need to go over the wire to print to the java console.
If you are running in dev mode you are running inside the JVM that is connected to a plugin inside your browser. This is why System.out works.
I set up a remote logger to solve this problem. This way all the client log statements are sent to the server where the logging still works. You can find instructions here: Setup a remoteLoggingServlet in GWT.
Then you can use normal java util logging.
import java.util.logging.Logger;
private static Logger log = Logger.getLogger("mylogger");
Stack traces are unfortunately in javascript. I haven't figured out how to get proper java ones yet.
Hope this helps!
Not the prettiest of solutions but you can create a native JSNI method like this:
public static native void debug(String text)/*-{
console.debug(text)
}-*/;
Then just call:
debug("text here").
And it should output to the console.

How to share a GWT RPC RemoteServiceServlet among multiple client modules / apps

I have several GWT modules and web apps running in Jetty. They each want to use my LoginService RPC interface, so I put this interface and its servlet implementation in a common module. I serve the servlet (LoginServiceImpl) from my root web context, and web.xml exposes it at the url "/loginService". In a another GWT module, to use this service, I had to set the entry point, like this...
LoginServiceAsync loginService = GWT.create(LoginService.class);
ServiceDefTarget t = (ServiceDefTarget)loginService;
t.setServiceEntryPoint("/loginService");
Now, the module trying to use the loginService is called discussions, and I get this error on the server.
ERROR: The serialization policy file
'/discussions/discussions/7B344C69AD493C1EC707EC98FE148AA0.gwt.rpc' was not found;
did you forget to include it in this deployment?
So the servlet is reporting an error that mentions the client (the discussions module). I'm guessing that the RPC plumbing passed the name of this .rpc file through from the client, and the servlet is now looking for it. (?) As an experiment, I copied, the *.gwt.rpc files from the discussions module into the root web context, so the servlet could find them. This did stop the error. But I still get another error:
com.google.gwt.user.client.rpc.SerializationException: Type
'mystuff.web.shared.User' was not assignable to
'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field
serializer. For security purposes, this type will not be serialized.: ...
This class is serializable; it worked before in other modules, so now I'm lost.
What is the right way to use the LoginService from multiple clients modules?
Update:
This error was showing up in hosted devmode, and it went away after a full compile. Maybe this is related to gwt serialization policy hosted mode out of sync . I will update again if I can better reproduce the problem.
See my answer here. The short answer is: you'll need to make mystuff.web.shared.Users source available at compile-time to your discussions module.