AnsweredAssumed Answered

Error in download= org.xml.sax.SAXParseException: Prematu

Question asked by kamal1387 on Aug 20, 2011
I am getting following error when i download the document from alfresco using JSP.
Please provide the solution.

org.apache.xml.security.c14n.InvalidCanonicalizerException: Unknown canonicalizer. No handler installed for URI http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments
   at org.apache.xml.security.c14n.Canonicalizer.<init>(Unknown Source)
   at org.apache.xml.security.c14n.Canonicalizer.getInstance(Unknown Source)
   at org.apache.xml.security.utils.XMLUtils.outputDOM(Unknown Source)
   at org.apache.ws.axis.security.WSDoAllSender.invoke(WSDoAllSender.java:195)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.client.AxisClient.invoke(AxisClient.java:127)
   at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
   at org.apache.axis.client.Call.invoke(Call.java:2767)
   at org.apache.axis.client.Call.invoke(Call.java:2443)
   at org.apache.axis.client.Call.invoke(Call.java:2366)
   at org.apache.axis.client.Call.invoke(Call.java:1812)
   at org.alfresco.webservice.content.ContentServiceSoapBindingStub.read(ContentServiceSoapBindingStub.java:467)
   at jsp_servlet._homebody.__runningreporthomebody._jspService(__runningreporthomebody.java:185)
   at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
   at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
   at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
   at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:502)
   at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:432)
   at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:163)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:137)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:881)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473)
   at jsp_servlet._home.__applicationlayout._jsp__tag8(__applicationlayout.java:520)
   at jsp_servlet._home.__applicationlayout._jsp__tag7(__applicationlayout.java:474)
   at jsp_servlet._home.__applicationlayout._jsp__tag2(__applicationlayout.java:248)
   at jsp_servlet._home.__applicationlayout._jsp__tag0(__applicationlayout.java:149)
   at jsp_servlet._home.__applicationlayout._jspService(__applicationlayout.java:104)
   at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
   at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
   at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
   at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:502)
   at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:432)
   at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:163)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:137)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:881)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473)
   at jsp_servlet._home.__runningreporthome._jsp__tag0(__runningreporthome.java:127)
   at jsp_servlet._home.__runningreporthome._jspService(__runningreporthome.java:85)
   at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
   at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
   at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
   at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:502)
   at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
   at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
   at org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl.dispatch(JspTilesViewHandlerImpl.java:236)
   at org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl.renderView(JspTilesViewHandlerImpl.java:222)
   at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
   at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
   at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
   at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
   at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
   at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
   at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
   at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
   at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
   at com.ultimatix.framework.jsf.util.ForcedLoginFilter.doFilter(ForcedLoginFilter.java:619)
   at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
   at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
   at weblogic.security.service.SecurityManager.runAs(Unknown Source)
   at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
   at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
   at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
   at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
   at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
error in webservice = org.xml.sax.SAXParseException: Premature end of file.



_______________________________________________________

My code:
<%@ page %>
<%@ page
   import="org.alfresco.webservice.util.*,javax.faces.context.FacesContext,org.alfresco.webservice.repository.UpdateResult,org.alfresco.webservice.types.*,org.alfresco.webservice.types.ParentReference,org.alfresco.util.ISO9075,org.alfresco.webservice.util.ContentUtils,org.alfresco.webservice.util.Constants,org.alfresco.webservice.content.Content,org.alfresco.webservice.content.ContentServiceSoapBindingStub,org.alfresco.webservice.types.Reference,org.alfresco.webservice.types.Predicate,org.alfresco.webservice.util.AuthenticationUtils,org.alfresco.webservice.util.WebServiceFactory,org.alfresco.webservice.types.Store,java.io.*,java.net.HttpURLConnection,java.net.URL,java.net.URLClassLoader"%>


<%
   try{
      
      try
      {
      java.lang.System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
      "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
      java.lang.System.setProperty("javax.xml.parsers.SAXParserFactory",
      "org.apache.xerces.jaxp.SAXParserFactoryImpl");
      
      }catch(Exception e1)
      {
         System.out.println("Error in se property : " + e1.getMessage());
      }   
            
            
    String uuid = "0ca66a49-8ebb-4d01-b2e7-4d5a13998c60";
   String filename = "Winter.jpg";
   Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
   System.out.println("Store = " + STORE);
   
   WebServiceFactory.setEndpointAddress("http://172.17.178.144:8090/alfresco/api/");
   System.out.println("getEndpointAddress = " + WebServiceFactory.getEndpointAddress());
   
   AuthenticationUtils.startSession("system", "system");
   System.out.println("getAuthenticationDetails = " +AuthenticationUtils.getAuthenticationDetails());
   
   Reference reference = new Reference(STORE, uuid, null);
   System.out.println("reference = " + reference);
   
   Predicate predicate = new Predicate(new Reference[] { reference },STORE, null);
   System.out.println("predicate = " + predicate);
   
      
   ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
   System.out.println("contentService = "+contentService);
   System.out.println("succes1");
   System.out.println("succes2");
   
   System.out.println("User Name : " + contentService.getUsername());
   
   Content[] readResult = contentService.read(predicate,Constants.PROP_CONTENT); // it is place the error is coming
   System.out.println("succes3");
   System.out.println("readResult = "+readResult);
   
     
   for (int i = 0; i < readResult.length; i++) {

      Content content1 = readResult[i];
      System.out.println("content1 = "+content1);
      
      String[] splitedUrl = content1.getUrl().split("/");
      System.out.println("splitedUrl = "+splitedUrl);
      
      filename = splitedUrl[splitedUrl.length - 1];
      System.out.println("filename = "+filename);         
      
      FacesContext facesContext = FacesContext.getCurrentInstance();
      HttpServletResponse response1 = (HttpServletResponse) facesContext
            .getExternalContext().getResponse();
      ServletOutputStream outputStream = response1.getOutputStream();
      String contType = "image/jpeg"; //getContentType(fileName);
      response1.setContentType(contType);
      response1.addHeader("Content-Disposition",
            "attachment;filename=\"" + filename + "\"");
      InputStream in = ContentUtils.getContentAsInputStream(content1);
      BufferedInputStream bis = new BufferedInputStream(in);
      ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
      int nByte = bis.read();
      while (nByte != -1) {
         baos.write(nByte);
         nByte = bis.read();
      }
      baos.writeTo(outputStream);
      baos.flush();
      baos.close();
      outputStream.flush();
      outputStream.close();
      response1.flushBuffer();
      facesContext.renderResponse();
      facesContext.responseComplete();
   }
 
  
   
   }
catch(Exception e)
{
   System.out.println("error in webservice = "+e.getMessage());
}

finally {
   AuthenticationUtils.endSession();

}
%>

Thanks in advance……

Outcomes