use of com.xpn.xwiki.web.XWikiResponse in project xwiki-platform by xwiki.
the class XWikiContextCopier method copy.
/**
* {@inheritDoc}
*
* Any in progress session/transaction on the store retained by the original context will be closed/rollbacked
* prior cloning (see {@link com.xpn.xwiki.store.XWikiStoreInterface#cleanUp(XWikiContext)}). Therefore,
* the copy operation has a side effect on the original context. You should never copy a context
* while a create/update transaction is in progress, since some changes would get rollbacked.
*/
@Override
public XWikiContext copy(XWikiContext originalXWikiContext) {
// Clean up the store session/transaction before cloning. For the hibernate store, in progress
// session/transaction is stored in the context, and would be swallow copied when the context is cloned.
// Cleaning after clone would not help, since it would close/rollback the session/transaction still referenced
// in the original context as well, causing this context to be corrupted.
// The correct way would be to not shallow clone the session/transaction when cloning the original context,
// since session/transaction are lazy initialize on request when missing.
originalXWikiContext.getWiki().getStore().cleanUp(originalXWikiContext);
// This is still a shallow clone, but at least for stuff like wikiID and userReference it gets the job done.
XWikiContext clonedXWikiContext = originalXWikiContext.clone();
// lets now build the stub context
// Copy the request from the context.
clonedXWikiContext.setRequest(this.xwikiRequestCloner.copy(originalXWikiContext.getRequest()));
// Force forged context response to a stub response, since the current context response
// will not mean anything anymore when running in the scheduler's thread, and can cause
// errors.
XWikiResponse stub = new XWikiServletResponseStub();
clonedXWikiContext.setResponse(stub);
// feed the dummy context
if (clonedXWikiContext.getURL() == null) {
try {
clonedXWikiContext.setURL(new URL("http://www.mystuburl.com/"));
} catch (Exception e) {
// the URL is clearly well formed
}
}
XWikiURLFactory xurf = originalXWikiContext.getWiki().getURLFactoryService().createURLFactory(originalXWikiContext.getMode(), originalXWikiContext);
clonedXWikiContext.setURLFactory(xurf);
return clonedXWikiContext;
}
use of com.xpn.xwiki.web.XWikiResponse in project xwiki-platform by xwiki.
the class SVGPlugin method outputSVGImageFromFile.
public void outputSVGImageFromFile(String filename, XWikiContext context) throws IOException {
File ofile = getTempFile(filename);
byte[] svgbytes = readSVGImage(ofile);
XWikiResponse response = context.getResponse();
context.setFinished(true);
response.setDateHeader("Last-Modified", ofile.lastModified());
response.setContentLength(svgbytes.length);
response.setContentType(context.getEngineContext().getMimeType(filename));
OutputStream os = response.getOutputStream();
os.write(svgbytes);
}
use of com.xpn.xwiki.web.XWikiResponse in project xwiki-platform by xwiki.
the class XWikiAuthServiceImplTest method before.
@Before
public void before() throws Exception {
this.authService = new XWikiAuthServiceImpl();
// Dummy response
XWikiResponse xwikiResponse = mock(XWikiResponse.class);
when(xwikiResponse.encodeURL(any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
});
this.oldcore.getXWikiContext().setResponse(xwikiResponse);
}
use of com.xpn.xwiki.web.XWikiResponse in project xwiki-platform by xwiki.
the class XWikiAuthServiceImplTest method testStripContextPathFromURLWhenRootWebAppAndJSessionId.
@Test
public void testStripContextPathFromURLWhenRootWebAppAndJSessionId() throws Exception {
doReturn("").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class));
// Simulate a rewrite filter that would add a jsession id and add a leading slash!
XWikiResponse xwikiResponse = mock(XWikiResponse.class);
when(xwikiResponse.encodeURL("http://localhost:8080")).thenReturn("http://localhost:8080/;jsessionid=0AF95AFB8997826B936C0397DF6A0C7F");
this.oldcore.getXWikiContext().setResponse(xwikiResponse);
assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http://localhost:8080/something"), this.oldcore.getXWikiContext()));
}
use of com.xpn.xwiki.web.XWikiResponse in project xwiki-platform by xwiki.
the class XWikiAuthServiceImplTest method testStripContextPathFromURLWhenOutBoundRewriteRuleChangingContextPath.
/**
* Simulates the use case when the {@code HttpServletResponse.encodeURL()} changes the context path.
*/
@Test
public void testStripContextPathFromURLWhenOutBoundRewriteRuleChangingContextPath() throws Exception {
doReturn("xwiki/").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class));
XWikiResponse xwikiResponse = mock(XWikiResponse.class);
when(xwikiResponse.encodeURL(any())).thenReturn("http://localhost:8080/anothercontext;jsessionid=0AF95AFB8997826B936C0397DF6A0C7F?language=en");
this.oldcore.getXWikiContext().setResponse(xwikiResponse);
// Note: the passed URL to stripContextPathFromURL() has also gone through encodeURL() which is why its
// context path has been changed from "xwiki" to "anothercontext".
assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http://localhost:8080/anothercontext/something"), this.oldcore.getXWikiContext()));
}
Aggregations