Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Vaadin 7 application server IP and port?

Tags:

java

vaadin7

How can I get the protocol, IP and port of the app server running my Vaadin webapp? I'm using Vaadin 7.

In vaadin 6 I doing in this way, but not work in vaadin 7:

String server = ((WebApplicationContext) this.getContext()).getHttpSession().getServletContext().getServerInfo();

java.net.URL url = this.getURL();
String s = url.getHost()+":"+url.getPort()+url.getPath();
like image 662
Jorge Infante Osorio Avatar asked Feb 14 '14 19:02

Jorge Infante Osorio


3 Answers

as for the application path part, to get the real application directory and not the browser request path, use VaadinServlet.getCurrent().getServletContext().getContextPath()

like image 120
Chalif Storch Avatar answered Oct 24 '22 00:10

Chalif Storch


System.out.println(UI.getCurrent().getPage().getLocation().getHost());
System.out.println(UI.getCurrent().getPage().getLocation().getPath());
System.out.println(UI.getCurrent().getPage().getLocation().getPort());
like image 14
Vikrant Thakur Avatar answered Oct 23 '22 23:10

Vikrant Thakur


I do it like this:

String basePath = Page.getCurrent().getLocation().getScheme() + ":" +
                  Page.getCurrent().getLocation().getSchemeSpecificPart()
like image 7
chicxurug Avatar answered Oct 24 '22 00:10

chicxurug