wood burning stoves*
The moose likes Java in General and the fly likes Need urgent help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need urgent help" Watch "Need urgent help" New topic
Author

Need urgent help

balakrishna gottipati
Greenhorn

Joined: Apr 06, 2010
Posts: 8
Hello All,

I have a requirement to show different type of image based on their availablity.

like there are two types of images (SWF, JPG) on webserver. My webserver and appserver are two different servers.

on click on a link i need show flash image if SWF files exist or show a JPG image if the flash image does not exist. and not to show anything if none of them exists

Since all the images are in webserver how to check the images availability . Can anyone advise on this.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You can just do an HTTP request to the web server and if you get an HTTP status code 404 (Not Found), then the resource doesn't exist on the web server.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Please don't simply say "need help"; we need to know what sort of help you need. And we never use words like "urgent" on JavaRanch.
balakrishna gottipati
Greenhorn

Joined: Apr 06, 2010
Posts: 8
Thanks everyone for your replies.

I have used the following code for checking the images existence.

String getPath = getProtocol+"://"+getDomain+"/catalogImages";
try {
url = new URL(getPath + "/"+fgPartNumber+".JPG");
URLConnection myConn = (HttpURLConnection)url.openConnection();
myConn.setRequestProperty("User-agent","Mozilla/4.0");
myConn.connect();
inputStream = myConn.getInputStream().toString();
smallImage = "true";
} catch (FileNotFoundException ex) {

smallImage = "false";
ex.printStackTrace();
}

used that part of code for all the three images and checking whether they exist or not, and it is working fine.

But the issue it is only working for sometime after 2 to 3 days i am getting a exception saying
java.io.IOException: Server returned HTTP response code: 403 for URL:
[9/9/10 0:40:42:733 EDT] e649f1 SystemErr at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:794)
[9/9/10 0:40:42:733 EDT] e649f1 SystemErr at org.apache.jsp._part_5F_information._jspService(_part_5F_information.java:726)
[9/9/10 0:40:42:733 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
[9/9/10 0:40:42:733 EDT] e649f1 SystemErr at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:388)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:745)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:843)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[9/9/10 0:40:42:734 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1036)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:544)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:210)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
[9/9/10 0:40:42:735 EDT] e649f1 SystemErr at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1036)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:544)
[9/9/10 0:40:42:736 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:210)
[9/9/10 0:40:42:737 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:139)
[9/9/10 0:40:42:737 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:332)
[9/9/10 0:40:42:737 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:120)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:250)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:652)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:448)
[9/9/10 0:40:42:738 EDT] e649f1 SystemErr at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:937)

If i restart the application server it is again working for 3 to 4 days.

Can anyone please help me out in this plzz
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Are you closing these connections ??


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
balakrishna gottipati
Greenhorn

Joined: Apr 06, 2010
Posts: 8
No i am not closing those connections. This this because of open connections.
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
May be. Either way closing a conection is always a good practice.
balakrishna gottipati
Greenhorn

Joined: Apr 06, 2010
Posts: 8
try {
url = new URL("....");
System.out.println("first" + url);
URLConnection myConn = (HttpURLConnection)url.openConnection();
myConn.setRequestProperty("User-agent","Mozilla/4.0");
//myConn.connect();
System.out.println("lookkkkkkkk" +((HttpURLConnection)myConn).getErrorStream());
InputStream in = myConn.getInputStream();
String check = in.toString();
smallImage = "true";
in.close();
((HttpURLConnection)myConn).disconnect();

} catch (Exception ex) {

ex.printStackTrace();
smallImage = "false";
}


i have changed the code. Please review it. Is that ok
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
balakrishna gottipati wrote: . . . Please review it. Is that ok
No. It is illegible without code tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need urgent help
 
Similar Threads
Convert SWF to jpg/jpeg/bmp/png
Having static files available in a cloned environment
Context Root be only /
How to display flash file(.swf) in java application?
Can we use to create an EBook