use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class TimerWrapper method checkCallPermission.
/**
* Verify that Timer method access is allowed from this context.
* This method is static so that TimerHandle can call it even
* before it has created a TimerWrapper instance.
*/
private static void checkCallPermission() throws IllegalStateException {
// Can't store a static ref because in embedded container it can be
// changed by server restart
EjbContainerUtil ejbContainerUtil = EjbContainerUtilImpl.getInstance();
EJBTimerService timerService = EJBTimerService.getEJBTimerService();
if (timerService == null) {
throw new IllegalStateException("EJBTimerService is not available");
}
ComponentInvocation inv = ejbContainerUtil.getCurrentInvocation();
if (inv == null) {
throw new IllegalStateException("Invocation cannot be null");
}
ComponentInvocation.ComponentInvocationType invType = inv.getInvocationType();
if (invType == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
if (inv instanceof EjbInvocation) {
ComponentContext context = ((EjbInvocation) inv).context;
// Delegate check to EJB context. Let any
// IllegalStateException bubble up.
context.checkTimerServiceMethodAccess();
}
}
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class J2EEInstanceListener method handleAfterEvent.
private void handleAfterEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
Wrapper wrapper = event.getWrapper();
Context context = (Context) wrapper.getParent();
if (!(context instanceof WebModule)) {
return;
}
WebModule wm = (WebModule) context;
Object instance;
if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
instance = event.getFilter();
} else {
instance = event.getServlet();
}
if (instance == null) {
return;
}
// Emit monitoring probe event
if (instance instanceof Servlet) {
if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
wm.servletInitializedEvent(wrapper.getName());
} else if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
wm.servletDestroyedEvent(wrapper.getName());
}
}
// EE invocation context
try {
if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
injectionMgr.destroyManagedObject(instance, false);
}
} catch (InjectionException ie) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
_logger.log(Level.SEVERE, msg, ie);
}
ComponentInvocation inv = new WebComponentInvocation(wm, instance);
try {
im.postInvoke(inv);
} catch (Exception ex) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
throw new RuntimeException(msg, ex);
} finally {
if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
if (tm != null) {
tm.componentDestroyed(instance, inv);
}
} else if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
// Emit monitoring probe event
if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
ServletResponse response = event.getResponse();
int status = -1;
if (response != null && response instanceof HttpServletResponse) {
status = ((HttpServletResponse) response).getStatus();
}
wm.afterServiceEvent(wrapper.getName(), status);
}
// BEGIN IASRI# 4646060
if (im.getCurrentInvocation() == null) {
// END IASRI# 4646060
try {
// clear security context
Realm ra = context.getRealm();
if (ra != null && (ra instanceof RealmInitializer)) {
// cleanup not only securitycontext but also PolicyContext
((RealmInitializer) ra).logout();
}
} catch (Exception ex) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
_logger.log(Level.SEVERE, msg, ex);
}
if (tm != null) {
try {
if (tm.getTransaction() != null) {
tm.rollback();
}
tm.cleanTxnTimeout();
} catch (Exception ex) {
}
}
}
if (tm != null) {
tm.componentDestroyed(instance, inv);
}
}
}
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class WebContainerListener method postInvoke.
private void postInvoke(WebModule ctx) {
WebModule wm = (WebModule) ctx;
ComponentInvocation inv = new WebComponentInvocation(wm);
invocationMgr.postInvoke(inv);
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class AbstractJMSContextManager method cleanup.
// Close and remove the JMSContext instances
@PreDestroy
public synchronized void cleanup() {
ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
ComponentInvocation currentInv = invMgr.getCurrentInvocation();
for (Entry<String, JMSContextEntry> entry : contexts.entrySet()) {
JMSContextEntry contextEntry = entry.getValue();
String ipId = contextEntry.getInjectionPointId();
JMSContext context = contextEntry.getCtx();
if (context != null) {
ComponentInvocation inv = contextEntry.getComponentInvocation();
if (inv != null && currentInv != inv)
invMgr.preInvoke(inv);
try {
context.close();
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.close", "Closed JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
}
} catch (Exception e) {
logger.log(Level.SEVERE, localStrings.getLocalString("JMSContext.impl.close.failure", "Failed to close JMSContext instance associated with id {0}: {1}.", ipId, context.toString()), e);
} finally {
if (inv != null && currentInv != inv)
invMgr.postInvoke(inv);
}
}
}
contexts.clear();
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class ContextSetupProviderImpl method setup.
@Override
public ContextHandle setup(ContextHandle contextHandle) throws IllegalStateException {
if (!(contextHandle instanceof InvocationContext)) {
logger.log(Level.SEVERE, LogFacade.UNKNOWN_CONTEXT_HANDLE);
return null;
}
InvocationContext handle = (InvocationContext) contextHandle;
String appName = null;
if (handle.getInvocation() != null) {
appName = handle.getInvocation().getAppName();
}
if (appName == null && handle.getInvocation().getJNDIEnvironment() != null) {
appName = DOLUtils.getApplicationFromEnv((JndiNameEnvironment) handle.getInvocation().getJNDIEnvironment()).getName();
}
ClassLoader backupClassLoader = null;
if (appName == null) {
// try to get environment from component ID
if (handle.getInvocation().getComponentId() != null && compEnvMgr != null) {
JndiNameEnvironment currJndiEnv = compEnvMgr.getJndiNameEnvironment(handle.getInvocation().getComponentId());
if (currJndiEnv != null) {
com.sun.enterprise.deployment.Application appInfo = DOLUtils.getApplicationFromEnv(currJndiEnv);
if (appInfo != null) {
appName = appInfo.getName();
// cache JNDI environment
handle.getInvocation().setJNDIEnvironment(currJndiEnv);
backupClassLoader = appInfo.getClassLoader();
}
}
}
}
// Check whether the application component submitting the task is still running. Throw IllegalStateException if not.
if (!isApplicationEnabled(appName)) {
throw new IllegalStateException("Module " + appName + " is disabled");
}
ClassLoader resetClassLoader = null;
SecurityContext resetSecurityContext = null;
if (handle.getContextClassLoader() != null) {
resetClassLoader = Utility.setContextClassLoader(handle.getContextClassLoader());
} else if (backupClassLoader != null) {
resetClassLoader = Utility.setContextClassLoader(backupClassLoader);
}
if (handle.getSecurityContext() != null) {
resetSecurityContext = SecurityContext.getCurrent();
SecurityContext.setCurrent(handle.getSecurityContext());
}
ComponentInvocation invocation = handle.getInvocation();
if (invocation != null && !handle.isUseTransactionOfExecutionThread()) {
// Each invocation needs a ResourceTableKey that returns a unique hashCode for TransactionManager
invocation.setResourceTableKey(new PairKey(invocation.getInstance(), Thread.currentThread()));
invocationManager.preInvoke(invocation);
}
// Ensure that there is no existing transaction in the current thread
if (transactionManager != null) {
transactionManager.clearThreadTx();
}
if (requestTracing != null && requestTracing.isRequestTracingEnabled()) {
RequestTraceSpan span = constructConcurrentContextSpan(invocation);
requestTracing.startTrace(span);
}
if (stuckThreads != null) {
stuckThreads.registerThread(Thread.currentThread().getId());
}
return new InvocationContext(invocation, resetClassLoader, resetSecurityContext, handle.isUseTransactionOfExecutionThread());
}
Aggregations