GWT

De Lillois Fractale Wiki
Révision datée du 6 octobre 2017 à 21:22 par Pge (discussion | contributions)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigation Aller à la recherche




Intro

The information below (version numbers etc...) have been updated in October 2017.

GWT (google web toolkit) is the preferred development platform of pge. The version of GWT is 2.8.1.

It is used in combination with the Eclipse IDE (eclipse neon - 4.6.3).

The deployment of the GWT apps is realized through Tomcat (tomcat 8.0.36). See command (script) tomcatInfo. Here is the local Tomcat admin page.

The  GWT apps gives access to the available project pages.

The DVP versions are accessible : only from the the fractal network ;  when eclipse and its jetty server run on MMM for the specified project

The Prod versions and Shortcut accessible versions are accessible when tomcat runs on MMU.

All are accessible with various browsers, but Google Chrome is the most efficient.


Small project (pages)

It is possible to quickly integarte new mini.projects as part of the gwtApp set.

Such small project has a source in mscp.gwt.app.client.* or in mscp.gwt.uXXX.* . It is convenient to clone sources from an existing other small project.

To make it accessible, it is necessary to integrate it to the access tree, which is defined in msp.gwt.app.client/G.java

Potential other GWT projects

. tennis money ($ value of a point played in a tennis match - tennis prob)

. the world and me (managing private and public data, with progressive revealing - meeting perspective - admin perspective)

. M3M manifest & DDD simulator

. graphical animation language (with interactive edition - janimava)

. sedux - a meeting/matching web site

Creating a new mscp GWT project (updated june 2015)

It is assumed that all projects use the animation logic defined in class anim (gwtLibClient)

Use eclipse (not netbeans)

Here are the key steps

GWT app creation

  • create a standard GWT web app (Google -> "New Application Project")
    • project name gwtXyz
    • package name mscp.gwt.xyz
    • create in directory /home/pge/javaNB4projects/
    • (disable google app engine)
    • Finish

[ upper lower case issues !!! ]

Linked sources

GWT needs the source of uniLib and gwtLibAll.

  • This is added using: Build Path / Link Source...
  • The linked folder (origin) are ($jnb)/uniLib/src ($jnb)/gwtLibAll/src
  • The folder (target) are uniLib and gwtLibAll

[ at this stage the super dev mode should be ok ]

Standard PG general (uniLib) libraries

The standard mscp libraries may be used on the server side - not on the client side.

They are part of the uniLib project.

They may NOT be called in the gwtServer & gwtShared libs.

These libraries should first be added to the project build path (build path / add Libraries / user libraries)

But the jar files must also be manually replicated to the war/WEB-INF/lib directories (the GWT plugin does not manage that !?!).

This is done with the script warLib.

It may be necessary to repeat these copies whenever these standard libraries are updated.

Source replication necessary for client side classes are not needed for server side classes.

sources

  • replace main class code (in mscp.gwtXyz.client) with an extend of anim class. Insert this minimal code (Xyz should be adapted ; the constructor arguments should be checked)
package mscp.gwt.Xyz.client;
 
import mscp.gwtClient.anim; 
import com.google.gwt.event.dom.client.MouseDownEvent; 
import com.google.gwt.event.dom.client.MouseMoveEvent; 
import com.google.gwt.user.client.ui.*; 
public final class GwtXyz extends anim {

public GwtXyz() {super("Xyz","Gwt Xyz",100,1.6,true);}
@Override
public void butEvent(MouseDownEvent arg0) {}

@Override
public void butEvent(MouseMoveEvent arg0) {}

@Override
public void draw() {}

@Override
public void drawBackground() {}

@Override
public void gwtInit() {}

@Override
public void onCanvasKey(char arg0) {}
@Override
public void onKeyUp(TextBox arg0, String arg1) {}

@Override
public void update() {}

@Override
public void onClick(ButtonBase source) {}

@Override
public void onChange(ListBox source) {}

@Override
public void rpcUpdate(String answer, String cmd, String param) {}

@Override
public void rpcUpdate(String[] answer, String cmd, String param) {}

@Override
public void rpcUpdate(int[] answer, String cmd, String param) {}

@Override
public void rpcUpdate(byte[] answer, String cmd, String param) {}

}

  • modify the xml file located in the project in src/mscp.gwt.xyz/GwtXyz.gwt.xml . This file should contain more inherits blocks
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='gwtxyz'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>
  <inherits name="com.google.gwt.logging.Logging"/>
  <set-property name="gwt.logging.logLevel" value="INFO"/>
  <set-property name="gwt.logging.enabled" value="TRUE"/>
  <set-property name="gwt.logging.consoleHandler" value="ENABLED"/>
  <set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
  <set-property name="gwt.logging.developmentModeHandler" value="ENABLED" />
  <!-- Other module inherits                                      -->
  <inherits name='mscp.gwtShared'/>
  <inherits name='mscp.gwtClient'/>
  <inherits name='mscp.uni'/>
  
  <!-- Specify the app entry point class.                         -->
  <entry-point class='mscp.gwt.M3M.client.GwtM3M'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>
</module>

