How can I access one Eclipse RAP entry point from another?

I have an Eclipse RAP 2.3 application with two entry points like /first

and /second

. The GUI of the first entry point has a button with which I would like to open the second entry point in a new browser tab. The event handler for this button is currently

UrlLauncher launcher = RWT.getClient().getService( UrlLauncher.class );
launcher.openURL( "/second");

      

This no longer works when the application is deployed as myapp.war

on the Tomcat web server (then it should be /myapp/second

).

My questions:

  • What's the best way to define the url to open in an event handler?
  • Should I get HttpServletRequest

    , get the context path and hence some string manipulation?
  • RWT.getRequest()

    Is it safe to call at this point ?

Update

According to Rüdiger's comment, I can get the context path in two different ways.

  • First approach -

    RWT.getRequest().getContextPath();
    
          

    where RWT.getRequest()

    documented with

    This method is not recommended

  • Second, I could get it with

    ApplicationContextImpl ac = (ApplicationContextImpl) RWT.getApplicationContext();
    String contextPath = ac.getServletContext().getContextPath();
    
          

    where the IDE displays a warning

    Fault Tolerant Access: The ApplicationContextImpl type is not available due to a required library restriction ... \ org.eclipse.rap.rwt_2.3.2.20150128-1013.jar

    Despite this warning, it still works when deploying a WAR file with OSGi packages for Tomcat.

So in both cases there is some kind of warning that makes the solutions look like workarounds.

+3


source to share


1 answer


Usage RWT.getRequest()

is discouraged because generally RWT shields you from lower level servlet APIs and certain direct interactions with the request can even affect the RWT lifecycle and give funny responses.

In your case, it would be safe to access ServletContext

via RWT.getRequest()

, I recommend using

RWT.getUISession( display ).getHttpSession().getServletContext();

      



to access the servlet context.

The second approach addresses internal classes that are not part of the public API and therefore should not be used. Available classes may change or be (re) moved in the future without further notice and break your application.

+1


source







All Articles