access to mediator out of java application

hi Fan’s

i am looking for an example showing the call/HTTP post of a mediator sequence out of a java application/servlet using for example the Apache Jakarta HTTPClient.

thansk in advance

Michael

Here is some basic standard java to make an HTTP POST request.
If you need to call Mediator from a Servlet, you may consider writing a servlet
filter (deployed on the Mediator’s ServletPortal servlet) instead of a servlet.

/
** necessary imports
/
import java.net.;
import java.io.
;
import java.net.HttpURLConnection.;


/

** some convenience variables
/
String xml = “some xml”;
String prtl = “http://localhost:8081/mediator/ServletPortal”;
String seq = “?xbd.sequence.uri=http://localhost:8081/test/sequences/test.xml”
/

** set up the HTTP connection
/
URL u = new URL(prtl + seq);
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
conn.setRequestProperty(“Content-Type”,“text/xml; charset=utf-8”);
conn.setDoOutput(true);
conn.setDoInput(true);
/

** send data to Mediator
/
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
bw.write(xml);
bw.close();
/

** read response from Mediator
*/
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while((inputLine = br.readLine()) != null){
System.out.println(inputLine);
}
br.close();

dear Arp,

first of all thanks for the code part. coming back to this now, i have just one question:
assuming i am building a xml document using the dom model and then i like to post this document to the mediator what is the best and efficient way?
do i have to serialise this document first, so i can use a stream reader or is there a way out to avoid the serialisation process.

thanks

Michael

I think one popular way is to use a transformer to parse and output your document to whatever target you need. In your case your output target will the OutputStream you get from the HTTPUrlConnection object:

import javax.xml.transform.*;


Transformer t = TransformerFactory.newInstance().newTransformer();
DOMSource d = new DOMSource(some NODE);
StreamResult s = new StreamResult(conn.getOutputStream());
t.transform(d,s);

I will let the DOM/SAX gurus give you the final word on this, however.