Interceptor called twice
sanghakanwar Jul 9, 2008 12:35 PMHi,
I have written a interceptor for my webservices which is exposed as a stateless EJB endpoint. All works fine , but in the logs i see that the interceptor is getting called twice !
My interceptor class -
public class CheckStateInterceptorForSubscriberProfile {
Logger log = Logger.getLogger(CheckStateInterceptorForGlobalProfile.class);
private ManagementStateManager appServerStateManager;
@AroundInvoke
public Object test(InvocationContext invocation) throws SubscriberServiceException,Exception {
appServerStateManager = new ManagementStateManager();
log.info("Inside Interceptor for EJB webservice method invocation");
// Populate the message string with the correct state of the app server (Lock,OSS..)
String message = "Server is not in a valid state ! It is either in a LOCKED/SHUTDOWN/STANDBY/OSS state. Please " +
"try after some time.";
// Method call to get the state of the app server
if(appServerStateManager.isInValidState()){
log.info("AppServer is in a valid state");
return invocation.proceed();
}
else{
log.info("AppServer is in a in-valid state");
throw new SubscriberServiceException(message,ExceptionUtil.newSPSError(ExceptionCode.INVALID_SESSION,message));
}
}
}
and my webservice endpoint ejb -
@WebService(endpointInterface = "com.xyz.sps.services.profile.GlobalProfileService", portName = "GlobalProfileService", serviceName = "GlobalProfileService")
@Stateless(name = "GlobalProfileService", mappedName = "GlobalProfileService")
@Local(GlobalProfileService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
@Interceptors(CheckStateInterceptorForGlobalProfile.class)
public class GlobalProfileServiceImpl extends AbstractServiceImpl
implements GlobalProfileService {
private ProfileDAO profileDAO;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed({"spsadmin"})
public void deleteGlobalProfile(ProfileReference profileReference) throws ProfileServiceException {
boolean success = false;
try {
validate(profileReference);
profileDAO.deleteGlobalProfile(new DeleteGlobalProfileParams(profileReference));
success = true;
} catch (ProfileServiceException profileServiceEx) {
throw profileServiceEx;
} catch (Throwable thrown) {
throw newProfileServiceException(
ExceptionCode.PROFILE_DELETE_FAILED,
"Failed to delete profile by reference " + profileReference,
thrown);
} finally {
if (!success) {
sessionContext.setRollbackOnly();
}
}
}