Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Thursday, March 7, 2013

File not found issue with tomcat: URL Encoding

I have to admit, today was lot better than yesterday. My struggle started when I was asked to quickly ( I mean it, in 10 minutes or so..) deploy a POC application on amazon ec2 instance. It is a windows 2008 server, so installed tomcat as service under "Program Files" and installed java 7. Hoping my 5 pages application will fly in no time that's when I noticed an error stack on the tomcat console :(. Main root cause was:

"Caused by: java.io.FileNotFoundException: File 'C:\Program%20Files\apache-tomcat-7.0.29\webapps\xyz\WEB-INF\classes\createData.sql' does not exist"

I could see the file under WEB-INF\classes and that's when I realized that my URL is getting encoded, hence all spaces are getting replaced with %20.

I had below line of code which was causing the issues since there is no folder with name "Program%20Files" in the system.

String path = FileUtils.class.getClassLoader().getResource("createData.sql").getPath();
List readLines = FileUtils.readLines(new File(path));
I wrapped it using URI and BOOM problem went away.

String path = FileUtils.class.getClassLoader().getResource("createData.sql").getPath();
List readLines = FileUtils.readLines(new File(new URI(path).getPath()));

as usual I happy soul again.
Manisha                

Tuesday, July 24, 2012

JMeter is not good tool for finding Request per second

I played around with performance tools a lot in my last project and this was one blog which I never got to finish. My goal was to come with a tool which is best for benchmarking an application on Tomcat. While working with JMeters all the numbers compare to AB tool were low, I suspected Tomcat and started reading the tomcat performance tuning book and found below lines.

(Page 136 - Chapter 4 - Tomcat Performance Tuning ) - JMeter's HTTP client is slower than that of AB or siege. You can use JMeter to  find out if a change to your webapp, your tomcat installation or your JVM, accelerated or slows the response times of the webpage however you cannot use JMeter to determine the server's maximum number of requests per second that it can successfully serve because of JMeter's HTTP client appears to be slower than Tomcat's server code.


http://books.google.com/books?id=vJttHyVF0SUC&pg=PA136&lpg=PA136&dq=%22maximum+number+of+requests+per+second%22++jmeter&source=bl&ots=i-5yv-tLh0&sig=0JnmfPtq2PwKWdEDkfSamUQMBEg&hl=en&sa=X&ei=6L0QT-3DGc6lsQKmio2LBA&ved=0CDIQ6AEwAg#v=onepage&q=%22maximum%20number%20of%20requests%20per%20second%22%20%20jmeter&f=false

I thought it was really valuable find :)
Manisha 

Thursday, July 19, 2012

JSP/Tomcat 6 "org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException"

We noticed "org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException" on our JSP pages in the morning. I have copied the entire exception stack trace below for reference.

My first guess was the jsp pages have some issue where we are trying to access some index which has not been assigned. But we realized it's the server which ran our of space. so the first exception was "
java.io.IOException: There is not enough space in the file system.".

Why tomcat has to throw such an non intuitive error message? Why?  Not sure if it's tomcat's fault or the underneath framework is messing up.

==============================================================
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException
 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 sun.reflect.GeneratedMethodAccessor209.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 java.lang.reflect.Method.invoke(Method.java:600)
 org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
 java.security.AccessController.doPrivileged(AccessController.java:284)
 javax.security.auth.Subject.doAsPrivileged(Subject.java:727)
 org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
 org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

root cause
java.lang.ArrayIndexOutOfBoundsException
 java.io.OutputStreamWriter.write(OutputStreamWriter.java:250)
 java.io.Writer.write(Writer.java:152)
 org.apache.log4j.helpers.CountingQuietWriter.write(CountingQuietWriter.java:44)
 org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:308)
 org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:236)
 org.apache.log4j.WriterAppender.append(WriterAppender.java:159)
 org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230)
 org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65)
 org.apache.log4j.Category.callAppenders(Category.java:203)
 org.apache.log4j.Category.forcedLog(Category.java:388)
 org.apache.log4j.Category.error(Category.java:319)
 com.jpmc.tao.common.logging.Logger.error(Logger.java:167)
 com.jpmc.tao.presentation.controller.FrontController.process(FrontController.java:61)
 org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 sun.reflect.GeneratedMethodAccessor225.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 java.lang.reflect.Method.invoke(Method.java:600)
 org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
 java.security.AccessController.doPrivileged(AccessController.java:284)
 javax.security.auth.Subject.doAsPrivileged(Subject.java:727)
 org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
 org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
 java.security.AccessController.doPrivileged(AccessController.java:251)
 java.security.AccessController.doPrivileged(AccessController.java:251)
 org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)
 org.apache.jasper.runtime.PageContextImpl.access$1000(PageContextImpl.java:71)
 org.apache.jasper.runtime.PageContextImpl$11.run(PageContextImpl.java:664)
 java.security.AccessController.doPrivileged(AccessController.java:251)
 org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:662)
 org.apache.jsp.default_jsp._jspService(default_jsp.java:54)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 sun.reflect.GeneratedMethodAccessor209.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 java.lang.reflect.Method.invoke(Method.java:600)
 org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
 java.security.AccessController.doPrivileged(AccessController.java:284)
 javax.security.auth.Subject.doAsPrivileged(Subject.java:727)
 org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
 org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
==============================================================

Any thoughts?
Manisha

Sunday, October 30, 2011

Accessing JMX remotely via VisualVM from jetty

During my testing I was getting some of weird numbers in GNUPlot so wanted to see what is happening inside JVM.

My application was deployed on Jetty 6.x version. I uncommented jetty-jmx.xml and passed it as parameter during startup i.e. java - jar start.jar etc/jetty-jmx.xml. Hoping that jmx connectors will start on RMI default 1099 port. Started visualvm and tried connecting to my remote jvm using the hostname:1099 port. Got connection refused exception.

I googled and found it's not to do it. There were million things suggested on the net. i.e. start jetty with remote-jmx parameter by specifying the port and then establish ssh tunnel on that port and then connect visualvm to it.

My pair(Chris) and I did all those but somewhere within me I was certain that I don't have to do all these ceremony to connect and it's because we use to connect to Tomcat similarly and the only configuration which we added was jmx related in catalina.sh file.

We followed couple of blogs and no success. Then thought of upgrading the jetty version to 8.x and followed the same steps of uncommenting "createRegistry" and "ConnectorServer" portion within jetty-jmx.xml file.

Then started the server. I got same error. Then found out the we have to specify the ip address of remote host during jetty start up.

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=YOUR_IP -jar start.jar etc/jetty-jmx.xml


Once you will do that you will notice that a URL will get printed on you start up console, copy the URL and change the localhost with your ip address and put the same on to visualvm. Boom it got connected. Now I know and it's simple. For me the url was "service:jmx:rmi:/hostname/jndi/rmi://YOUR_IP:1099/jettyjmx"

Just incase any of you are looking for parameters for enabling stuff in tomcat. Here are they.

In catalina.sh file add the below line anywhere in the beginning around line number 150 :P.

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=YOUR_IP"

Then connect using your_ip:9004 in visualvm.


Did not have lots of fun
Manisha