[opencms-dev] Create resource problem with PDF files as binary

Ivan Jelenic ivan.jelenic at nbs.yu
Mon Jan 26 16:03:00 CET 2004


Hi,

I am developing Intranet site with OpenCms. I have a problem with createResource method. First JSP is :

<%

// Create a JSP action element
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);

// Create a string of requested file
String filename = cms.getRequestContext().getUri();

// Get CmsObject
CmsObject cmsObject =cms.getCmsObject();
String userName = request.getParameter("OPENCMSUSERNAME");
String password = request.getParameter("OPENCMSPASSWORD");
boolean logout = false;

if (request.getParameter("OPENCMSUSERNAME") == null) {
 %>
  <table>
   <form name="login" method="post" action="<%= cms.link("ImportPDF.jsp")%>">
   <tr align="left"><td colspan="2"><br><p><b>Prijava:</b></p></td></tr>
   <tr>
    <td><p>Username: </p></td>
    <td><p><input type="text" name="OPENCMSUSERNAME" size="15" maxlength="64"></p></td>
   </tr>
   <tr>
    <td><p>Password: </p></td>
    <td><p><input type="password" size="15" maxlength="32" name="OPENCMSPASSWORD"></p></td>
   </tr>
   <tr align="center"><td colspan="2"><input type="submit" value="Prijava"></td></tr>
   </form>
  </table>
 <%
} else {
 out.println("Pocinjem prijavu na OpenCMS !!");
 try {
  cmsObject.loginUser(userName,password);
  out.println("Welcome to OpenCMS! \n Korisnik: " + userName + "<br>");
  %>
    <form name="webhouse" action="<%= cms.link("/intranet/jsp/obrada1.jsp")%>" method="post" enctype="multipart/form-data">
     Naslov:<INPUT size=80 name="NavText"><br>
     Virtualni fajl sistem:<INPUT size=80 name="Path"><br>
     Ključne reči:<BR>
                <TEXTAREA name="Keywords" rows=3 cols=25 size="30"></TEXTAREA> 
     Opis strane:<BR>
                <TEXTAREA name="Description" rows=3 cols=25></TEXTAREA><br>
                <INPUT type=file size=60 name="Page"><br>
                <INPUT type=radio value="V1" name="Format"> HTML   
                <INPUT type=radio value="V2" name="Format"> PDF<br>
                <INPUT type=submit value=Pošalji name=Send>  <INPUT type=reset value=Poništi name=Cancle>
    </form>
   <!-- enctype="multipart/form-data" -->
  <%
  
  //nastavak
    
  } catch(CmsException e) {
    System.out.println(new java.util.Date() + " OpenCMS INFO: Neuspesno ulogovan korisnik " + userName);
    out.println("<h2>Neuspešna prijava na sistem, molimo pokušajte ponovo</h2>");
  }//end catch
}
%>

As you can see it's very simple and I use it for log in and showing a form for uploading PDF files. After that I use another JSP for processing data. Code is:

<%
// Create a JSP action element
CmsJspActionElement cmsJsp = new CmsJspActionElement(pageContext, request, response);

// Create a string of requested file
String filename = cmsJsp.getRequestContext().getUri();
CmsObject cms = cmsJsp.getCmsObject();
String format = cmsJsp.getRequestContext().getRequest().getParameter("Format");
out.println("Format: " + format);
String pathVFS = "";

Enumeration files = cms.getRequestContext().getRequest().getFileNames();
out.println("Prosao enumeration!!");
while (files.hasMoreElements()) {
 out.println("Usao u while!!");
 String fileName = (String) files.nextElement();
 fileName = fileName.toUpperCase();
 System.out.println("Ime: " + fileName);
  if (fileName.endsWith(".PDF") && fileName != "unknown") {
  System.out.println("Usao i if (PDF)");
  byte[] filecontent = (byte[]) cms.getRequestContext().getRequest().getFile(fileName);
  //Prijava admin user-a
  try {
   cms.loginUser("Admin","opencms");
   cms.getRequestContext().setCurrentProject(3);
   System.out.println("Uspesno logovanje Admin-a");
   Hashtable props = new Hashtable();
   //props.put("Title",cmsJsp.getRequestContext().getRequest().getParameter("Page"));
   props.put("Description",cmsJsp.getRequestContext().getRequest().getParameter("Description"));
   props.put("Keywords",cmsJsp.getRequestContext().getRequest().getParameter("Keywords"));
   props.put("NavText",cmsJsp.getRequestContext().getRequest().getParameter("NavText"));
   System.out.println("Setovani Properties za file-ove");
   CmsResource cmsres = null;
   System.out.println("Kreiranje PDF file-a u CMS-u!!");
   pathVFS = cms.getRequestContext().getRequest().getParameter("Path");
     try{
      //cms.lockResource(pathVFS);
      cms.getRequestContext().setCurrentProject(3);//temp project ID
      System.out.println("Na putanji: " + pathVFS);
      cmsres = cms.createResource(pathVFS, fileName, "binary", props, filecontent);
      System.out.println("PDF file je uspesno kreiran u CMS-u !!");     
     }catch(CmsException e){
      System.out.println("Neuspesno kreiranje !!!");
      out.println("Neuspesno kreiranje PDF!!!");
      e.printStackTrace();
     }
  } catch(CmsException e){
     System.out.println("Neuspesno logovanje !!!");
  } 
 } 
} 
%>

VFS path is OK. I've got this error:

javax.servlet.ServletException: Resource loader error in file '/intranet/jsp/obrada1.jsp'

Root cause:
org.apache.jasper.JasperException
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
......

Tomcat Log file:

 
2004-01-26 16:01:15 ApplicationDispatcher[/opencms] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
	at com.opencms.file.mySql.CmsDbAccess.createFile(CmsDbAccess.java:352)
	at com.opencms.file.genericSql.CmsResourceBroker.createFile(CmsResourceBroker.java:1789)
	at com.opencms.file.CmsObject.doCreateFile(CmsObject.java:978)
	at com.opencms.file.CmsResourceTypePlain.createResource(CmsResourceTypePlain.java:308)
	at com.opencms.file.CmsObject.createResource(CmsObject.java:934)
	at com.opencms.file.CmsObject.createResource(CmsObject.java:929)
	at org.apache.jsp.WEB_002dINF.jsp.online.intranet.jsp.obrada1_jsp_jsp._jspService(obrada1_jsp_jsp.java:110)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:742)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:630)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:542)
	at com.opencms.flex.cache.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:158)
	at com.opencms.flex.CmsJspLoader.service(CmsJspLoader.java:972)
	at com.opencms.flex.cache.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:256)
	at com.opencms.flex.CmsJspLoader.load(CmsJspLoader.java:577)
	at com.opencms.flex.CmsJspLoader.initlaunch(CmsJspLoader.java:239)
	at com.opencms.core.OpenCms.showResource(OpenCms.java:961)
	at com.opencms.core.OpenCmsHttpServlet.doGet(OpenCmsHttpServlet.java:310)
	at com.opencms.core.OpenCmsHttpServlet.doPost(OpenCmsHttpServlet.java:331)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
	at java.lang.Thread.run(Thread.java:534)Please Help.Best regards, Ivan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20040126/47202c97/attachment.htm>


More information about the opencms-dev mailing list