Create and send an XML document using JSP

<b>create and send an XML document using JSP</b>

Hi,

can anyone reccomend/post an article/code that discusses HOW to create and send an XML document using JSP

I read few threads on this topic, but none that I could answer me totally.

Thanks

I’ve been able to create an XML file

wondering if any of you how to read from the XML file, and traverse through its elements.

Any sample code, pointers on how to HTTP POST xml files?

Thanks
Noaman

To create the xml file in jsp just write it out programatically.

To traverse through the elements use commons digester.
I had to do this a couple weeks back and it took me about 2 hours to get it all working.

It’s very nice.
Read this article digester

cheers and good luck.

Thanks for that, I’ve got that working, I need to know how to HTTP POST the xml file

and, how to receive the same.

You’re getting into web services.

You might want to look into the Axis open source project.

Regards,

Nate

Yes Nate
I’m getting into web services in increments though (since I’m a newbie in it).

I want to send my XML document as a HTTP POST to a remote server.
How does it happen?

  1. Is it an HTML page that I display as XML and that is posted, or
  2. is it done via attachments, or
  3. using SOAP package, or
  4. any other, all of the above, one of the above, combination?

If you’re up to it you may want to take a look at the Spring Framework .
It can do most of the work for you about creating and publishing a web service. You can also use it to create your client.
It is really a greate framework, some of the best written code I’ve seen.

Cheers and good luck.

To be honest, I thought it would be as easy and looking at a sample code/demo/tutorials, learning, understanding and implementing

Thats how I’ve been learning for years. And this web services just doesnt seem to be working this way.

I’ve attached a file that I found over the internet, dont know if this will help me send and receive XML across

Thanks

Hi nouman,

This is quite a good article http://java.sun.com/developer/technicalArticles/xml/WebAppDev2/#code7
One good thing about SAX is you can extract what you want without having to parse the whole document.
gaza.

Isnt there something as similar as CURL library in php
/* Use CURL to execute XML POST and write output into a string */
$myvariable = curl_init( $this->myGatewayURL );
curl_setopt( $myvariable, CURLOPT_POST, 1 );
curl_setopt( $myvariable, CURLOPT_POSTFIELDS, $xmlRequest );
curl_setopt( $myvariable, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $myvariable, CURLOPT_TIMEOUT, 240 );

    $xmlResponse = curl_exec( $myvariable);

I was working on this code, and looking for confirmation

url = new URL("https://www.someotherwebsite.com.au/somepage.asp[/size][size=1]");
urlConn = url.openConnection();
// urlConn.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
urlConn.setRequestProperty(“Content-Type”, “text/xml”);

urlConn.setDoOutput(true);
dout = new DataOutputStream( urlConn.getOutputStream());

The line above gives the following exception
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

I am not having a SSL certificate in my server, and I am posting an xml file to a secure server. Is this the reason why I’m getting this exception
Which means I can ONLY post data across TO a secure server with a SECURE server.

Is this correct? If so is there anyway around that I can still post the file without installing the certificate?

Thanks