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("/feed") | |
public class RESTFeed { | |
@Inject | |
Event<String> event; | |
@POST | |
@Consumes(MediaType.TEXT_PLAIN) | |
public void push(String msg) { | |
event.fire(msg); |
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
public void onMsg(@Observes String msg) { | |
//different WS enpoint instance - notice the hash code value in the server log | |
System.out.println("WS End point class ID -- " + this.hashCode()); | |
try { | |
client.getBasicRemote().sendText(msg); | |
} catch (IOException ex) { | |
Logger.getLogger(ServerEndpoint.class.getName()).log(Level.SEVERE, null, ex); |
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
private static Set<Session> peers = Collections.synchronizedSet(new HashSet()); |
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
//This is valid | |
@Stateless | |
@Dependent | |
public class EJB1 { | |
@PostConstruct | |
public void init(){ | |
System.out.println(EJB1.class.getName() + " constructed successfully on "+ new Date().toString()); | |
} | |
} |
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
//This is legal | |
@Singleton | |
@Startup | |
@ApplicationScoped | |
public class Singleton1 { | |
@PostConstruct | |
public void init(){ | |
System.out.println(Singleton1.class.getName() + " constructed successfully on "+ new Date().toString()); | |
} |
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("/testcache") | |
public class RESTfulResource { | |
@GET | |
@Produces("text/plain") | |
public Response find(){ | |
CacheControl cc = new CacheControl(); | |
cc.setMaxAge(20); | |
return Response.ok(UUID.randomUUID().toString()).cacheControl(cc).build(); | |
} | |
} |
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
@Retention(RUNTIME) | |
@Target({FIELD, PARAMETER}) | |
public @interface CachControlConfig { | |
public boolean isPrivate() default true; | |
public boolean noCache() default false; | |
public boolean noStore() default false; | |
public boolean noTransform() default true; | |
public boolean mustRevalidate() default true; | |
public boolean proxyRevalidate() default false; |
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
public class CacheControlFactory { | |
@Produces | |
public CacheControl get(InjectionPoint ip) { | |
CachControlConfig ccConfig = ip.getAnnotated().getAnnotation(CachControlConfig.class); | |
CacheControl cc = null; | |
if (ccConfig != null) { | |
cc = new CacheControl(); | |
cc.setMaxAge(ccConfig.maxAge()); |
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("/testcache") | |
public class RESTfulResource { | |
@Inject | |
@CachControlConfig(maxAge = 20) | |
CacheControl cc; | |
@GET | |
@Produces("text/plain") | |
public Response find() { | |
return Response.ok(UUID.randomUUID().toString()).cacheControl(cc).build(); |
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}") |