简体   繁体   中英

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

I have an Eclipse RAP 2.3 application with two entry points, say /first and /second . In the GUI of the first entry point, there is a button with which I would like to open the second entry point in a new browser tab. The event handler of that button is currently

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

This already doesn't work when the application is deployed as myapp.war in a Tomcat web server (should then be /myapp/second ).

My questions:

  • What's the best way to determine the URL to open within the event handler?
  • Do I have to fetch the HttpServletRequest , get the context path and so some string manipulation?
  • Is it actually safe to call RWT.getRequest() at this point?

Update

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

  1. The first approach is

     RWT.getRequest().getContextPath(); 

    where RWT.getRequest() is documented with

    This method is not recommended

  2. Secondly, I could obtain it with

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

    where the IDE displays the warning

    Discouraged access: The type ApplicationContextImpl is not accessible due to restriction on required library ...\\org.eclipse.rap.rwt_2.3.2.20150128-1013.jar

    Despite the warning, it still works when deploying a WAR file with OSGi bundles to Tomcat.

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

Using RWT.getRequest() is not recommended because usually RWT would shield you from the lower-level servlet API and certain direct interactions with the request could even interfere with RWTs life cycle and yield funny responses.

While in your case it would be safe to access the ServletContext via RWT.getRequest() , I recommend to use

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

to access the servlet context.

The second approach accesses internal classes that aren't part of the public API and therefore shouldn't be use. The accessed classes may change or be (re)moved in the future without further notice and break your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM