In our application we have couple of webservices.i need to get the userids(means who has loged in and webservice name) for auditing purpose i need to store. Could anyone suggest which will be either filter chain or Interceptors and how to get the webservice name.
Asked
Active
Viewed 323 times
1 Answers
1
You can use PreSecurityInterceptor for doing this ,request from client will first goto it and there you can log the data in db or file .
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
/**
* This interceptor verify the method name and log the details
* */
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
//import org.jboss.resteasy.core.ResourceMethodInvoker;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
@Provider
@ServerInterceptor
public class PreSecurityInterceptor implements PreProcessInterceptor {
@Context HttpServletRequest req;
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException {
System.out.println("********************************************* pre process *****************************");
System.out.println(new Date() + " Method : " + method.getMethod().getName() + " being called from "
+ req.getRemoteHost()+":"+req.getLocalPort()+": Remote Port "+req.getRemotePort());
if ( "defaultMethod".equalsIgnoreCase(method.getMethod().getName())) {
return null; // normal flow continues
} else {
System.out.println(new Date() + " Method : " + method.getMethod().getName() + " Precondition failed ");
return (ServerResponse) Response
.status(Response.Status.PRECONDITION_FAILED).entity("invalid method details provided !!").build();
}
}
}

gladiator
- 1,249
- 8
- 23
-
It Works Thanks Ravikant – Mahesh Nov 04 '16 at 19:32