JBoss.orgCommunity Documentation

Chapter 20. Development Proxy

Proxied access to external containersUsually GWT developement happens in hosted mode and then, later on, the GWT app is turned into a webapp (*.war) that can be deployed on a target container (app server, servlet engine). This works quiet well for closed systems that don't depend on additional resources the target container provides. A typical resource would be a DataSource for access to a relational database.

Instead of pulling these resources into the hosted mode servlet engine (jetty, read-only JNDI) or creating mock objects for any resources that cannot be run in hosted mode, we offer you a much more simple way to work with external resources: Simply proxy all requests that occur in hosted mode to an external target container:

Development Proxy

Figure 20.1. Development Proxy


The proxy is implemented a yet another servlet that you need to add to the web.xml that's being sed in hosted mode:

<servlet>
  <servlet-name>erraiProxy</servlet-name>
  <description>Errai Proxy</description>
  <servlet-class>org.jboss.errai.tools.proxy.XmlHttpProxyServlet</servlet-class>
  <init-param>
    <param-name>config.name</param-name>
    <param-value>errai-proxy.json</param-value> (1)
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>erraiProxy</servlet-name>
  <url-pattern>/app/proxy/*</url-pattern> (2)
</servlet-mapping>
  1. Proxy configuration. See details below.

  2. The proxy url pattern convetion. The bus bootstraps on this URL.

The web.xml proxy declaration contains two notable elements: A reference to the proxy configuration file and a URL pattern, where the proxy can found. While the later shouldn't be changed (the bus bootstraps on this URL), you need to change the proxy config according to your needs:

{"xhp": {
  "version": "1.1",
  "services": [
    {"id": "default",
     "url":"http://127.0.0.1:8080/my-gwt-app/in.erraiBus",
     "passthrough":true
    },]
  }
}

You would need to change the host, port and webcontext ('my-gwt-app' in this case) to reflect the location of the external container. 'passthrough' simply means that any request to 'proxy/in.erraiBus' will go to 'container/my-gwt-app/in.erraiBus'. This already indicates that you need to have the server side part of your GWT application, already running on the target container. The most simple way to achieve this, is to build a the complete webapp, deploy it and ignore the UI parts that may be available on the server.