Accessing XML data via an HTTPS site.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kalpana_Ahuja
Posted On:   Wednesday, July 17, 2002 08:00 AM

I have a Java - XML via HTTPS question that hopefully someone can help me figure out. I am attempting to access XML data contained at an HTTPS URL. I understand to connect to an HTTPS URL, I need to use the HttpsUrlConnection as I am in the following code snippet: import java.io.*; import java.net.*; import java.util.*; import java.security.*; import javax.net.ssl.*; public class Simple { public static void main(String[] args) throws Exception { //System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); //Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider(   More>>


I have a Java - XML via HTTPS question that hopefully someone can help me figure out.




I am attempting to access XML data contained at an HTTPS URL. I understand to connect to an HTTPS URL, I need to use the HttpsUrlConnection as I am in the following code snippet:



			
import java.io.*;
import java.net.*;
import java.util.*;
import java.security.*;
import javax.net.ssl.*;

public class Simple
{
public static void main(String[] args) throws Exception
{
//System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

URL url = new URL("https://dataport.somesite.com/my_servlet/xml?username=xx&password=yy&instance=zz");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setAllowUserInteraction(true);

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}



The data I get back is essentially the logon.jsp page at this site with my values plugged in.




What I don't understand is how do I access XML data at this URL? How do I specify to my paser, Xerces, to utilize the HTTPS connnection I have just established?


I have also tried to use the javax.xml.parsers library in the following code snippet:


			
import org.w3c.dom.*;
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
import javax.xml.parsers.*;

public class trial {

public static void main(String[] args) {
try {
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document doc = db.parse("https://dataport.somesite.com/my_servlet/xml?username=xx&
password=yy&instance=zz");
} catch (Throwable e) {
e.printStackTrace();
}
}
}



and get an SAXParseException of: The value of attribute "language" must begin with either a single or
double quote character. This I suspect is it is trying to parse the login.jsp page returning HTML.




The only documentation I have accessing this site is via an HTTP connection referencing the HTTPClient utility. Once the connection is established, the HTTPResponse, connection.Get, and connection.Post methods are used to access the XML at this URL. Are there any equivalents to this for a secured site?




Any help would be *immensely* appreciated.




- Kalpana

   <<Less

Re: Accessing XML data via an HTTPS site.

Posted By:   Laurent_Mihalkovic  
Posted On:   Wednesday, July 17, 2002 08:07 AM

Hi,


Do you really need to pass the parser the URL directly, or can you just establish the connection yourself, and then pass an InputStream to the parser? That would also keep things as two separate steps 1) acquire the InputStream for the proper source 2) parse a document represented by an InputStream.

cheers,
laurent

About | Sitemap | Contact