Child pages
  • Creating a wonder app to deploy as a servlet

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
 
		<!-- fix the web.xml file to use a custom Servlet Adaptor that allows for Project Wonder initialization -->
		
    	<replaceregexp file="${dest.dir}/${project.name}/WEB-INF/web.xml" match="com.webobjects.jspservlet.WOServletAdaptor"
    		replace="er.extensions.jspservlet.ERXServletAdaptor" byline="true" />

Actually, one other last thing

As Henrique pointed out somewhere, servlet containers are not going to be saavy about config stuff in your Properties file. That sucks, because Properties files are really great and make it really easy to configure a lot of cool Project Wonder stuff. Someone on a list I saw today suggested setting everything up programmatically (I guess with a bunch of System.setProperty statements in your Application class), but Henrique was smarter than that. With just a little modification in your Application class, you can keep your Properties goodness without having to lift a finger. Add the following two methods and you're on your way:

No Format

  @Override
  public void finishInitialization() {
      ClassLoader classLoader =
          Thread.currentThread().getContextClassLoader();

       Enumeration jarBundles = null;
       try {
          jarBundles = classLoader.getResources("Resources/Properties");
       }
       catch (IOException exception) {
          exception.printStackTrace();
       }

       URL propertiesPath = null;

       while (jarBundles.hasMoreElements()) {
          URL url = (URL) jarBundles.nextElement();

          String urlAsString = url.toString();

          if (urlAsString.contains("jsphelloworld.jar")) {
             try {
                propertiesPath =
                   new URL(URLDecoder.decode(urlAsString, "UTF-8"));
                Application.readProperties(propertiesPath);
             }
             catch (MalformedURLException exception) {
                exception.printStackTrace();
             }
             catch (UnsupportedEncodingException exception) {
                exception.printStackTrace();
             }

             break;
          }
       }
  	super.finishInitialization();
  }
   
  private static Properties readProperties(URL url) {
      Properties result = new Properties();
      if (url == null) {
         return null;
      }
      try {
         result.load(url.openStream());
      } catch (MalformedURLException exception) {
         exception.printStackTrace();
         return null;
      }
      catch (IOException exception) {
         exception.printStackTrace();
         return null;
      }
      return result;
  }

Okay, so I hacked this code up just a bit to make it work. Notice that I hard coded the reference to my application's jar file in the finishInitialization method:

No Format

          if (urlAsString.contains("jsphelloworld.jar")) {

That's pretty lame, but it works and it's late. You can do better, and I encourage you to get this value programmtically and then post your code here as an improvement. Bascially what we're doing here is referencing the Properties file as a URL rather than as a full file path so that the servlet container can get at it.

Done and done

That's it! Now, just do an ant install, copy the JSPHelloWorld folder into the webapps folder of your tomcat (or whatever) installation, restart tomcat, and load it up in your browser!

...