views:

63

answers:

2

We have a local database of our products without the price. To get the price, we need to POST an XML file containing the product ID and the credential of our company to the manufacturer. The manufacturer will send back the same XML file and will add the price in a new tag. I need to parse that file to get the price.

Here is a part of the manufacturer specification :

The client must first build a Request XML document (see specific examples below).

Once the XML document has been built the client software must initiate an HTTPS connection with the server. The client must present its client certificate as part of this process in order to authenticate itself with the server. If client certificate authentication is not possible then the UserID and Password fields in the XML must be populated with a valid UserID/password combination on the server.

After the HTTPS session has been established the client must POST the XML document to the server.

The server will process the document and return any information that it is able to provide. It is important to note that the server will not build a new document, but will add information to the request document. The client must then parse this XML document to extract the required information.

I was thinking of using AJAX to do that. But after a couple of minutes i figured out that I couldn't do that for the following reason :

  • It impossible to use cross-side AJAX
  • I can't create an XML file in JavaScript
  • The credential will be in clear text in the XML file

I don't think I can do that with PHP either (server side).

Are my last option a Java Applet or Flash ActionScript ? How would you do that ?

A: 

How often does this need to happen? Once a day? Every request?

I would do this all behind the scenes with something like cURL in PHP or LWP in Perl. I'm sure there is something similar in Java.

I don't think you can do this client-side. Even if you could, you probably shouldn't.

Chris Kloberdanz
Can you explain how should I use cURL to do that ?
Jean-Philippe Brabant
I don't have any examples handy, but http://us2.php.net/curl will get you started. You can also accomplish the same thing with output streams. Here's an example: http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
Chris Kloberdanz
+1  A: 

Send the key parameters for the request to the server, use HttpClient or Apache Axis on the server to build the request for the manufacturer and post it. Collect the result (again on the server), process it and send the price back to the browser.

Aaron Digulla
@Jean-Philippe Brabant - You Basically want a restful web service client. I would actually recommend the use of Apache CXF over Axis. Although you could actually use the HttpURLConnection class. All of these options are Java
jconlin