Search code examples
jspitextjdeveloper

Jdeveloper itext fatal internal error


I am working on Jdeveloper to create dynamic PDFs using JSP. However I get a "Error: Internal compilation error, terminated with a fatal exception" on the compilation of the code. I am not sure what the problem is. The code of my JSP page(name Make.jsp) is:

<%@ page import="java.text.*,java.util.*,java.sql.*,javax.servlet.Filter.*,javax.sql.*,java.io.*"  %>
<%@ page import="com.itextpdf.text.*,com.itextpdf.text.pdf.*"  %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
   <title>Make</title>
 </head>
 <body>
<%
 OutputStream file=new FileOutputStream(new File("E:\\CreatedPDF\\JdevFile.pdf"));
 Document document=new Document();
 PdfWriter.getInstance(document,file);
 document.open();
 document.add(new Paragraph("Hello World"));
 document.close();
%>
</body>

The log file shows the following:

   errorFound:         true
   class:              _Make
   method:              void _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  field:               

  source:              C:\Users\e\Documents\BHEL Bhopal\jdevstudio1013\jdev\mywork\Test\EstimationProj\public_html\WEB-INF\classes\.jsps\_Make.java
   line:                56

    java.lang.NullPointerException
    at oracle.ojc.compiler.Symbol.checkForAmbigousImport(Symbol.java:261)
    at oracle.ojc.compiler.UnresolvedClassSymbol.resolveType(Symbol.java:8515)
    at  oracle.ojc.compiler.UnresolvedClassSymbol.resolveActualTypeParameters(Symbol.java:8260)
    at oracle.ojc.compiler.UnresolvedClassSymbol.resolveType(Symbol.java:8527)
    at oracle.ojc.compiler.ClassFileReader.readClassFile(ClassFileReader.java:1684)
    at oracle.ojc.compiler.RawClassSymbol.loadType(Symbol.java:6418)
    at oracle.ojc.compiler.RawClassSymbol.loadType(Symbol.java:6402)
    at oracle.ojc.compiler.ImportDescriptor.importInnerClasses(Parser.java:8780)
    at oracle.ojc.compiler.ImportDescriptor.importInnerClasses(Parser.java:8807)
    at oracle.ojc.compiler.ImportDescriptor.importInnerClasses(Parser.java:8807)
    at oracle.ojc.compiler.ImportSymbol.resolveAndCheck(Symbol.java:11257)
    at oracle.ojc.compiler.StorageScope.lookupSpecificSymbolInScope(Scope.java:823)
    at oracle.ojc.compiler.PackageScope.lookupSpecificSymbol(Scope.java:1088)
    at oracle.ojc.compiler.ClassScope.lookupSpecificSymbol(Scope.java:1282)
    at oracle.ojc.compiler.MethodScope.lookupSpecificSymbol(Scope.java:1414)
    at oracle.ojc.compiler.BlockScope.lookupSpecificSymbol(Scope.java:1518)
    at oracle.ojc.compiler.MemberExpression.resolveQualifiedName(Expression.java:1540)
    at oracle.ojc.compiler.InvokeExpression.resolveAndCheck(Expression.java:5094)
    at oracle.ojc.compiler.ExpressionStatement.resolveAndCheck(Statement.java:225)
    at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
    at oracle.ojc.compiler.TryStatement.resolveAndCheck(Statement.java:3499)
    at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
    at oracle.ojc.compiler.MethodSymbol.resolveMethod(Symbol.java:10822)
    at oracle.ojc.compiler.RawClassSymbol.resolveMethodBodies(Symbol.java:6648)
    at oracle.ojc.compiler.Parser.resolveMethodBodies(Parser.java:8316)
    at oracle.ojc.compiler.Parser.parse(Parser.java:7823)
    at oracle.ojc.compiler.Compiler.main_internal(Compiler.java:978)
    at oracle.ojc.compiler.Compiler.main(Compiler.java:745)
    at oracle.jdeveloper.compiler.Ojc.translate(Ojc.java:1486)
    at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildGraph(UnifiedBuildSystem.java:300)
    at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildProjectFiles(UnifiedBuildSystem.java:516)
    at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildAll(UnifiedBuildSystem.java:715)
    at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.run(UnifiedBuildSystem.java:893)

I tried the above code on Eclipse and it works fine but I am working for an organisation and they want me to work on jdeveloper only. So,it would be really helpful if someone could point out the problem. I am using Jdeveloper 10g and itext 5.5.1


Solution

  • PDF is a binary format. Each PDF starts with %PDF- and ends with %%EOF. In between, there are objects and some of these objects contain binary streams.

    As you (should) know, JSP should not be used to create binary files, hence your "requirement" to create PDF from JSP is... not wise. It's possible to create PDF from JSP. This is a proof of concept: http://itextpdf.com:8180/book/helloworld.jsp

    This POC was written in the context of my book "iText in Action - Second Edition" to explain why it's a bad idea to create PDF from JSP. You can use secion 9.1.3 from that book if you need arguments to make sure that the person who wrote your requirement sees the error of his ways and reconsiders.

    As for your code. It is wrong on many levels.

    For instance, a PDF should start with %PDF- whereas the result of your JSP file starts with:

    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
        <title>Make</title>
    </head>
    <body>
    

    That's HTML, not PDF, how is that ever going to work? (It isn't!)

    I suppose that you want to send a PDF to the browser. However, I see that you create a FileOutputStream. That means that you're creating a file on the server, more specifically on the E: disk. It would really surprise me if your web server had access to that disk. (It's possible, but it's not wise to do stuff like this.)

    The exception itself is probably unrelated to iText. It says something about an ambiguous import. You're importing:

    • java.text.*
    • java.util.*
    • java.sql.*
    • javax.servlet.Filter.*
    • javax.sql.*
    • java.io.*
    • com.itextpdf.text.*
    • com.itextpdf.text.pdf.*

    There are plenty of class names that are used in different of these packages. For instance: there's java.util.List, but also com.itextpdf.text.List. That's a simple example, I'm not saying that this is the cause of your exception, but it is sloppy to use the * instead of importing the specific classes you need.

    Long story short: please throw away your code. Do not use JSP, write a Servlet as is done in Chapter 9 of my book.