Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create depending on type of URL

Status
Not open for further replies.

developerinlondon

Programmer
Jan 11, 2003
196
GB
I need to find a way to create an object based on the type of URL we get at runtime.

eg:
Code:
URL url = new URL ("[URL unfurl="true"]http://gizmo.com");[/URL]
URLConnection conn = (URLConnection) url.openConnection();

if (url.contains("https")) {
     conn = (HTTPSConnection) url.openConnection();
}
the above code obviously doesnt work, but hopefully this will explain what I want to achieve. Any easy way of doing this?
 
if (url.toString().startsWith("https")) {

}

maybe ?

--------------------------------------------------
Free Database Connection Pooling Software
 
thanks. that will solve the 'if' condition. but the definition at the bottom doesnt work as it doesnt let me redefine a URLConnection type object as HttpsURLConnection.
 
[javac] /opt/tomcat557/MultiFetcher/src/WEB-INF/classes/ntools/Jurl.java:116: cannot find symbol
[javac] symbol : method setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory)
[javac] location: class java.net.URLConnection
[javac] conn.setDefaultSSLSocketFactory(sslSocketFactory);

above is the exact error message. basically further down inside the 'if' block I use some methods specific to HttpsURLConnection which it fails to compile.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top