How do I get the base url of my server with JAX-RS? Basically I want ""http://localhost:8080/.." when the program is on localhost and "http://www.theSite.com/..." when the program is on a live server. I am using Jersey Framework.
There's nothing in the Android URI class that gives you the base URL directly- As gnuf suggests, you'd have to construct it as the protocol + getHost(). The string parsing way might be easier and let you avoid stuffing everything in a try/catch block.
JAX-RS is a Java programming language API designed to make it easy to develop applications that use the REST architecture. The JAX-RS API uses Java programming language annotations to simplify the development of RESTful web services.
Root resource classes are "plain old Java objects" (POJOs) that are either annotated with @Path or have at least one method annotated with @Path or a request method designator, such as @GET , @PUT , @POST , or @DELETE .
Yes, you may use myUri = uri.getBaseUri();
Here how you get the Uri object :
@Path("myresource")
public class MyResource{
@Context
UriInfo uri;
@GET
public String myresponse(){
URI myUri = uri.getBaseUri();
return ...
}
}
You will have plenty of informations with UriInfo. Check here the javadoc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With