• Post Reply Bookmark Topic Watch Topic
  • New Topic

verifying a url for image

 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a url to an image something like
https://web.somewhere.com/images/someone/blah.jpg

Thi url is auto generated and sometimes it is not valid. Means sometimes there are not images as specified above and my webpage displays an X mark for image.

I am trying to detect this blank images which are non existant and replace it with a valid image.

I am getting an IO exception saying certificate expired even for valid urls on the following code.....

try {
HttpURLConnection urlC = (HttpURLConnection) new URL(agentPhotoURL).openConnection();
if (urlC.getResponseCode() == HttpURLConnection.HTTP_OK && "image/jpeg".equals(urlC.getContentType())){
return agentPhotoURL;
}
} catch (MalformedURLException e) {
StringBuffer strError = new StringBuffer();
strError.append("Error in ").append(this.getClass().getName()).append(".getAgentPhotoUrl(Agent)");
strError.append(" :URL=");
strError.append(agentPhotoURL);
strError.append(";");
logger.error(strError.toString(), e);
} catch (IOException e) {
StringBuffer strError = new StringBuffer();
strError.append("Error in ").append(this.getClass().getName()).append(".getAgentPhotoUrl(Agent)");
strError.append(" :URL=");
strError.append(agentPhotoURL);
strError.append(";");
logger.error(strError.toString(), e);
}


Can you suggest something to verify the https URL?

Thanks in advance
 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are getting an error that says your certificate has expired, why are you looking at URL parsing as a solution? It seems to me that you need to investigate the validity of your certificate.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I check whether the certificate is expired?

While doing a direct refrence to this url from my jsp pge, I am able to display this image correctly.

The problem is only when I use URLConnection to verify the existence of this url. Am i missing to pass some parameters in the connection.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I verified the certificate through browser and it is not expired.

Talking with various people I found that the certificate is not actually expired. It is the issue with client.

I am able to display the https page correctly from internet explorer.
The problem is only when I use URLConnection in java api to get response code.

That means I need to setup something in my java client. Reading through various article I found that browser keeps a set of certificates which are derived from the public key of the https site certificate. The certificate in my browser needs to be exported from browser and imported to a keystore which my java client (WSAD in local) can use.

I was told that I can use keytool.exe supplied aling with javac.exe and java.exe to do this in windows platform.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the issue is how is the keytool used.


C:\Program Files\ibm\websphere studio v5.1.1\runtimes\base_v51\java\jre\bin>keyt
ool -import -file C:\Documents and Settings\somename\My Documents\My certificates\
webProd.cer


is not the right usage. What am I missing here?

webprod.cer is the certificate I imported.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!