Skip to content

Instantly share code, notes, and snippets.

View abhirockzz's full-sized avatar
👋
fmt.Println(hello, world!)

Abhishek Gupta abhirockzz

👋
fmt.Println(hello, world!)
View GitHub Profile
@abhirockzz
abhirockzz / gist:d05db7a2f6911cd22cad
Created December 4, 2014 18:06
JAX-RS parameters
@Path("{k}={v}")
@GET
public void test(@PathParam("k") String key, @PathParam("v") String val){
System.out.println("Key == "+ key);
System.out.println("Val == "+ val);
}
@abhirockzz
abhirockzz / MethodInterceptorExample.java
Last active August 29, 2015 14:12
Method Interceptors
public class MethodInterceptor{
@AroundInvoke
public Object interceptorMethod(InvocationContext ictx) throws Exception{
//logic goes here
}
}
@Stateless
public class AnEJB{
@Interceptors(MethodInterceptor.class)
@abhirockzz
abhirockzz / ConstructorInterceptorExample.java
Last active August 29, 2015 14:12
Lifecycle Callback interceptors @AroundConstruct
public class ConstructorInterceptor{
@AroundConstruct
public Object interceptorMethod(InvocationContext ictx) throws Exception{
//logic goes here
}
}
public class APOJO{
@Interceptors(ConstructorInterceptor.class)
public APOJO(){
public class PostConstructInterceptor{
@PostConstruct
public void interceptorMethod(InvocationContext ictx) throws Exception{
//logic goes here
}
}
@Interceptors(PostConstructInterceptor.class)
public class APOJO{
@PostConstruct
@InterceptorBinding
@Target({TYPE, METHOD, CONSTRUCTOR})
@Retention(RUNTIME)
public @interface @Auditable {
}
@Auditable
@Interceptor
public class AuditInterceptor {
@Provider
public class LoggingFilter implements ContainerRequestFilter{
public void filter(ContainerRequestContext requestContext){
//logic here - logging etc
}
}
@Path("info")
@GET
@Produces("application/json")
public Response getTweeterInfo(@QueryParam("tweeter") String tweeterId){
//fetch details for abhi_tweeter
}
@Path("info/{tweeter}")
@GET
@Produces("application/json")
@Path("info/{tweeter}")
@GET
@Produces("application/json")
public Response getTweeterInfo(@HeaderParam("referrer") String refURL, @CookieParam("id") String id){
//use the injected values of refURL, id from header attribute called header and Cookie named id respectively
}
@Path("info/{tweeter}")
@POST
@Consumes("application/x-www-form-urlencoded")
public class ClientRequestBean{
@FormParam("tweeter_id")
private String id;
@FormParam("tweeter_email")
private String email;
@HeaderParam("referrer")
private String referrer;
@Provider
public CustomReaderInterceptor implements ReaderInterceptor{
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric){
//use the methods from the ReaderInterceptorContext
ric.proceed();
//invoke the proceed method to get things moving!
}
}