3

TomEE 1.7.2, Java EE 6, Java 8

I have this JAX-RS Application:

@ApplicationPath("/api")
public class CallStatsCatcherApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        return new HashSet<Class<?>>(Arrays.asList(RestEndpoint.class));
    }
}

@ApplicationScoped
@Path("/rest")
public class RestEndpoint {
    @GET
    public String echo(@QueryParam("foo") String foo) {
        return foo;
    }
}

During startup, TomEE prints:

INFO:               GET http://localhost:8080/test-application/api/rest/      ->      String echo(String)

How can I get that URL programmatically during startup? I'd like to create a framework that advertises this URL locally on the network.

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84

2 Answers2

1

To get server adress part you can try use something like that: Java EE: how to get the URL of my application?

But if you need IP address in startup bean, you can try use:

InetAddress ip = InetAddress.getLocalHost();
String ipAddress = ip.getHostAddress();`

Another option is to use:

MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer()`

But it may be associated with the server platform and you will need to search the property.

Community
  • 1
  • 1
ostry
  • 117
  • 1
  • 2
  • 8
0

You can use the UriInfo class in conjunction with UriBuilder class to mount or create URLs using the current path.

There is similar question in stackoverflow: getting the base url...

Community
  • 1
  • 1
Silvio Lucas
  • 1,959
  • 1
  • 14
  • 11