• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need urgent help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you closing these connections ??
 
balakrishna gottipati
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i am not closing those connections. This this because of open connections.
 
Sandeep Sanaboyina
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be. Either way closing a conection is always a good practice.
 
balakrishna gottipati
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

balakrishna gottipati wrote: . . . Please review it. Is that ok

No. It is illegible without code tags.
 
I am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic