Server Side Configuration for GWT

Trying to avoid reinventing the wheel here. I have a Google Web Toolkit page that I’m about to deploy, but the web service I'm talking to will have a different relative address on the deployed server than my local test machine.

So I'm looking for an easy way to deploy with some kind of easily editable configuration file that I can put on basic server-side settings. I have a couple of ideas on how to do this, but they seem somewhat hacked, and it seems to me that there should be a solution to this problem (in the end, the settings for each server are VERY common thing!)

Any ideas?

Edit: Since this does not seem to attract much attention, let me outline my initial thoughts: Keep a static file local to the GWT files that I request with an AJAX call, before any other logic. When the file is returned, I look through my data and save it as globally accessible vars, and then enable the page construction logic. It seems awkward, and there is a big drawback in waiting for AJAX to return before any download, but it will work. Any best deals? (You are welcome?)

My solution: I found the solution myself, but it is quite specific for my exact scenario, so I don’t know how useful it is for the average user. I will post it here anyway if someone finds this useful.

The page I'm working on is actually a GWT control built into ASP.net. Using this and opening the GWT Dictionary class, I put together a “settings” system, for example:

First, the setup I want (in this case, the address for the web service) is set in the ASP.net Web.Config file

<appSettings> <add key="serviceUrl" value="http://mySite.com/myService.asmx"/> </appSettings> 

On the ASP page that embeds the GWT control, I add a “static” javascript object that contains the configuration settings that I need:

 <head runat="server"> <title>Picklist Manager</title> <script type="text/javascript" language="javascript"> var AppConfig = { serviceUrl: "<%= ConfigurationManager.AppSettings["serviceUrl"] %>" }; </script> <script type="text/javascript" language="javascript" src="gwtcontrol.nocache.js"></script> <!-- Include my GWT control --> </head> 

Finally, in GWT, I create a static class "AppConfig" that provides this option:

 public class AppConfig { public static String serviceUrl = "defaultUrl"; public static void Initialize() { Dictionary appConfig = Dictionary.getDictionary("AppConfig"); if(appConfig == null) { return; } servicePath = appConfig.get("serviceUrl"); } } 

From there, I can call AppConfig.serviceUrl anywhere in my code to get the setting ... whew! So yes, this is a good long hard way to get around this, but it works for me. Of the answers given to Alexander, it seems most important what I was looking for, so generosity goes to him, but thanks to everyone who broke my sticky little problem!

+6
gwt configuration
source share
3 answers

Feel free to correct me, but it doesn't seem to you that you need server-side configuration at runtime. In case you really need this flexibility or you want to use one .zip for all deployments, you can use the technique described in the Yahoo Performance Rules - (see the section "Add expiration or header for cache management"). - In the future, the future ends with headlines. This means that the AJAX request will be heavily cached by the browser and will slightly slow down the first request.

Instead, I would suggest using the compile-time flags and the property system proposed by GWT. To simplify this, I made a small package called auto-config, available on github . Using this simplifies access to the deployment configuration. Add the following class:

 public interface MyConfiguration extends AutoConfiguration { public String getFoobar(); } 

To access the value from the GWT code, add this simple helper:

 private MyConfiguration getMyConfiguration() { return (MyConfiguration) GWT.create(MyConfiguration.class); } 

Create several different .gwt.xml files, one for each deployment server. Then minimize any duplication using the parent .gwt.xml file. For more information on this topic, read CompileOnePermutation on the wiki.

In conclusion, add the following snippet to your .gwt.xml deployment (and be sure to add the desired inheritance line):

 <set-configuration-property name="foobar" value="whee1234" /> 

Hope that helped :)

+5
source share

The easiest way is to save this configuration information somewhere available for the server code, i.e. your ServiceImpl classes.

You have several options for this:

  • set the environment variable;
  • set a system property;
  • put the properties file in the classpath;
  • find the JNDI bean.
+1
source share

I am a little confused by what you ask.

If you want to compile once and run the GWT application on different servers with different parameters and use the options on the client side during the creation of the GUI, there are many parameters.

Get information in your program using:

  • Environment variable
  • System property
  • Etc

Get information on the client side:

  • AJAX file call (as you indicated)
  • Listen to your GUI from JSP instead of static HTML. Ask JSP to insert information into a JS variable that your GUI can access by using a JSNI call. It saves you both ways.
+1
source share

All Articles