Build Path

  • Modify the build path: Build Path/Link Source ... select jnb/uniLib/src as source dir and name it srcUni.
  • Modify the build path: Build Path/Link Source ... select jnb/gwtLibAll/src as source dir and name it srcGwt
  • [ Modify the build path: Build Path/Link Source ... select jnb/uniAlexLib/src as source dir and name it srcUniAlexLib ]

(NECESSARY!) 

HTML & XML

  • Modify the war/GwtXyz.html file : the <body> section should be empty. The following is enough (lowercase needed for the cache.js def)
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="GwtApp.css">
<title>Matscape Web App Xyz</title>
<script type="text/javascript" language="javascript" src="gwtxyz/gwtxyz.nocache.js"></script>
</head>
<body>...Loading...</body>
</html>

modify the name greetingServiceImpl.java -> svcImpl.java (server side source)

put this code (minimal, empty) in the svcImpl.java sources:

package mscp.gwt.Xyz.server;
import mscp.gwtServer.svcImpl0;

/**
* The server-side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public final class svcImpl extends svcImpl0 implements ServletContextListener {

<span style="line-height: 1.5em; font-family: sans-serif; font-size: 13.28px;">public String[] answerStrings(String user,String cmd,String param) {return(null);}
public int[] answerInts (String user,String cmd,String param) {return(null);}
public byte[] answerBytes (String user,String cmd,String param) {return(null);}
public String answerString (String user,String cmd,String param) {return(null);}
public void contextDestroyed(ServletContextEvent arg0) {}
public void contextInitialized(ServletContextEvent arg0) {}

}
</span>

remove thre greeting....java (client side source)

modify  war/WEB-INF/web.xml accordingly

Logging

Logging on both side (client and server) may be useful to identify and correct source problems.

These elements are necessary to enable logging:

  • use method app.logg() from the anim subclass instance
  • modify war/WEB-INF/web.xml file, adding these lines (if the last part is omitted, the servlet context listener methods will be IGNORED).
<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>/gwtxyz/remote_logging</url-pattern> </servlet-mapping> 
<listener>
<listener-class>mscp.gwt.xyz.server.svcImpl</listener-class>
</listener>
  • modify GwtApp.xml module file, inserting this logging directive block
<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.logLevel" value="INFO"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.consoleHandler" value="ENABLED"/>
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />

Notes

Some modif listed above require to fully restart the project...

Checking the project consistency (super dev mode) is recommended after some steps

Application data

For an application whose key is Xyz (for instanca 'App', 'Alex' 'PBP', all data is stored on the server side, on the directory /media/Shared/webApp/db/Xyz .

The relevant java sources are ug.java, gwtFile.java and more generally the server side package mscp.gwtServer (general) and mscp.gwt.xyz.server (project specific).

Library Summary Slide

GWT Lib structure.png
GWT Lib structure.png



Deployment process

The following steps should be carefully followed:

  1. (eclipse) increase version number in ug.java
  2. (bash) close all fossil deltas (see command fo)
  3. (bash) fossil backup (fo ba)
  4. (eclipse) rebuild dist/jar file with jardesc file (for involved gwt projects) (double-clicking gwtproject/dist/gwtproject.jardesc)
  5. (eclipse) google project compile (for involved gwt projects) (runnig dvp projects should be stopped during the compilation) (may take ~60 sec)
  6. (bash, dvp machine) jnr -r (this puts several file in ~/jnrd - these files to be used by jnr (to run programs with bash, and also for the tomcat deployment (see next step))
  7. (bash, deployment machine(s) with tomcat) gwt -d XXX (on tomcat servers)
  8. (browser) the deployed app(s) may then be checked on various servers from home.gonze.org (servers select and app select) (the test may be performed from any browser on any PC).


Use modes

Three use mode are defined. The running program is aware of the current use mode.

Development mode "DEV"

The server is 127.0.0.1. Server running within eclipse. OK for access to local network ressources. Nashorn is NOT runing on server.

IUO mode "IUO"

The server is gonze.eu (MMU). Server running from tomcat. OK for access to local network ressources. Nashorn runing on server,

Production mode "PROD"

The server is gonze.org (MMA). Server running from tomcat. No access to local network ressources. Nashorn runing on server,

Blank page problem

Sometimes (probably when a deployement fails), the webapp page is simply a blank page.

It is not clear how this blank page was generated by Tomcat/Catalina.

In this case the only solution is not on the server side, but on the client side: it is necessary to clear the browswer cache, because otherwise the browser continues to use the cached empty page,

Tomcat configuration

Here is described the tomcat configuration.

This is applicable to tomcat 8.0.36.

Tomcat is installed under /opt/tomcat .

The deployment of tomcat is realized thru systemctl. The key config file is /etc/systemd/system/tomcat.service. In this file, most options are standard, but the JVM memory settings may be increased:

  1. Environment='CATALINA_OPTS=-Xms4000m -Xmx4000m -server -XX:+UseParallelGC'

It is also necessary to adapt /opt/tomcat/conf/tomcat-users.xml, adding/adapting these lines

  1. <role rolename="manager-gui"/>
  2. <user username="pge" password="xxxxx" roles="manager-gui"/>

The autodeploy / autorelod question is normally handled by the gwt bash processig (without having to tune anything in tomcat's config).

The tomcat service (daemon) behaviour may be checked using

  1. (bash) sc
  2. (bash) systemctl status tomcat.service