This file contains 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
@Path("books") | |
public class Books{ | |
@Produces("application/json") | |
@GET | |
public List<Book> findAll(){ | |
//find all books | |
} | |
@Produces("application/json") | |
@GET | |
@Path("{id}") |
This file contains 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
@Path("movies") | |
public class Books{ | |
@Produces("application/json") | |
@GET | |
public List<Movie> findAll(){ | |
//find all movies e.g. /movies/ | |
} | |
@Produces("application/json") | |
@GET | |
@Path("{name}") |
This file contains 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
@GET | |
@Produces("text/plain") | |
public void execute(@Suspended AsyncResponse response){ | |
System.out.println("Initially invoked on thread - "+ Thread.currentThread.getName() + ". This will free up soon !"); | |
new Thread(){ | |
@Override | |
public void run(){ | |
response.resume("executed asynchronously on thread - "+ Thread.currentThread.getName()); | |
} | |
}.start(); |
This file contains 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
@GET | |
@Produces("text/plain") | |
public void execute(@Suspended AsyncResponse response){ | |
System.out.println("Initially invoked on thread - "+ Thread.currentThread.getName() + ". This will free up soon !"); | |
//just having this would result in HTTP 503 after 10 seconds | |
response.setTimeout(10, TimeUnit.SECONDS); | |
//client will recieve a HTTP 408 (timeout error) after 10 seconds | |
response.setTimeoutHandler((asyncResp) -> asyncResp.resume(Response.status(Response.Status.REQUEST_TIMEOUT)).build()); | |
new Thread(() -> { | |
try { |
This file contains 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
@StatefulTimeout(15000,java.util.concurrent.TimeUnit.MILLISECONDS) | |
public class SFSB_With_Timeout{ | |
public void register(){ | |
//....business logic | |
} | |
} |
This file contains 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
@Singleton | |
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) //this is actually by default | |
public class Singleton_With_Timeout{ | |
@AccessTimeout(value = 5000, unit = java.util.concurrent.TimeUnit.MILLISECONDS) | |
@Lock(LockType.WRITE) //default configuration | |
public void find(){ | |
//... business logic | |
} | |
} |
This file contains 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
@Path("testinject") | |
public class InjectURIDetails{ | |
//localhost:8080/<root-context>/testinject/httpheaders | |
@GET | |
@Path("httpheaders") | |
public void test(@Context HttpHeaders headers){ | |
System.out.println("ALL headers -- "+ headers.getRequestHeaders().toString()); | |
System.out.println("'Accept' header -- "+ headers.getHeaderString("Accept")); | |
System.out.println("'TestCookie' value -- "+ headers.getCookies().get("TestCookie").getValue()); | |
} |
This file contains 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
@Path("testinject") | |
public class InjectURIDetails{ | |
//localhost:8080/<root-context>/testinject/uriinfo | |
@GET | |
@Path("uriinfo") | |
public void test(@Context UriInfo uriDetails){ | |
System.out.println("ALL query parameters -- "+ uriDetails.getQueryParameters().toString()); | |
System.out.println("'id' query parameter -- "+ uriDetails.getQueryParameters.get("id")); | |
System.out.println("Complete URI -- "+ uriDetails.getRequestUri()); | |
} |
This file contains 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
@Path("testinject") | |
public class InjectSecurityContext{ | |
//localhost:8080/<root-context>/testinject/securitycontext | |
@GET | |
@Path("securitycontext") | |
public void test(@Context SecurityContext secContext){ | |
System.out.println("Caller -- "+ secContext.getUserPrincipal()getName()); | |
System.out.println("Authentication Scheme -- "+ secContext.getAuthenticationScheme()); | |
System.out.println("Over HTTPS ? -- "+ secContext.isSecure()); | |
System.out.println("Belongs to 'admin' role? -- "+ secContext.isUserInRole("admin"); |
This file contains 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
@Path("email") | |
@Stateless | |
public class EmailService { | |
//pulls in default Conn Factory as per Java EE 7 | |
@Resource | |
ConnectionFactory cf; | |
//application managed | |
JMSContext ctx; |