aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes getting error -HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "getting error -HttpURLConnection" Watch "getting error -HttpURLConnection" New topic
Author

getting error -HttpURLConnection

vinoth sathiya
Ranch Hand

Joined: Sep 20, 2011
Posts: 36
Dear Friends,

I'm testing my application in HttpURLConnection httpcon.

I have written some code for http connection.

when i get httpcon.getInputStream(); means it showing

" Internal Server Error" throwing 500.
but when i run in eclipse workspace means its working. but in EAR means it showing this exception.


Any one help?


thanks in advance.

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I don't think there's anything we could say without seeing the complete stack trace, and the section of code that causes it.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

You'll need to trouble shoot why the server is causing this error. Catch the IOException, and in the catch block call getErrorStream() to read from this instead. This may give you the reason.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
vinoth sathiya
Ranch Hand

Joined: Sep 20, 2011
Posts: 36
Rob Spoor wrote:You'll need to trouble shoot why the server is causing this error. Catch the IOException, and in the catch block call getErrorStream() to read from this instead. This may give you the reason.





Thanks for response.


I have written catch block:

getErrorStream(): sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@28f2f1

getResponseMessage(): Internal Server Error

getResponseCode: 500

any solution?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Tim Moores wrote:I don't think there's anything we could say without seeing the complete stack trace
vinoth sathiya
Ranch Hand

Joined: Sep 20, 2011
Posts: 36
StackTrace is:
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:28080/prod/CM.racst.mlrp
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2012-01 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1227)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1221)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:910)
at prod.RPTaction.mulrptcallingval.generateReports(mulrptcallingval.java:1281)
at prod.RPTaction.mulrptcallingval.valmulrptcall(mulrptcallingval.java:721)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at prodweb.utility.XMLDTHttpServlet.getInfo(XMLDTHttpServlet.java:425)
at prodweb.utility.XMLDTHttpServlet.doGet(XMLDTHttpServlet.java:166)
at prodweb.utility.XMLDTHttpServlet.doPost(XMLDTHttpServlet.java:273)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:28080/prod/CM.racst.mlrp
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1174)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1899)
at java.net.HttpURLConnection.getHeaderFieldDate(HttpURLConnection.java:438)
at java.net.URLConnection.getExpiration(URLConnection.java:502)
at prod.RPTaction.mulrptcallingval.generateReports(mulrptcallingval.java:1272)
... 29 more


Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
That looks like client-side stack trace - there should be a server-side stack trace that points to the problem. If the server is not under your control, contact the server admin.
vinoth sathiya
Ranch Hand

Joined: Sep 20, 2011
Posts: 36
Hi, Server side stack trace is:


2012-01-23 15:14:04,754 INFO [STDOUT] java.lang.NullPointerException
2012-01-23 15:14:04,754 INFO [STDOUT] at CM.racst.getReportParameters(racst.java:132)
2012-01-23 15:14:04,754 INFO [STDOUT] at Framework.MailReportServlet.doGet(MailReportServlet.java:175)
2012-01-23 15:14:04,754 INFO [STDOUT] at Framework.MailReportServlet.doPost(MailReportServlet.java:914)
2012-01-23 15:14:04,754 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
2012-01-23 15:14:04,754 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
2012-01-23 15:14:04,754 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
2012-01-23 15:14:04,754 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595)


2012-01-23 15:14:04,754 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Panacea].[MailReportServlet]] Servlet.service() for servlet MailReportServlet threw exception
java.lang.NullPointerException
at Framework.MailReportServlet.doGet(MailReportServlet.java:805)
at Framework.MailReportServlet.doPost(MailReportServlet.java:914)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)




Thanks,
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So you need to investigate which object is null, and why that is.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

vinoth sathiya wrote:
Rob Spoor wrote:You'll need to trouble shoot why the server is causing this error. Catch the IOException, and in the catch block call getErrorStream() to read from this instead. This may give you the reason.





Thanks for response.


I have written catch block:

getErrorStream(): sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@28f2f1

getResponseMessage(): Internal Server Error

getResponseCode: 500

any solution?

Instead of printing the result of getErrorStream() you should read the contents from that InputStream. That would have given the error message the server is sending back to the client. In this case it's probably similar to the error found in the server logs, but you can use this technique if you don't have access to the server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting error -HttpURLConnection