Title: dcruz@example.net
Tags: java;eclipse;itext;war;qr-code
Question: I am trying to load a pdf file that has an image in it (to be more specific, my java code generates the pdf file by printing some text and an image to it. The image is a qr-code image that is generated by some other part of the code) in my web application. When I run my program in Eclipse as "Run on Server", there is no error and I can see the pdf on my localhost using chrome. However, when I create a WAR file out of my project to deploy my project locally and try to browse the pdf page in chrome I get "dcruz@example.net" error.
I commented out the part that prints the image on the pdf file in my java code and re-generated the WAR file. Now I am able to see the pdf file but of course without the image. I should say that I have no problem with browsing other pages of my application.
Would anyone please help me how I can solve this problem. Any information is greatly appreciated.
Update 1:
Here is the full stack trace
SEVERE: Exception or error caught in server resource
org.restlet.resource.ResourceException: Internal Server Error (500) - The server
encountered an unexpected condition which prevented it from fulfilling the dcruz@example.net(ServerResource.java:539)
at org.restlet.resource.ServerResource.get(ServerResource.java:742)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:617)
at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource
.java:678)
at org.restlet.resource.ServerResource.doConditionalHandle(ServerResourc
e.java:356)
at org.restlet.resource.ServerResource.handle(ServerResource.java:1043)
at org.restlet.resource.Finder.handle(Finder.java:236)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:639)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.jav
a:140)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHe
lper.java:77)
at org.restlet.Application.handle(Application.java:385)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:639)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:639)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
at org.restlet.Component.handle(Component.java:408)
at org.restlet.Server.handle(Server.java:507)
at org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:dcruz@example.net(HttpServerHelper.j
ava:143)
at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:dcruz@example.net(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:dcruz@example.net(Appl
icationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpo
int.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: dcruz@example.net(PdfGraphics2D.java:dcruz@example.net(PdfGraphics2D.java:dcruz@example.net(PdfGraphics2D.java:dcruz@example.net(PdfGraphics2D.java:dcruz@example.net(Image.java:838)
at org.safetycode.msc3.resources.PocketCardServerResource.addCodeImage(P
ocketCardServerResource.java:159)
at org.safetycode.msc3.resources.PocketCardServerResource.printCodeImage
(PocketCardServerResource.java:155)
at org.safetycode.msc3.resources.PocketCardServerResource.getPdf(PocketC
ardServerResource.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:523)
... 60 more
Comment: Whenever you solve the issue of your question yourself, please use an **answer**, not an edit of your question, to present the solution and eventually accept it.

Comment: @Compass Thank you for your comment. I just updated the post with full stack trace

Comment: Thanks a lot! I double checked my code. Every thing looks correct. I think the fact that the code executes without any problem while running on server in Eclipse, confirms that all parameters match with the method signature. The error is only when I generate a WAR file.

Comment: @ Compass Thank you for your time. My problem just solved. I updated the post accordingly.

Comment: I didn't know that. Thank you. I just posted the answer.

Comment: The full stack trace would help.

Comment: Found the source: http://grepcode.com/file/repo1.maven.org/maven2/com.itextpdf/itextpdf/5.1.3/com/itextpdf/text/pdf/PdfGraphics2D.java#PdfGraphics2D.drawImage%28java.awt.Image%2Cint%2Cint%2Cjava.awt.Color%2Cjava.awt.image.ImageObserver%29 Stepping back, it looks like you can get a bit more information out. The exception is at Line 1340. I'm not 100% familiar with itext these days, but check that your Image instance creation has 100% valid arguments. There do not appear to be any checked exceptions otherwise.

Comment: You might have to check with itext support, because there's not much else to work on aside from this. Alternatively, figure out what type of exception is triggering the IllegalArgumentException

Here is the accepted answer: I found the solution to my problem:
I tried other versions of the itextpdf
As a result, the error message was converted to "javax.imageio.IIOException: Can't create cache file!"
In the Tomcat log file, there was a message saying: "Caused by: java.nio.file.NoSuchFileException: C:\Program Files\Tomcat\apache-tomcat-7.0.69-windows-x64\apache-tomcat-7.0.69\temp\imageio2971026406080838335.tmp"
I created a folder called "temp" in the path mentioned above and reloaded the page.
I think when I was using Eclipse to run my program such temp file was generating somewhere without any problem. But with the WAR file tomcat did not have permission to create the "temp" file.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 8, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:06/23/16', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<java><eclipse><itext><war><qr-code>', 'Title': 'java.lang.IllegalArgumentException at com.itextpdf.text.pdf.PdfGraphics2D.drawImage', 'ViewCount': 633, 'id': 37999533, 'user_AboutMe': None, 'user_AccountId': 7277899.0, 'user_DisplayName': 'Rane', 'user_Reputation': 41.0, 'user_Views': 3.0, 'user_id': 5548707.0}}