# access to mediator out of java application

**URL:** <https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562>\
**Category:** Forum\
**Tags:** Former-Crossvision-Products, Service-Orchestrator\
**Created:** [May 25, 2004, 5:44pm UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562 "2004-05-25T17:44:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelK](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@MichaelK](https://techcommunity.softwareag.com/u/MichaelK)\
**Post date:** [May 25, 2004, 5:44pm UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562/1 "2004-05-25T17:44:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 26, 2004, 5:32am UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562/2 "2004-05-26T05:32:48Z")

</div>

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](http://java.net)._;  
import [java.io](http://java.io)._;  
import java.net.HttpURLConnection._;  
…  
…  
/_  
\*\* some convenience variables  
_/  
String xml = “some xml”;  
String prtl = “[http://localhost:8081/mediator/ServletPortal](http://localhost:8081/mediator/ServletPortal)”;  
String seq = “?xbd.sequence.uri=[http://localhost:8081/test/sequences/test.xml](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();

---

<div class="post-metadata">

**Author:** ![MichaelK](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@MichaelK](https://techcommunity.softwareag.com/u/MichaelK)\
**Post date:** [May 26, 2004, 12:54pm UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562/3 "2004-05-26T12:54:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 26, 2004, 2:02pm UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562/4 "2004-05-26T14:02:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:39pm UTC](https://techcommunity.softwareag.com/t/access-to-mediator-out-of-java-application/58562/5 "2021-04-02T14:39:20Z")

</div>


