use of org.xwiki.context.ExecutionContextException in project xwiki-platform by xwiki.
the class XWikiStubContextInitializerTest method testWithAndWithoutXWikiContext.
public void testWithAndWithoutXWikiContext() throws Exception {
XWikiContext xcontext = new XWikiContext();
xcontext.put("key", "value");
this.mockXWiki = mock(XWiki.class);
this.mockXWiki.stubs().method("prepareResources");
xcontext.setWiki((XWiki) this.mockXWiki.proxy());
ExecutionContext context = new ExecutionContext();
xcontext.declareInExecutionContext(context);
XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
stubContextProvider.initialize(xcontext);
final ExecutionContext daemonContext = new ExecutionContext();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
executionContextManager.initialize(daemonContext);
} catch (ExecutionContextException e) {
fail("Failed to initialize execution context: " + e.getStackTrace());
}
}
});
thread.start();
thread.join();
XWikiContext daemonXcontext = (XWikiContext) daemonContext.getProperty("xwikicontext");
assertNotNull(daemonXcontext);
assertNotSame(xcontext, daemonXcontext);
assertEquals("value", daemonXcontext.get("key"));
assertNotNull(daemonXcontext.getWiki());
}
use of org.xwiki.context.ExecutionContextException in project xwiki-platform by xwiki.
the class DefaultPortletContainerInitializer method initializeRequest.
@Override
public void initializeRequest(javax.portlet.PortletRequest portletRequest, Object xwikiContext) throws PortletContainerException {
// 1) Create an empty request. From this point forward request initializers can use the
// Container object to get any data they want from the Request.
this.container.setRequest(new PortletRequest(portletRequest));
// 2) Create en empty Execution context so that the Container initializers can put things in the
// execution context when they execute.
this.execution.setContext(new ExecutionContext());
// XWikiContext object whereas new code uses the ExecutionContext found in the Execution component.
if (xwikiContext != null) {
ExecutionContext ec = this.execution.getContext();
String key = "xwikicontext";
if (ec.hasProperty(key)) {
ec.setProperty(key, xwikiContext);
} else {
ec.newProperty(key).inherited().initial(xwikiContext).declare();
}
}
// initializers.
try {
this.requestInitializerManager.initializeRequest(this.container.getRequest());
} catch (RequestInitializerException e) {
throw new PortletContainerException("Failed to initialize request", e);
}
// 5) Call Execution Context initializers to perform further Execution Context initializations
try {
this.executionContextManager.initialize(this.execution.getContext());
} catch (ExecutionContextException e) {
throw new PortletContainerException("Failed to initialize Execution Context", e);
}
}
use of org.xwiki.context.ExecutionContextException in project xwiki-platform by xwiki.
the class HtmlPackager method renderDocuments.
/**
* Init provided {@link ExportURLFactory} and add rendered documents to ZIP stream.
*
* @param zos the ZIP output stream.
* @param urlf the {@link com.xpn.xwiki.web.XWikiURLFactory} used to render the documents.
* @param context the XWiki context.
* @throws XWikiException error when render documents.
* @throws IOException error when render documents.
*/
private void renderDocuments(ZipOutputStream zos, ExportURLFactory urlf, XWikiContext context) throws XWikiException, IOException {
ExecutionContextManager ecm = Utils.getComponent(ExecutionContextManager.class);
Execution execution = Utils.getComponent(Execution.class);
for (DocumentReference pageReference : this.pageReferences) {
try {
// Isolate and initialize Contexts
XWikiContext renderContext = initializeContexts(ecm, execution, urlf, context);
renderDocument(pageReference, zos, urlf.getFilesystemExportContext(), renderContext);
} catch (ExecutionContextException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_EXPORT, XWikiException.ERROR_XWIKI_INIT_FAILED, "Failed to initialize Execution Context", e);
} finally {
// Clean up context
execution.popContext();
}
}
}
use of org.xwiki.context.ExecutionContextException in project xwiki-platform by xwiki.
the class AbstractDocumentMojo method createXWikiContext.
protected XWikiContext createXWikiContext() throws MojoExecutionException {
EmbeddableComponentManager ecm = new EmbeddableComponentManager();
ecm.initialize(this.getClass().getClassLoader());
Utils.setComponentManager(ecm);
// Context component manager is totally useless here
ecm.unregisterComponent(ComponentManager.class, "context");
// We need to initialize the Component Manager so that the components can be looked up
XWikiContext xcontext = new XWikiContext();
xcontext.put(ComponentManager.class.getName(), ecm);
// Initialize the Container fields (request, response, session).
try {
ExecutionContextManager ecim = ecm.getInstance(ExecutionContextManager.class);
ExecutionContext econtext = new ExecutionContext();
// Bridge with old XWiki Context, required for old code.
xcontext.declareInExecutionContext(econtext);
ecim.initialize(econtext);
} catch (ExecutionContextException | ComponentLookupException e) {
throw new MojoExecutionException("Failed to initialize Execution Context.", e);
}
return xcontext;
}
use of org.xwiki.context.ExecutionContextException in project xwiki-platform by xwiki.
the class ContextLinkCheckerThreadInitializer method initialize.
@Override
public void initialize() {
ExecutionContext context = this.execution.getContext();
if (context == null) {
// Create a clean Execution Context
context = new ExecutionContext();
try {
this.executionContextManager.initialize(context);
} catch (ExecutionContextException e) {
throw new RuntimeException("Failed to initialize the Execution Context", e);
}
// Bridge with old XWiki Context, required for old code.
XWikiContext xwikiContext = this.stubContextProvider.createStubContext();
xwikiContext.declareInExecutionContext(context);
this.execution.pushContext(context);
}
}
Aggregations