Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "RAP/FAQ"

< RAP
m (No context available outside of the request service lifecycle)
m (Problems using Import-Package header: -- Link changed (code9 > eclipsesource), the same post but with user discussion)
Line 121: Line 121:
  
 
=== Problems using Import-Package header ===
 
=== Problems using Import-Package header ===
Since RAP 1.1 the workbench introduced a concept of so-called "split packages". This is a way of OSGi to have virtual packages which are physically splitted across several bundles. See [http://code9.com/2008/08/22/tip-split-packages-and-visibility/ this post] and the OSGi 4.1 specification (§3.13.3) for more informations about split packages.
+
Since RAP 1.1 the workbench introduced a concept of so-called "split packages". This is a way of OSGi to have virtual packages which are physically splitted across several bundles. See [http://eclipsesource.com/blogs/2008/08/22/tip-split-packages-and-visibility/ this post] and the OSGi 4.1 specification (§3.13.3) for more informations about split packages.
  
 
A common problem with them is that a split-package is only resolved when there is at least one additional split part available during runtime. As the RAP infrastrcuture only contains the workbench bundle at the moment this constrain is not met. In RCP world you often have the <code>org.eclipse.ui.ide</code> bundle available which contributes to these split packages and let Equinox resolve the constrains.
 
A common problem with them is that a split-package is only resolved when there is at least one additional split part available during runtime. As the RAP infrastrcuture only contains the workbench bundle at the moment this constrain is not met. In RCP world you often have the <code>org.eclipse.ui.ide</code> bundle available which contributes to these split packages and let Equinox resolve the constrains.

Revision as of 04:05, 6 March 2009

This FAQ is still developing. Please also scan the RAP newsgroup archives for answers.

Getting Started

I found a bug in RAP. Where should I report it?

The best way to report a problem or request a new feature in RAP is to use the Bugzilla system. Please follow the instructions in RAP Bug Reporting Howto when submitting a bug report. More details are provided on the RAP Project Bugs page.

Writing RAP Applications

How to create a fullscreen application

  • use the style-bit SWT.NO_TRIM before creating the Shell. This will remove the title-bar, the minimize/maximize/close buttons and the ability for manually resizing the window.
  • overwrite the WorkbenchWindowAdvisor.postWindowCreate() method. Here we set the state of the Shell to maximized.
  • optional: depending on the requirements and complexity of our application it may be desirable to hide the menu bar by calling getWindowConfigurer().setShowMenuBar( false ). This is usually a good choice for small applications where the menu bar may not be needed.
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
 
  // ...
 
 public void preWindowOpen() {
   // ...
   getWindowConfigurer().setShellStyle( SWT.NO_TRIM );
   getWindowConfigurer().setShowMenuBar( false );
 }
 
 public void postWindowCreate() {
   Shell shell = getWindowConfigurer().getWindow().getShell();
   shell.setMaximized( true );
 }
}

Take a look [1] for a more detailed discussion of the topic.

How do I add an applet / flash / an existing Javascript libary

  • A very simplistic approach is to create a html page (or a servlet) containing your applet / flash / JS. You can simply use the browser widget to load that page within your application.
  • A tighter integration can be achieved by developing a custom widget as explained here (integrating GMap): custom widget tutorial

How to access the request parameters?

Let's suppose that the request URI looks like the following:

   http://www.example.com:8080/rap?startup=foo&var1=value1&var2=value2

To snippet below will retrieve the values of request parameters var1 and var2.

   HttpServletRequest request = RWT.getRequest();
   String var1 = request.getParameter( "var1" );
   String var2 = request.getParameter( "var2" );

How to access the HTTP session / session store?

In RAP, the sessoin store is the preferred way to store information in the session context. However it also provides access to the HTTP session (see the code below). For working with session singletons, please use the SessinSingletonBase class.

Access the HTTP session / session store from the UI thread: HttpSession session = RWT.getSessionStore().getHttpSession();

Access the HTTP session / session store from a background thread:

 final Display display = new Display();
 final Runnable bgRunnable = new Runnable() {
   public void run() {
     UICallBack.runNonUIThreadWithFakeContext( display, new Runnable() {
       public void run() {
         Object someValue = RWT.getSessionStore().getAttribute( "myAtt" );
         System.out.println( someValue );
         // access the HTTP session
         RWT.getSessionStore().getHttpSession();
       }
     } );
   }
 };
 Shell shell = new Shell( display );
 Button button = new Button( shell, SWT.PUSH );
 button.setText( "Start Background Thread" );
 button.addSelectionListener( new SelectionAdapter() {
   public void widgetSelected( final SelectionEvent evt ) {
     RWT.getSessionStore().setAttribute( "myAtt", "someValue" );
     Thread thread = new Thread( bgRunnable );
     thread.setDaemon( true );
     thread.start();
   }
 } );

No context available outside of the request service lifecycle

Why am I getting the exception java.lang.IllegalStateException: No context available outside of the request service lifecycle.?

Your code tries to access session-information but isn't run from the UI thread (the only thread that has a session context associated by default).

The soltion is to wrap your code in a Runnable and have it executed by UICallBack#runNonUIThreadWithFakeContext().

Please also see this thread: [2]

How to integrate the Eclipse Help System in a RAP application?

An example of how to integrate the Eclipse Help webapplication org.eclipse.help.webapp into a RAP application is provided here File:Org.eclipse.rap.help.integration.zip.

After importing the example project, the following plugins have to be added, since they are not included in the RAP target:

  • javax.servlet.jsp
  • org.apache.commons.el
  • org.apache.jasper
  • org.apache.lucene.analysis
  • org.apache.lucene
  • org.eclipse.equinox.jsp.jasper.registry
  • org.eclipse.equinox.jsp.jasper
  • org.eclipse.help.appserver
  • org.eclipse.help.base
  • org.eclipse.help.webapp
  • org.eclipse.help

The plug-ins mentioned above should be taken from a "suitable" Eclipse installation. Currently (RAP 1.1) this is version 3.4.

Please note that the included launch configuration must be used. It conatins the -Dorg.eclipse.equinox.http.jetty.other.info=org.eclipse.help VM argument. Furthermore, the launch config assumes that the "RAP plug-ins" (...workbench etc.) are in your workspace. The target only contains the "Base plug-ins" (...equinox, ..core.runtime). In case your setup differs, you will need to adjust it.

Deployment

Problems using Import-Package header

Since RAP 1.1 the workbench introduced a concept of so-called "split packages". This is a way of OSGi to have virtual packages which are physically splitted across several bundles. See this post and the OSGi 4.1 specification (§3.13.3) for more informations about split packages.

A common problem with them is that a split-package is only resolved when there is at least one additional split part available during runtime. As the RAP infrastrcuture only contains the workbench bundle at the moment this constrain is not met. In RCP world you often have the org.eclipse.ui.ide bundle available which contributes to these split packages and let Equinox resolve the constrains.

In order to work around this problem you are able to import only a certain part of the package (the part of the workbench in our example). You just need to extend your Import-Package declaration with the split attribute as shown in the following MANIFEST.MF fragment:

Manifest-Version: 1.0
...
Import-Package: org.eclipse.ui; ui.workbench="split",
org.eclipse.ui.part; ui.workbench="split"

The ui.workbench="split" directive tells Equinox to use only the "ui.workbench" part of this split package.

Exported .war does not work

The application is working at development time, but when after exporting it, the web application does not work. Check the following:

  • Check your build.properties
    • are you exporting the plugin.xml?
    • are all libraries you are using in the plugin.jars?
    • Tip: As PDE build sometimes swallows error messages try exporting your feature with "Deployable feature" export, this may turn up error messages
  • Enable the osgi console by adding this init-param to the web.xml:
<init-param>
  <param-name>commandline</param-name>
  <param-value>-console</param-value> 
</init-param>
    • you may want to add a port after -console in unix environments, you can then telnet to the osgi console
    • type ss in the console and see if all bundles are started. If not try starting them with "start <bundle-id>"
    • the stack traces may hint to what is missing
  • Make sure that the WAR does not contain javax.servlet or org.eclipse.update.configurator bundles. In the plug-in maniferst the javax.servlet should be listed in the "Import-Package" section, not in "Require-Bundle".
  • The WAR contains compile errors. You will probably find a zip archive somewhere in your output folder. It contains log files with the compiler output.
  • Start with a working example: rapdemo.war and integrate your plugins

How do I make remote calls to EJB's deployed on Jboss 4.x AS

This is not a solution for calling local interface EJB's (I wasn't able to do it :( ), neither for EJB3 specification (didn't tried yet)

Nevertheless is more useful to make remote calls as the RAP application and the JBoss AS could be on separate machines (or will be sometime in the application life-cycle)

  • prepare a jar with EJB's interfaces which you are about to call from RAP (I think here you may use it wrapped as a bundle if you want to separate it from your application bundle)
  • put the jar in the application runtime classpath or add it as a dependency plugin if you use it as a bundle
  • add the following jar's from the jboss installation folder in the application runtime classpath : jboss.jar, jboss-remoting.jar, jboss-serialization.jar, jbosssx.jar, jboss-transaction.jar, jnpserver.jar

Here's an example code for calling the EJB's remote interface :

Hashtable<String, String> props = new Hashtable<String, String>();
props.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
props.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
props.put( Context.PROVIDER_URL, "jnp://localhost:1099" ); // here you put your JBoss AS server's address
Context ctx = null;
try {
  ctx = new InitialContext( props );
} catch( NamingException e ) {
  throw new RuntimeException( "fail to get initial context", e );
}
Object obj = null;
try {
  obj = ctx.lookup( "Test" ); //The jndi ejbs name is Test
} catch( NamingException e ) {
  throw new RuntimeException( "could not obtain test home interface", e );
}
TestHome home = ( TestHome )PortableRemoteObject.narrow( obj, TestHome.class );
try {
  testService = home.create();
} catch( CreateException e ) {
  throw new RuntimeException( "could not create test remote interface", e );			
} catch( RemoteException e ) {
  throw new RuntimeException( "remote exception when creating test remote interface", e );
}
try {
  testService.callSomeBusinessMethod(...);
} catch( RemoteException e ) {
  throw new RuntimeException( "remote exception when calling business method", e );
}

How do I use a RWT standalone application in Tomcat

To use the RWT standalone application in Tomcat follow the steps below:

  • Create a new Java project.
  • In the project create the folders:
    • "WEB-INF"
    • "WEB-INF/lib"
    • "WEB-INF/classes"
    • "WEB-INF/conf"
  • In "WEB-INF" create a file web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  version="2.4">
 
  <display-name>Welcome to RWT</display-name>
  <description>Welcome to RWT</description>
 
  <context-param>
    <param-name>org.eclipse.rwt.entryPoints</param-name>
    <param-value>org.eclipse.rap.helloworld.HelloWorld</param-value>
  </context-param>
 
  <listener>
    <listener-class>org.eclipse.rwt.internal.engine.RWTServletContextListener</listener-class>
  </listener>
 
  <servlet>
    <servlet-name>rapServlet</servlet-name>
    <servlet-class>org.eclipse.rwt.internal.engine.RWTDelegate</servlet-class>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>rapServlet</servlet-name>
    <url-pattern>/main</url-pattern>
  </servlet-mapping>
</web-app>
  • You can use different features (branding + theming), that normally are done with extension points by specifying some variables.

This is optional:

<context-param>
  <param-name>org.eclipse.rwt.themes</param-name>
  <param-value>useradmin#theme/theme.properties</param-value>
</context-param>
 
<context-param>
  <param-name>org.eclipse.rwt.brandings</param-name>
  <param-value>rap.RAPUseradminBranding</param-value>
</context-param>
  • In "WEB-INF\conf" create a file "w4t.xml":
<?xml version="1.0" encoding="UTF-8"?>
<w4t:application xmlns:w4t="http://w4toolkit.com/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://w4toolkit.com/ w4t.xsd ">
  <initialisation>
    <lifecycle>org.eclipse.rwt.internal.lifecycle.RWTLifeCycle</lifecycle>
  </initialisation>
</w4t:application>
  • Copy the folloing jars from RAP in the WEB-INF/lib folder:
    • org.eclipse.rap.rwt
    • org.eclipse.rap.q07
  • In case you want to make use of JFace, you also need to add these jars
    • org.eclipse.core.commands
    • org.eclipse.equinox.common
    • org.eclipse.rap.jface
  • Add these jars to the project build path as external jars.
  • Change the project output directory to "WEB-INF/classes".
  • Use a normal implementation of IEntryPoint#createUI() - HelloWorld.java:
package org.eclipse.rap.helloworld;
 
import org.eclipse.rwt.lifecycle.IEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
 
public class HelloWorld implements IEntryPoint {
 
  public int createUI() {       
    Display display = new Display();
    Shell shell = new Shell( display );
    Label label = new Label( shell, SWT.NONE );
    label.setText( "Hello RAP World" );
    label.setSize( 80, 20 );
    shell.setSize( 500, 400 );        
    shell.open();
    while( !shell.isDisposed() ) {
      if( !display.readAndDispatch() )
        display.sleep();
    }
    return 0;
  }
}
  • ZIP the the "WEB-INF" directory (including the directory) as "RWT_Standalone.war".
  • Deploy the "RWT_Standalone.war" in Tomcat.
  • Start the standalone RWT application from:
http://<host>:<port>/RWT_Standalone/main
  • If you get an IllegalArgumentException or a ClassNotFoundException after deploying your application, please check first the contents of your WAR file. Maybe it doesn't contain all class files.

Why are there encoding issues after deplying my RAP application as a WAR?

The pde.exportFeatures Ant task uses the encoding specified in file.encoding system property, which might not match the encoding of your source files. You can change this behaviour by explicitly defining the encoding used in pde.exportFeatures task. Just identify the plugin, which contains the strings with non-ASCII characters, and add javacDefaultEncoding property to his build.properties file.

The following example sets the encoding to utf-8, but you should specify whatever encoding your source files are using:

  javacDefaultEncoding.. = UTF-8

Reference: Feature and Plug-in Build Configuration Properties in the Plug-in Development Environment Guide.

I cannot access resource/image after deploying as a WAR

The image/resource is visible when running from within the IDE but is missing after deploying.

All resources must be explicitly listed in the bin.includes variable or they will not be included in the binary distribution of your plug-in. Please verify your build.properties files to ensure that your plug-ins are not missing any entries for images and other resource files.

Branding and Theming

How can I use an image in the branding body?

Using a user-defined resource inside of a RAP application requires registering it in some way. In case of images used inside the branding body, this can be done declaratively using the org.eclipse.equinox.http.registry.resources extension.

Assume you have a folder branding in the root of your plugin, containing an image called loading.gif. Add the following code to your plugin.xml:

<extension point="org.eclipse.equinox.http.registry.resources">
    <resource
        alias="loading.gif"
        base-name="branding/loading.gif">
    </resource>
</extension>

This maps the provided resource base name to the given alias name and makes it available for use.

Access the image in your branding body by referring to the alias name:

...
    <img src="loading.gif" border="0" />
...

Why doesn't RAP simply use CSS for styling, such as e.g. GWT?

In GWT for example, every widget has a configurable style name that is rendered as class attribute. Styling is done by adding a CSS file to the target HTML document. Although this is a simple technique, it does not work out for RAP for a number of reasons:

1. One of the main objectives of RAP is to prevent vendor lock-in by allowing for exchangeable client implementations. Although our current client-side technique is based on JavaScript, there are completely different technologies out there that might be interesting candidates for RAP clients (GWT, Flex, Silverlight ...). Not all of those technologies can necessarily deal with CSS.

2. In RAP, all layouts are computed on the server side, thus the server also needs to know about any variable dimensions like paddings and borders. This is not possible if a style sheet is applied only on the client side.

3. Due to browser bugs and differences, writing cross-browser CSS code is a complex task. Client technologies may work around those browser issues. In fact, the qooxdoo library does so.

How can I change the favicon / title of my RAP app?

With the help of RAPs branding features you're able to define several (visual) aspects of your RAP application. This includes for example the page title which is shown in the browser, the favicon or the theme to be used for the application. See the Branding section of the RAP Developer guide for details.

Back to the top