Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-2008, 04:24 PM
Member
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
MCJP is on a distinguished road
Default 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)

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;
	}
}
If you have any ideas, I would certainly appreciate it.

Last edited by MCJP; 09-19-2008 at 04:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-25-2008, 02:48 PM
Member
 
Join Date: Jul 2008
Posts: 20
Rep Power: 0
suprabha is on a distinguished road
Default
use ssl configuration of http..it will help..
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDK 1.3 with HTTPS sriram Advanced Java 2 01-21-2008 11:51 PM
Java certificate Nick15 Professional Certification 2 11-12-2007 07:02 AM
j2me.storage.RandomAccessStream certificate error asdfghjkl CLDC and MIDP 1 11-09-2007 04:27 PM
How do i read from a website with a certificate?? karl Advanced Java 0 07-12-2007 05:25 PM
Help needed with certificate used to access webpage karl Advanced Java 0 07-10-2007 10:13 PM


All times are GMT +2. The time now is 10:52 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org