Results 1 to 2 of 2
Thread: HTTPS using certificate
- 09-19-2008, 03:24 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
HTTPS using certificate
Good morning.
I am fairly new to Java, so please be patient.
I am currently working on a small Java class to recover the header of a URL to determine the last modification date. I am using a previously developed Java class that does it for HTTP, but want to extend it to HTTPS. I know that in general certificates should be imported into a keystore file so that secure sockets can refer to them. However, I would like to be able to load the certificate from a file dynamically.
The original HTTP code is the following (using JDK 1.5)
Java Code:package com.xxx.utils.http; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; public class HttpFile { private String url = null; private HttpURLConnection urlConn = null; public HttpFile(String url) { this.url = url; if (this.url != null) { try { URL u = new URL(url); URLConnection conn = u.openConnection(); this.urlConn = (HttpURLConnection)conn; } catch (Exception ex) { ex.printStackTrace(); } } } public void Finalize() { if (this.urlConn != null) { this.urlConn.disconnect(); } this.urlConn = null; } public boolean exists() { try { if (this.urlConn != null) { return (this.urlConn.getResponseCode() == HttpURLConnection.HTTP_OK); } else { return false; } } catch (Exception ex) { return false; } } public long lastModified() { if (this.exists()) { return this.urlConn.getHeaderFieldDate("Last-Modified", 0); } else { return 0L; } } public static boolean exists(String url) { HttpFile hf = new HttpFile(url); boolean exists = hf.exists(); hf.Finalize(); return exists; } public static long lastModified(String url) { HttpFile hf = new HttpFile(url); long lastModified = hf.lastModified(); hf.Finalize(); return lastModified; } }
Last edited by MCJP; 09-19-2008 at 03:52 PM.
- 09-25-2008, 01:48 PM #2
Member
- Join Date
- Jul 2008
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
JDK 1.3 with HTTPS
By sriram in forum Advanced JavaReplies: 2Last Post: 01-21-2008, 10:51 PM -
Java certificate
By Nick15 in forum Java CertificationReplies: 2Last Post: 11-12-2007, 06:02 AM -
j2me.storage.RandomAccessStream certificate error
By asdfghjkl in forum CLDC and MIDPReplies: 1Last Post: 11-09-2007, 03:27 PM -
How do i read from a website with a certificate??
By karl in forum Advanced JavaReplies: 0Last Post: 07-12-2007, 04:25 PM -
Help needed with certificate used to access webpage
By karl in forum Advanced JavaReplies: 0Last Post: 07-10-2007, 09:13 PM
Bookmarks