Created
May 28, 2019 17:04
-
-
Save travisrcory/46a3727710f0882c717a3f93d98d19d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.liferay.docs.application; | |
import java.util.Collections; | |
import java.util.Set; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.QueryParam; | |
import javax.ws.rs.core.Application; | |
import org.osgi.service.component.annotations.Component; | |
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants; | |
/** | |
* @author traviscory | |
*/ | |
@Component( | |
property = { | |
JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE + "=/greetings", | |
JaxrsWhiteboardConstants.JAX_RS_NAME + "=Greetings.Rest" | |
}, | |
service = Application.class | |
) | |
public class RestApplication extends Application { | |
public Set<Object> getSingletons() { | |
return Collections.<Object>singleton(this); | |
} | |
@GET | |
@Path("/morning") | |
@Produces("text/plain") | |
public String hello() { | |
return "Good morning!"; | |
} | |
@GET | |
@Path("/morning/{name}") | |
@Produces("text/plain") | |
public String morning( | |
@PathParam("name") String name, @QueryParam("drink") String drink) { | |
String greeting = "Good Morning " + name; | |
if (drink != null) { | |
greeting += ". Would you like some " + drink + "?"; | |
} | |
return greeting; | |
} | |
@GET | |
@Produces("text/plain") | |
public String working() { | |
return "It works!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment