List of usage examples for org.apache.wicket ThreadContext detach
public static ThreadContext detach()
From source file:at.molindo.wicketutils.utils.MockUtils.java
License:Apache License
/** * unset request and session to force mocking *//*from w ww . j a v a 2s .c o m*/ public static <V> V withNewRequest(WebApplication webApplication, IMockRequestCallback<V> callback) { ThreadContext oldContext = ThreadContext.detach(); try { return withRequest(webApplication, callback); } finally { ThreadContext.restore(oldContext); } }
From source file:at.molindo.wicketutils.utils.MockUtils.java
License:Apache License
/** * reuse an existing session if possible *//*from www. ja v a 2s . c om*/ public static <V> V withRequest(WebApplication webApplication, IMockRequestCallback<V> callback) { Session oldSession = ThreadContext.exists() ? ThreadContext.getSession() : null; ThreadContext oldContext = ThreadContext.detach(); try { ThreadContext.setApplication(webApplication); ThreadContext.setSession(oldSession); // mock http session ServletContext context = webApplication.getServletContext(); MockHttpSession httpSession = new MockHttpSession(context); // mock servlet request MockServletRequest servletRequest = new MockServletRequest(webApplication, httpSession, context); callback.configure(new MockRequest(servletRequest)); servletRequest.setDefaultHeaders(); // mock response MockHttpServletResponse servletResponse = new MockHttpServletResponse(servletRequest); // mock web request final WebRequest request = VisibilityHelper.newWebRequest(webApplication, servletRequest, "/"); // mock web response final WebResponse response = VisibilityHelper.newWebResponse(webApplication, request, servletResponse); // create ThreadContext.setRequestCycle(webApplication.createRequestCycle(request, response)); return callback.call(); } finally { Session newSession = ThreadContext.getSession(); ThreadContext.restore(oldContext); if (oldSession == null && newSession != null && !newSession.isTemporary()) { // reuse session if a new one was created ThreadContext.setSession(newSession); } } }
From source file:com.mastfrog.acteur.wicket.WicketActeur.java
License:Open Source License
@Inject
WicketActeur(HttpEvent evt, Application application, PathFactory pf, Charset charset, WicketConfig config,
ByteBufAllocator alloc, Settings settings, ReentrantScope scope) {
RequestAdapter request = new RequestAdapter(evt, config.locale(), charset, settings);
ResponseAdapter response = new ResponseAdapter(response(), charset, alloc, pf);
try (QuietAutoCloseable closeScope = scope.enter(request, response, response())) {
ThreadContext.setApplication(application);
RequestCycle requestCycle = application.createRequestCycle(request, response);
ThreadContext.setRequestCycle(requestCycle);
boolean processed = requestCycle.processRequestAndDetach();
if (!processed) {
reject();/*from w w w. j a va2 s.c o m*/
} else {
HttpResponseStatus status = response.status();
reply(status == null ? OK : status);
}
} finally {
ThreadContext.detach();
}
}
From source file:org.artifactory.webapp.WebappServiceImpl.java
License:Open Source License
@Override public void rebuildSiteMap() { // get the first application key (in aol it will not work!) ArtifactoryApplication app = (ArtifactoryApplication) Application .get(Application.getApplicationKeys().iterator().next()); // we must attach the application to the current thread in order to perform wicket operation ThreadContext.setApplication(app);/*from www . ja v a2 s .c om*/ try { app.rebuildSiteMap(); } finally { ThreadContext.detach(); } }
From source file:org.efaps.ui.wicket.background.JobRunnable.java
License:Apache License
@Override public void run() { try {//w w w .j a v a2 s.c o m ThreadContext.setApplication(this.application); ThreadContext.setSession(this.session); final Context context = Context.begin(this.bridge.getJobContext().getUserName(), this.bridge.getJobContext().getLocale(), null, null, null, Context.Inheritance.Local); context.setCompany(Company.get(this.bridge.getJobContext().getCompanyUUID())); this.job.execute(this.bridge); Context.commit(true); } catch (final EFapsException e) { LOG.debug("run", e); } finally { ThreadContext.detach(); } }
From source file:org.wicketstuff.springreference.AbstractSpringDependenciesTest.java
License:Apache License
@After public void after() { ThreadContext.detach(); }
From source file:sf.wicklet.ext.test.auth.TestWxSignInPanel01.java
License:Apache License
@Before public void setup() { // make sure no leaked threadlocals are present ThreadContext.detach(); final WebApplication application = new MockApplication() { @Override// ww w. j a va 2s . co m public Session newSession(final Request request, final Response response) { return new TestSession(request); } }; tester = new WicketTester(application); }
From source file:sf.wicklet.test.support.WicketTestBase.java
License:Apache License
@Before public void setup() { // make sure no leaked threadlocals are present ThreadContext.detach(); final WebApplication application = new MockApplication(); tester = new WicketTester(application); }
From source file:sf.wicklet.wicketext.test.TestMarkupParser02.java
License:Apache License
@Test public void test01() { ThreadContext.detach(); tester = new WicketTester(new Application01()); tester.getSession().setLocale(Locale.ENGLISH); tester.startPage(HomePage01.class); tester.dumpPage();/* www . j a v a2 s . c o m*/ }