04-26-2016 08:48 AM
<webscript>
<shortname>ElasticSearch search and export as Excel</shortname>
<description>ElasticSearch search and export as Excel</description>
<url>/es/exportexcel</url>
<authentication>none</authentication>
<format default=""></format>
</webscript>
public class PublicSearchExportExcelWebScript extends AbstractWebScript {
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-Disposition", "attachment; filename=\"export.xls\"");
Workbook wb = new HSSFWorkbook();
//….. build Excel
OutputStream contentOutputStream = res.getOutputStream();
wb.write(contentOutputStream);
}
}
ERROR [org.springframework.extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: strict servlet API: cannot call getWriter() after getOutputStream()
java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()
at weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletResponseImpl.java:324)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:148)
at org.springframework.extensions.webscripts.servlet.WebScriptServletResponse.getWriter(WebScriptServletResponse.java:198)
at org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer.executeScript(LocalWebScriptRuntimeContainer.java:241)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
at org.springframework.extensions.webscripts.servlet.mvc.WebScriptView.renderMergedOutputModel(WebScriptView.java:104)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:573)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:272)
at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3367)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
ERROR org.springframework.extensions.webscripts.WebScriptException: 03260002 Internal error
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:335)
at org.springframework.extensions.webscripts.servlet.mvc.WebScriptView.renderMergedOutputModel(WebScriptView.java:104)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()
at weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletResponseImpl.java:324)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:148)
at org.springframework.extensions.webscripts.servlet.WebScriptServletResponse.getWriter(WebScriptServletResponse.java:198)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:330)
at org.springframework.extensions.webscripts.servlet.mvc.WebScriptView.renderMergedOutputModel(WebScriptView.java:104)
Truncated. see log file for complete stacktrace
// call through to the parent container to perform the WebScript processing
ExtensibilityModel extModel = openExtensibilityModel();
super.executeScript(scriptReq, scriptRes, auth);
closeExtensibilityModel(extModel, scriptRes.getWriter());
String validTemplatePath = container.getTemplateProcessorRegistry().findValidTemplatePath(statusTemplate.getPath());
TemplateProcessor statusProcessor = container.getTemplateProcessorRegistry().getTemplateProcessor(validTemplatePath);
statusProcessor.process(validTemplatePath, statusModel, res.getWriter());
05-11-2016 08:29 AM
05-24-2016 09:10 AM
05-25-2016 08:31 AM
http://localhost:8080/share/proxy/alfresco/<my-alfresco-webscript-url>
http://localhost:8080/alfresco/service/<my-alfresco-webscript-url>
12-06-2017 12:28 AM
Thank you again for your responses, Steven.
Unfortunately it has nothing to do with Alfresco Repository or Share.
I just wanted this feature to work for a simple web application using the Spring Surf library, without any connection to Share or Alfresco.
In my case it is a WebQuickStart application, but it could be any application using the Spring Surf and Spring Webscripts libraries.
Apparently the same problem has been reported by these people here:
[ALF-21949] Conflict between Surf extensibility handling and streaming web script - Alfresco JIRA
I will try to have a look whether I can find a fix for this problem (preferably a generic solution).
01-19-2018 01:59 AM
Finally I have fixed this problem by patching Alfresco Surf, like this:
1) I created a new class inside spring-webscripts-1.2.0.jar :
package org.springframework.extensions.webscripts;
/**
* Represents a type of {@link WebScript} which directly streams the content (such as a binary file) to the {@link WebScriptResponse#getOutputStream()}.
* <p>
* If you want to implement the streaming of the content directly to the OutputStream obtained from the {@link WebScriptResponse},
* then subclass this abstract class and override the method {@link AbstractWebScript#execute(WebScriptRequest, WebScriptResponse)}.
*/
public abstract class OutputStreamWebScript extends AbstractWebScript {
}
As you can see, this is just an empty "marker class".
2) I have modified the following class inside spring-surf-1.2.0.jar : org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer (the one which was causing the exception):
2a) I have added a new method after executeScript(WebScriptRequest scriptReq, WebScriptResponse scriptRes, Authenticator auth) :
private void executeScriptWithExtensibilityModel(WebScriptRequest scriptReq, WebScriptResponse scriptRes, Authenticator auth) throws IOException
{
WebScript script = scriptReq.getServiceMatch().getWebScript();
if (script instanceof OutputStreamWebScript)
{
// This type of WebScript streams directly the content to the OutputStream of the WebScriptResponse,
// so we must not apply any extensibility model, but call through to the parent container to perform the WebScript processing
super.executeScript(scriptReq, scriptRes, auth);
}
else
{
// For all the other types of WebScripts, apply the extensibility model as needed
ExtensibilityModel extModel = openExtensibilityModel();
super.executeScript(scriptReq, scriptRes, auth);
closeExtensibilityModel(extModel, scriptRes.getWriter());
}
}
2b) I replaced the following lines inside executeScript(WebScriptRequest scriptReq, WebScriptResponse scriptRes, Authenticator auth):
try
{
// call through to the parent container to perform the WebScript processing
ExtensibilityModel extModel = openExtensibilityModel();
super.executeScript(scriptReq, scriptRes, auth);
closeExtensibilityModel(extModel, scriptRes.getWriter());
}
with these lines:
try
{
// call through to the parent container to perform the WebScript processing, applying any ExtensibilityModel
executeScriptWithExtensibilityModel(scriptReq, scriptRes, auth);
}
I will try to see if someone with access to the spring-surf and spring-webscripts repository can commit these improvements, so anyone else can use them in the future.
07-15-2017 01:17 AM
There is one generic example using which you can export any kind of data in excel.Below link will help you understanding that stuff.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.