gagaliya
asked on
dynamically generate images on serverside
hey, i need to dynamically generate images on the serverside using java. here's something i am really confused about, please clarify
the requirements to generate images on the server are:
1) headless mode
2) x graphic thing installed
Are those two the same or different? i have java 1.4 so that should solve the headless mode problem automatically right? Do i still need to worry about having x-windows installed? how do i know if xwindow is installed, how do i install it?
i am using:
Redhat Linux 7.3
Apache 1.3.27
Tomcat 4.03
J2SDK 1.4.0
--------
I also would love to give out the 500 points to the last question related to this, if anyone can take a look at it. basically the solution was already provided to me, but i am getting exceptions while trying it out. You can find the question at:
https://www.experts-exchange.com/questions/20907938/convert-servlet-to-jsp-how.html
the requirements to generate images on the server are:
1) headless mode
2) x graphic thing installed
Are those two the same or different? i have java 1.4 so that should solve the headless mode problem automatically right? Do i still need to worry about having x-windows installed? how do i know if xwindow is installed, how do i install it?
i am using:
Redhat Linux 7.3
Apache 1.3.27
Tomcat 4.03
J2SDK 1.4.0
--------
I also would love to give out the 500 points to the last question related to this, if anyone can take a look at it. basically the solution was already provided to me, but i am getting exceptions while trying it out. You can find the question at:
https://www.experts-exchange.com/questions/20907938/convert-servlet-to-jsp-how.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks guys, guess i will just post in this thread and split the points later in both.
<%=GraphicsEnvironment.isH eadless()% > this returns a false
So i guess it is not in headless mode.
" try setting the following property when starting tomcat:
java.awt.headless=true"
how do i do this? currently i have <% java.awt.headless=true; %>in the beginning of my jsp file.
you mentioned i ned to do it when starting tomcat? how do i do that?
also the x window part, do i have to worry about that too? thanks!
<%=GraphicsEnvironment.isH
So i guess it is not in headless mode.
" try setting the following property when starting tomcat:
java.awt.headless=true"
how do i do this? currently i have <% java.awt.headless=true; %>in the beginning of my jsp file.
you mentioned i ned to do it when starting tomcat? how do i do that?
also the x window part, do i have to worry about that too? thanks!
ASKER
hey i did some more test see below:
<html>
<head>
<%@ page import = "java.awt.*, java.awt.image.*, com.sun.image.codec.jpeg.* , java.util.*, java.io.*" %>
</head>
<body>
<%System.setProperty("java .awt.headl ess", "true");%>
<%=GraphicsEnvironment.isH eadless()% > //this shows as false
<%=System.getProperty("jav a.awt.head less")%> //this shows as true
</body>
</html>
i still get the same exceptions
javax.servlet.ServletExcep tion
at org.apache.jasper.runtime. PageContex tImpl.hand lePageExce ption(Page ContextImp l.java:463 )
at org.apache.jsp.itemlogo$js p._jspServ ice(itemlo go$jsp.jav a:102)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.jasper.servlet. JspServlet $JspServle tWrapper.s ervice(Jsp Servlet.ja va:202)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:382)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:474)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.access$0 (Applicati onFilterCh ain.java:1 97)
at org.apache.catalina.core.A pplication FilterChai n$1.run(Ap plicationF ilterChain .java:176)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 72)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:243)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:190)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .Certifica tesValve.i nvoke(Cert ificatesVa lve.java:2 46)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2343)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:170)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:170 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.ajp.tomcat4.Ajp 13Processo r.process( Ajp13Proce ssor.java: 429)
at org.apache.ajp.tomcat4.Ajp 13Processo r.run(Ajp1 3Processor .java:495)
at java.lang.Thread.run(Threa d.java:536 )
root cause
java.lang.NoClassDefFoundE rror
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Cl ass.java:1 30)
at java.awt.GraphicsEnvironme nt.getLoca lGraphicsE nvironment (GraphicsE nvironment .java:62)
at java.awt.image.BufferedIma ge.createG raphics(Bu fferedImag e.java:105 3)
at java.awt.image.BufferedIma ge.getGrap hics(Buffe redImage.j ava:1043)
at org.apache.jsp.itemlogo$js p._jspServ ice(itemlo go$jsp.jav a:65)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.jasper.servlet. JspServlet $JspServle tWrapper.s ervice(Jsp Servlet.ja va:202)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:382)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:474)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.access$0 (Applicati onFilterCh ain.java:1 97)
at org.apache.catalina.core.A pplication FilterChai n$1.run(Ap plicationF ilterChain .java:176)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 72)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:243)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:190)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .Certifica tesValve.i nvoke(Cert ificatesVa lve.java:2 46)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2343)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:170)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:170 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.ajp.tomcat4.Ajp 13Processo r.process( Ajp13Proce ssor.java: 429)
at org.apache.ajp.tomcat4.Ajp 13Processo r.run(Ajp1 3Processor .java:495)
at java.lang.Thread.run(Threa d.java:536 )
when trying to run this file:
<%@ page import = "java.awt.*, java.awt.image.*, com.sun.image.codec.jpeg.* , java.util.*, java.io.*" %><%
System.setProperty("java.a wt.headles s", "true");
// Create image
int width=200, height=200;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB );
// Get drawing context
Graphics g = image.getGraphics();
// Fill background
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// Create random polygon
Polygon poly = new Polygon();
Random random = new Random();
for (int i=0; i < 5; i++) {
poly.addPoint(random.nextI nt(width),
random.nextInt(height));
}
// Fill polygon
g.setColor(Color.cyan);
g.fillPolygon(poly);
// Dispose context
g.dispose();
// Send image to browser
response.setContentType("i mage/jpg") ;
OutputStream outputStream = new BufferedOutputStream(respo nse.getOut putStream( ), 1024);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncode r(outputSt ream);
encoder.encode(image);
outputStream.close();
%>
<html>
<head>
<%@ page import = "java.awt.*, java.awt.image.*, com.sun.image.codec.jpeg.*
</head>
<body>
<%System.setProperty("java
<%=GraphicsEnvironment.isH
<%=System.getProperty("jav
</body>
</html>
i still get the same exceptions
javax.servlet.ServletExcep
at org.apache.jasper.runtime.
at org.apache.jsp.itemlogo$js
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at java.security.AccessContro
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.ajp.tomcat4.Ajp
at org.apache.ajp.tomcat4.Ajp
at java.lang.Thread.run(Threa
root cause
java.lang.NoClassDefFoundE
at java.lang.Class.forName0(N
at java.lang.Class.forName(Cl
at java.awt.GraphicsEnvironme
at java.awt.image.BufferedIma
at java.awt.image.BufferedIma
at org.apache.jsp.itemlogo$js
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at java.security.AccessContro
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.ajp.tomcat4.Ajp
at org.apache.ajp.tomcat4.Ajp
at java.lang.Thread.run(Threa
when trying to run this file:
<%@ page import = "java.awt.*, java.awt.image.*, com.sun.image.codec.jpeg.*
System.setProperty("java.a
// Create image
int width=200, height=200;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB
// Get drawing context
Graphics g = image.getGraphics();
// Fill background
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// Create random polygon
Polygon poly = new Polygon();
Random random = new Random();
for (int i=0; i < 5; i++) {
poly.addPoint(random.nextI
random.nextInt(height));
}
// Fill polygon
g.setColor(Color.cyan);
g.fillPolygon(poly);
// Dispose context
g.dispose();
// Send image to browser
response.setContentType("i
OutputStream outputStream = new BufferedOutputStream(respo
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncode
encoder.encode(image);
outputStream.close();
%>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're on Windows you'd be editting catalina.bat this would be located somewhere like:
C:\jakarta-tomcat-4.0.3\bi
You want to find the line with CATALINA_OPTS, something like:
set CATALINA_OPTS=%CATALINA_OP
and change it to:
set CATALINA_OPTS=%CATALINA_OP
As I understand from your previous post that you don't have access to servlet deployment, YOU HAVE NO PERMISSION to change the system properties and I guess you cannot change the comcat startup parameter as well.
You should talk to your admin people to add the -Djava.awt.headless=true property to tomcat startup script. If they want do it, believe me, forget about the jfreechart, you'll need other charting system that doesn't depend on AWT.
SVG is one of them as I stated in the other Q and Kava chart is another option (it's not free). http://www.ve.com/?ref=gad1
You should talk to your admin people to add the -Djava.awt.headless=true property to tomcat startup script. If they want do it, believe me, forget about the jfreechart, you'll need other charting system that doesn't depend on AWT.
SVG is one of them as I stated in the other Q and Kava chart is another option (it's not free). http://www.ve.com/?ref=gad1
> how do i do this?
When you startup tomcat itself.
If thisn't an option then have a look at the pja toolkit.
When you startup tomcat itself.
If thisn't an option then have a look at the pja toolkit.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
argg i am so confused, i asked the tech to reboot the tomcat server with the headless mode set, here's the post:
---------------
hey i need to reboot the tomcat server with the following property set:
Add CATALINA_OPTS="$CATALINA_O PTS -Djava.awt.headless=true"
to the catalina.sh file so <%=GraphicsEnvironment.isH eadless()% > will show up as true in my jsp. it shows up as false right now
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
The line has been added to the Catalina.sh file and Tomcat4 has been restarted. Please let us know if there is anything else we can assist you with.
--------------------
so i load up the jsp..and lo behold: headless: <%=GraphicsEnvironment.isH eadless()% > = false sigh. did i not tell him correctly? he didnt do it right? or what? (#&@*#@* HEADLESS MODE! please advise, thanks.
I tried pja a while ago, it was just a disaster. I am going to try install Xvfb (XFree86-Xvfb-4.3.0-2.90.5 5.i386.rpm ) see if it helps. But the bottomline i think is headless mode will solve my problem easily just that i cant get it to turn on (*&@#*(#@! thanks again guys!
gaga
---------------
hey i need to reboot the tomcat server with the following property set:
Add CATALINA_OPTS="$CATALINA_O
to the catalina.sh file so <%=GraphicsEnvironment.isH
--------------------------
The line has been added to the Catalina.sh file and Tomcat4 has been restarted. Please let us know if there is anything else we can assist you with.
--------------------
so i load up the jsp..and lo behold: headless: <%=GraphicsEnvironment.isH
I tried pja a while ago, it was just a disaster. I am going to try install Xvfb (XFree86-Xvfb-4.3.0-2.90.5
gaga
ASKER
nevermind, dont have permission to install the rpm. /bangs head
back to trying set headless mode.
back to trying set headless mode.
he might have added the line to the end of the catalina.sh file :-)
ask him to add line in the beginning of the file right after the first comment section.
or you can as them to send you a copy of catalina.sh to see if they added correctly.
ask him to add line in the beginning of the file right after the first comment section.
or you can as them to send you a copy of catalina.sh to see if they added correctly.
> so <%=GraphicsEnvironment.isH eadless()% > will show up as true in my jsp. it shows up as false right now
Also check the value of the property:
<%= System.getProperty("java.a wt.headles s") %>
DO you have access to the startup logs, they'd also be worth checking.
Also check the value of the property:
<%= System.getProperty("java.a
DO you have access to the startup logs, they'd also be worth checking.
ASKER
giving up on this for now, when i have more time will try more or maybe switch hosting. thanks all
As objects says in this and your reference question, set the java.awt.headless=true method; I'd then check that this is being picked up with <%=GraphicsEnvironment.isH