/** * Creates a WorkContext for the request. * <p/> * client that is wired to it. Otherwise, it is null. * * @param header the serialized work context header * @return the work context */ @SuppressWarnings({"unchecked"}) protected WorkContext setWorkContext(byte[] header) { try { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); if (header == null || header.length == 0) { return workContext; } List<CallbackReference> stack = CallbackReferenceSerializer.deserialize(header); // add the last callback twice as it will be needed when the callback is made back through the binding if (!stack.isEmpty()) { stack.add(stack.get(stack.size() - 1)); } workContext.addCallbackReferences(stack); return workContext; } catch (IOException e) { throw new ServiceRuntimeException("Error deserializing callback references", e); } }
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { req = new HttpServletRequestWrapper(req); ClassLoader old = Thread.currentThread().getContextClassLoader(); WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); workContext.setHeader("fabric3.httpRequest", req); workContext.setHeader("fabric3.httpResponse", res); servlet.service(req, res); } catch (ServletException se) { se.printStackTrace(); throw se; } catch (IOException ie) { ie.printStackTrace(); throw ie; } catch (Throwable t) { t.printStackTrace(); throw new ServletException(t); } finally { Thread.currentThread().setContextClassLoader(old); workContext.reset(); } }
public T call() throws Exception { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); try { workContext.setSubject(subject); workContext.addHeaders(headers); workContext.addCallbackReferences(stack); return delegate.call(); } finally { workContext.reset(); } } }
Object invoke(Method method, Object[] args) throws MBeanException, ReflectionException { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); try { T instance = objectFactory.getInstance(); return method.invoke(instance, args); } catch (ObjectCreationException e) { throw new ReflectionException(e); } catch (IllegalAccessException e) { throw new AssertionError(e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); cause.printStackTrace(); if (cause instanceof Exception) { throw new MBeanException((Exception) e.getCause()); } else { throw new ReflectionException(e); } } finally { workContext.reset(); } } }
WorkContextCache.getAndResetThreadWorkContext(); ClassLoader old = Thread.currentThread().getContextClassLoader(); try {
public void destroy() throws ShutdownException { // destroy system components WorkContextCache.getAndResetThreadWorkContext(); scopeContainer.stopAllContexts(); try { repository.shutdown(); } catch (RepositoryException e) { throw new ShutdownException(e); } }
public void run() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); try { workContext.setSubject(subject); workContext.addHeaders(headers); workContext.addCallbackReferences(stack); delegate.run(); } finally { workContext.reset(); } } }
public void onLeaderElected(String name) { if (topologyService != null && !topologyService.isZoneLeader()) { // this runtime is not the leader, ignore return; } activated = true; // this runtime was elected leader, start the components synchronized (deferredContexts) { WorkContextCache.getAndResetThreadWorkContext(); for (QName deployable : deferredContexts) { try { super.startContext(deployable); } catch (GroupInitializationException e) { monitor.leaderElectionError(e); } } deferredContexts.clear(); } }
public void handle(Object event, boolean endOfBatch) { WorkContextCache.getAndResetThreadWorkContext(); Object instance; try { instance = component.getInstance(); } catch (InstanceLifecycleException e) { throw new InvocationRuntimeException(e); } try { invoke(event, instance); } finally { try { component.releaseInstance(instance); } catch (InstanceDestructionException e) { throw new InvocationRuntimeException(e); } } }
public void execute(StopContextCommand command) throws ExecutionException { QName deployable = command.getDeployable(); WorkContextCache.getAndResetThreadWorkContext(); try { compositeScopeContainer.stopContext(deployable); if (domainScopeContainer != null) { // domain scope not available during bootstrap domainScopeContainer.stopContext(deployable); } } catch (ComponentException e) { throw new ExecutionException(e); } channelManager.stopContext(deployable); if (monitor != null && command.isLog()) { monitor.undeployed(deployable); } }
public void run() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); Object instance; try {
public long nextInterval() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); Object instance = null; try { instance = component.getInstance(); return (Long) method.invoke(instance); } catch (InstanceLifecycleException e) { monitor.executeError(e); throw new InvocationRuntimeException(e); } catch (InvocationTargetException e) { monitor.executeError(e); throw new InvocationRuntimeException(e); } catch (IllegalAccessException e) { monitor.executeError(e); throw new InvocationRuntimeException(e); } finally { if (instance != null) { try { component.releaseInstance(instance); } catch (InstanceDestructionException e) { monitor.executeError(e); } } workContext.reset(); } }
public void execute(StartContextCommand command) throws ExecutionException { QName deployable = command.getDeployable(); WorkContextCache.getAndResetThreadWorkContext(); try { compositeScopeContainer.startContext(deployable); if (domainScopeContainer != null) { // domain scope not available during bootstrap domainScopeContainer.startContext(deployable); } } catch (GroupInitializationException e) { throw new ExecutionException(e); } catch (ComponentException e) { throw new ExecutionException(e); } if (channelManager != null) { channelManager.startContext(deployable); } if (command.isLog()) { monitor.deployed(deployable); } }
public void run() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); Object instance; try {
public void run() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); workContext.addCallbackReferences(stack); workContext.addHeaders(headers); workContext.setSubject(subject); Message message = MessageCache.getAndResetMessage(); message.setBody(payload); message.setWorkContext(workContext); Message response = next.invoke(message); if (response.isFault()) { // log the exception monitor.onError((Throwable) response.getBody()); } message.reset(); workContext.reset(); }
public boolean onUpload(String fileName, String contentType, InputStream uploadData) throws Exception { Object[] args = new Object[]{fileName, uploadData}; WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); Message input = MessageCache.getAndResetMessage(); try { // set the header value for the request context workContext.setHeader(FtpConstants.HEADER_CONTENT_TYPE, contentType); input.setWorkContext(workContext); input.setBody(args); Message response = getInterceptor().invoke(input); if (response.isFault()) { monitor.fileProcessingError(servicePath, (Throwable) response.getBody()); input.reset(); return false; } return true; } finally { input.reset(); workContext.reset(); } }