Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Any incoming GET request that has the URL of "/welcome" is handled by WelcomeMessage class's returnWelcomeMessage() method. A string is returned that represents the response body and is sent as the response payload in a HTTP 200 status response.

Using a javax.ws.rs.core.Response

In the previous GET resource method example, the response body is returned as a String. If a more complex response is requiredfor example, additional HTTP response headers or a different status code, a javax.ws.rs.core.Response should be used as the Java method's return type. By building a Response object, additional information can be returned to the client.

...

Code Block
titleAdministratorResourceWithSubresourceMethod
borderStylesolid
@Path("/administrator")
public class Administrator{

    @GET
    public String findUserInfo() {
        String userInfo = null;
        /* build user info */
        return userInfo;
    }

    @GET
    @Path("/name")
    public String getJustUserName() {
        String userName = "";
        /* get the user name */
        return userName;
    }

    @GET
    @Path("/id")
    public String getUserId() {
        String userId = "";
        /* get the user id */
        return userId;
    }
}

A An HTTP URL request to the "/administrator" would resolve to Administrator#findUserInfo(). A HTTP URL request to "/administrator/name" would invoke the Administrator#getJustUserName() method. Finally a HTTP URL request to "/administrator/id" would resolve to Administrator#getUserId().

Anchor
SubresourceLocator
SubresourceLocator

Using Subresource Locators (@Path on Java method)

In more complicated scenarios, subresource locators are needed. Subresource locators are particularly useful when requests must be further resolved by other objects. Subresource locators are Java methods which have only an @Path annotation. They are different than subresource methods because they do not have any HTTP method annotation on them.

...