Post  XML Payload to other application in java

Hi All,
I am trying to post an xml file as a string to another url using a HttpURLConnection,OutputStream classes. My code will look like below:
String xmldata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<cust><firstNmTxt>"
+ firstNmTxt
+ "</firstNmTxt><midInitTxt>"
+ lastNmTxt
+ "</midInitTxt><lastNmTxt>"
+ lastNmTxt
+ "</lastNmTxt>"
+ "<addrLine1Txt>"
+ addrLine1Txt
+ "</addrLine1Txt><addrLine2Txt>"
     + addrLine2Txt
+ "</addrLine2Txt><cityNm>"
     + cityNm
     + "</cityNm><postlStCd>"
     + postlStCd
     + "</postlStCd><zipCd>"
     + zipCd
     + "</zipCd><phoneNum>
     + phoneNum
     + "</phoneNum><emlAddrTxt>"
     + emlAddr
     + "</emlAddrTxt></cust>";
HttpURLConnection con = null;
OutputStreamWriter output = null;
try
URL portalUrl = new URL("http://sampleurl/PayloadsServlet");
con = (HttpURLConnection) portalUrl.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
     System.out.println("Requested Method IS : " + con.getRequestMethod() + " AND Requested URL IS:" + con.getURL());
con.setRequestProperty("Content-Type", "text/xml");
con.connect();
output = new OutputStreamWriter(con.getOutputStream());
output.write(xmldata);
     System.out.println("CONTENT:" + output.toString());
//Clean-up resources
output.close();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
while ((line = reader.readLine()) != null)
     System.out.println("Response From Application URL:" + line +"\n");
catch (Exception e)
// Handle exception
e.printStackTrace();
// Log exception          
finally
if (output != null)
output.close();
if (con != null)
con.disconnect();
The issue with this code is when I am printing the response from the URL, I couldn't see the data I am sending( i.e.xml payload) But I could see the the output of the URL page I have given to connect.
Do I need to commit the "output" after writing it to the URL's Outputstream?
Please anybody help me with this. I am in hurry.
Thanks in Advance,
NB
Edited by: user7470167 on May 6, 2011 3:33 AM

This can't be done.
Windows Token are unique to each process.  To pass a token from one process to another in Windows, you need to call DuplicateHandle() which requires process handles in each process.
thanks
Frank K [MSFT]
Follow us on Twitter, www.twitter.com/WindowsSDK

Similar Messages

  • How to run Other application from Java

    I want to run other applications such as IE.exe, notepad.exe from Java? How can I run?

    Dear Friend, the following is the code to open IExplorer from Java Program
    class RunTimeTest {
    public static void main(String args[]) {
    try {
    Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
    catch(Exception e) {
    [\code]
    ALL THE BEST
    Shiva                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Unable to receive special characters in XML using UTL_HTTP request from Other application

    Hi Team,
    We are using SOAP request in Oracle Application to Pull XML data from Other application.I am using below commands before receving response but still i am unable to receive special charcters/Spanish Charcters in XML.
    utl_http.set_body_charset(v_http_req, 'UTF-8');
    utl_http.set_header (v_http_req, 'Content-Type', 'text/xml');
    Thanks and Regards,
    Raghul

    Hello,
    Just when you think that you know everything, it is slammed in your face that you don't. The .Mac member name field in the System Preferences DOES NOT take your whole e-mail address. It only takes your user name or whatever comes BEFORE the "@" symbol. There was absolutely nothing wrong with my MacBook Pro (other than ther brain dead user).
    Sorry for wasting your time...
    If we learn from our mistakes, then I obtained my PhD years ago,
    Dr. Z.

  • How to post  xml over http

    Hi experts,,
    My idea is to post XMl file from client application to server.
    user.XMl file will be created then and there dynamically based on user entered data.
    For this i have a .java program in client application.
    And one important thing is My XMl file contain image in binary data,, which is in Base64Encoded format.
                      <?xml version="1.0" encoding="UTF-8"?>
                    <FileAttachment>
                                         <UserName>krish</userName>
                                         <password>rao</password>
                                        <image type="jpg">
                                                   <PictureData>
                                                    QAAAAIAGtaMS2/u6RnIAAAAIYAAAAKAAAAYm
                                                          l0bWFwLmJtcHPybWOAADMg1gBiVihm
                                                      ZJAAiwcA8RE+CIaB/6iAYj4AUEsBAhQAFAAAAAgAa1oxLb+7
                                                     pGcgAAAAhgAAAAoAAAAAAAAA
                                                      AAAgALaBAAAAAGJpdG1hcC5ibXBQSwUGAAAAAA
                                                    EAAQA4AAAASAAAAAAA
                                             </PictureData>
                                        </image>
                     </FileAttachment>My .xml like above.. i have to post it to server . Some thing like http://myserver:8080/Requesthandler.java which recive the xml and parse it and do some other things.
    And one thing is My server at some location and my client application at other location.
    Plz do me some help as early as possible

    Thak u
    but i am sitting in front of laptop but i cant find perfect code match to me.
    Give me link if possible,
    <Product>
      <SKU>99238</SKU>
      <Description>Super Gidgetidoo</Description>
      <Picture>
    Content-Description: File encoded with ENCODE64.EXE.
    Content-Disposition: attachment; filename="foo.zip"
    Content-Transfer-Encoding: BASE64
    Content-Type: application/octet-stream
    UEsDBBQAAAAIAGtaMS2/u6RnIAAAAIYAAAAKAAAAYm
    l0bWFwLmJtcHPybWOAADMg1gBiVihm
    ZJAAiwcA8RE+CIaB/6iAYj4AUEsBAhQAFAAAAAgAa1oxLb+7
    pGcgAAAAhgAAAAoAAAAAAAAA
    AAAgALaBAAAAAGJpdG1hcC5ibXBQSwUGAAAAAA
    EAAQA4AAAASAAAAAAA
      </Picture>
    </Product> If my xml like above and its created dynamically based on client input.
    I find some code to post above xml, But it post an XMl file in hard disk
    it uses output stream to post , ie read every byte in xml and write to out put stream.like below
    response.setContentType("text/xml");
          response.addHeader("Content-Disposition", "attachment; filename="
              + fileName);
          response.setContentLength((int) xml.length());
          FileInputStream input = new FileInputStream(xml);
          buf = new BufferedInputStream(input);
          int readBytes = 0;
          while ((readBytes = buf.read()) != -1)
            stream.write(readBytes);But i want to post xml file as it is , means whole xml document as an element
    let me help

  • Xml payload related problem

    Hi ALL
    Currently I am doing a scenario in which i m encrypting the incoming xml payload(field by field) in java mapping and then decrypting it with in the adapter module.Now problem that i m facing is that after encryption if i get some special characters, the resulting xml payload becomes invalid and will not be parsed.

    hi,
    Try to put it into CDATA.
    <script>
    <b><![CDATA[</b>!@!#!@#!@#!@$@#$<b>]]></b>
    </script>
    regards,
    Wojciech
    Message was edited by: Wojciech Gasiorowski

  • How to pass XML payload to HTTP POST Service.

    Hi All,
    I am calling a RestFul service using Http Post method.
    If the payload type is "url-encoded" then my directly assignment of values using assign activity is working fine.
    But when i change the payload type to "xml" , It's erroring out saying the value is not provided for the parameters..
    You can also try this using below details to reproduce the issue.
    Details:
    =====
    URL : http://api.geonames.org/postalCodeSearch
    Used HttpBinding as reference in composite.
    XSD :
    <?xml version= '1.0' encoding= 'UTF-8' ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org" targetNamespace="http://www.example.org"
    elementFormDefault="qualified">
    <xsd:element name="geonames">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="totalResultsCount" type="xsd:integer"/>
    <xsd:element name="code" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="postalcode" type="xsd:string"/>
    <xsd:element name="name" type="xsd:string"/>
    <xsd:element name="countryCode" type="xsd:string"/>
    <xsd:element name="lat" type="xsd:float"/>
    <xsd:element name="lng" type="xsd:float"/>
    <xsd:element name="adminCode1" type="xsd:string"/>
    <xsd:element name="adminName1" type="xsd:string"/>
    <xsd:element name="adminCode2" type="xsd:integer"/>
    <xsd:element name="adminName2" type="xsd:string"/>
    <xsd:element name="adminCode3" type="xsd:integer"/>
    <xsd:element name="adminName3" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="Input">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="postalcode" type="xsd:string"/>
    <xsd:element name="username" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    We need to send following input values to the service.
    postalcode = 90110
    username =siddhardha
    Can someone let me know how to make it work with XML payload.Looks like i am not constructing the XML payload correctly in assign.
    Please send me the sample to [email protected].
    Thanks in advance,
    Siddhardha.

    Sid,
    I am still trying the same, here we need to change the input type to mimeXml
    have a look at this link....
    https://blogs.oracle.com/reynolds/entry/oracle_http_adapter
    I am trying multiple ways, everytime i get the same below error...
    <messages>
    <Invoke1_Request-Response_InputVariable_2>
    <part name="Input">
    <Input>
    <postalcode>90110</postalcode>
    <username>siddhardha</username>
    </Input>
    </part>
    </Invoke1_Request-Response_InputVariable_2>
    <Invoke1_Request-Response_OutputVariable>
    <part name="geonames">
    <geonames>
    <status message="Please add a username to each call in order for geonames to be able to identify the calling application and count the credits usage." value="10"/>
    </geonames>
    </part>
    </Invoke1_Request-Response_OutputVariable>
    </messages>
    Thanks,
    N

  • Httpservice POST headers/XML payload formation

    I am trying to use the Quickbase API (see reference below) with a POST.  I am having trouble forming it; specifically, I am clueless as to how to format the header (headers="").  I think the XML Payload is correct, but who knows.  Thanks for your help!
    Quickbase API reference:
    Example XML Request
    POST /db/6c5xatxy HTTP/1.0
    Content-Type: application/xml
    Content-Length: 88
    QUICKBASE-ACTION: API_GetRecordInfo
    <qdbapi>
    <rid>4</rid>
    <ticket>1_6c6482m9_j36_c7mdvh9cmmtn9c8qtr5qchvw33v</ticket>
    </qdbapi>
    My code:
    <fx:Declarations>
      <s:HTTPService id="serviceQBPost" method="POST"
                     url="https://www.quickbase.com/db/beu45unrw"
                 headers="Content-Type: application/xml Content-Length: 88 QUICKBASE-ACTION: API_GetRecordInfo"
             result="serviceQBPost_resultHandler(event)"
             fault="serviceQBPost_faultHandler(event)">
                     <s:request xmlns="">
               <qdbapi>
                 <rid>4</rid>
                         <ticket>1_6c6482m9_j36_c7mdvh9cmmtn9c8qtr5qchvw33v</ticket>
               </qdbapi>
             </s:request>
      </s:HTTPService>
    </fx:Declarations>

    Well, I solved my performance problem by using XMLSocket,
    instead of HTTPService - a shame, since HTTPService is more
    appropriate.
    Question: how do I determine whether Adobe knows about this
    issue, and whether they care?

  • Installing BDB XML and including it into a java application

    Hi there :)
    I'm new to BDB XML and I've got some questions about it :
    1/ The documentation says about BDB XML that it is based on BDB. Does it mean that I need to install the standard BDB first to use BDB XML ? (I'm pretty sure I don't have to but I would like a confirmation =))
    2/ I want to developp a web application which will use BDB XML. The documentation says I need to add some jars into my project to use it but do I need to install it on my computer (Windows XP) first ? (with the .msi file ?)
    3/ Where will the xml files be physically stored after I add them into the database ? (what is the default database folder on the hard disk ?)
    Thank you for you help :)
    Regards,
    Gary

    Hi Gary,
    1) You need to install only DB XML. BDB is bundled with DB XML, so you don't have to worry.
    2) Yes, you need to add two jars: db.jar and dbxml.jar. But these jars depend on native DB XML libraries, so you will have to install DB XML anyway: only jars wouldn't be sufficient. Moreover, I would recommend to install DB XML from sources providing the --enable-java+ flag to the buildall.sh script
    3) All XML files will be stored in a container or containers (depending on how many of those you will decide to utilize in your application). It is up to you where you are going to reside DB XML environment/containers -- DB XML is quite low-level XML-database.
    Hope this helps,
    Vyacheslav

  • Server.xml: Parent Application Tag: java.lang.ClassNotFoundException

    Hi,
    I have 2 EAR´s deployed on an OC4J (10.1.2) Standalone:
    uncomsso - SingleSignOn
    uncomtvv - Main App.
    My server.xml is as follows:
    <application name="uncomsso" path="../applications/singlesignon.ear" />
    <application name="uncomtvv" path="../applications/uncomtvv.ear"
    parent="uncomsso"/>
    I have many jars in the singlesignon.ear/lib that must be shared to uncomtvv.ear.
    I tought that with the parent application tag, this could be possible, but even with the tag on the server.xml, I´m getting java.lang.ClassNotFoundException.
    How can I make the jars on the singlesignon.ear/lib be available to the uncomtvv.ear classes?
    Any clarification will be appreciated,
    Thanks,
    Murilo

    Actually, it seems to search the classes first on the WEB-INF/classes of uncomtvv web module and then, instead of searching the lib directory of uncomtvv EAR, it searches the lib dir of singlesignon EAR and finally the instance classloader...
    Anybody can explain me why it doesn´t look for the classes on the lib dir of the uncomtvv EAR?
    ( The jars in lib dir of uncomtvv.ear are referenced by the MANIFEST.MF of META-INF web-module )
    Thanks,

  • How to get return value from java and read by other application?

    i want to read return value from java and the other application read it.
    for example:
    public class test_return {
        test_return(){
        public int check(){
            return 1;
        public static void main(String args[]){
           new test_return().check();
    }from that class i make as jar file. How to read the return value (1) by other application?
    thx..

    If your installer is requiring some process it invokes to return a particular value on failure, then the installer is seriously broken. There are a bazillion commands your installer could invoke, and any of them could fail, which in turn could invalidate the entire install process, and any of them could return any value on failure. The only value that's consistent (in my experience) is that zero means success and non-zero means failure, with specific non-zero values being different in different programs.
    About the only control you have over the JVM's exit code is that if your main method completes without throwing an exception, the JVM will have an exit code of 0, and if main throws an exception (either explicitly or by not catching one thrown from below), it will be non-zero. I'm not even sure if that's guaranteed, but I would guess that's the case.
    EDIT: I'm kind of full of crap here. If you're writing the Java code, you can call System.exit(whatever). But nonetheless, if your installer requires certain exit codes from any app--java or otherwise--you have a problem.
    Edited by: jverd on Oct 29, 2009 1:27 AM

  • Drag and Drop - Java -- other application

    Hi,
    I'm writing an application, which requires to transfer the content of textfields through Drag and Drop to any other application.
    Basically this works, but in combination with some applications, e.g. Mozilla, it happens, that the DragSourceListener doesn't recognize, that the Drag and Drop - operation is finished.
    Because of this I get an InvalidDnDOperationException, when I try to start a new Drag and Drop - operation.
    Can anyone tell me, how to solve the problem?
    thanks in advance
    Christoph

    And I get the:
    java.lang.NullPointerException
         at oracle.jbo.uicli.jui.JUPanelBinding.bindUIControl(JUPanelBinding.java:808)
         at empapppack.empframe.jbInit(empframe.java:116)
         at empapppack.empframe.<init>(empframe.java:51)
         at emppapppack.Application1.<init>(Application1.java:13)
         at empapppack.Application1.main(Application1.java:50)

  • How can I communicate with other applications from my Java application?

    Hello,
    I need help about how can i communicate with other application(say textpad.exe/wordpad.exe/MS word.exe) from my Java program.
    More precisely, I need to know how i can get the current position of the cursor whether it is in any .txt/.doc files, then I may write some text in my java application and click a button and then my program will append the line(string) in that position of the file which is running under another appliction(Notepade.exe/MSword.exe).
    Please provide me some help.

    I may be wrong (and anyone, please correct me if so), but Java may not be the best tool for something such as this. I envision that you'd have to make some OS calls such as calls to the user32.dll, and while this can be done through the JNI, you'd still have to have a C or C++ program doing the dirty work.

  • Executing any other applications from a java application

    how can i execute or invoke other applications on the pc
    from a java application?

    Runtime.getRuntime().exec("dir");

  • 'Unable to Launch Application Error' - Java Web Start Running Under MS IIS.

    I am attempting to render the following .jnlp in MS IE:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for LottoMadness Application -->
    <jnlp
       codebase="http://localhost/LottoMadness/"
       href="LottoMadness.jnlp">
       <information>
         <title>LottoMadness Application</title>
         <vendor>Rogers Cadenhead</vendor>
         <homepage href="http://localhost/LottoMadness/"/>
         <icon href="lottobigicon.gif"/>
       </information>
       <resources>
         <j2se version="1.5"/>
         <jar href="LottoMadness.jar"/>
       </resources>
       <application-desc main-class="LottoMadness"/>
    </jnlp>I've deployed the .jnlp, .gif, and .jar to MS IIS, running locally on my PC.
    When I attempt to render the .jnlp in IE I obtain an 'Application Error' window stating 'Unable to Launch Application'. Clicking details gives me:
    com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://localhost/LottoMadness/LottoMadness.jnlp
         at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
         at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
         at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
         at com.sun.javaws.Launcher.launch(Unknown Source)
         at com.sun.javaws.Main.launchApp(Unknown Source)
         at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
         at com.sun.javaws.Main$1.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)I have configured MS IIS for Web Start, by setting the Extension/Content Type fields to .jnlp and application/x-java-jnlp-file.
    (The .jnlp is basically from 'Programming with Java in 24 Hours', as this is the book I am learning Java from.)

    AndrewThompson64 wrote:
    I am not used to seeing references to a local server that do not include a port number.
    E.G. http://localhost:8080/LottoMadness/
    I have deployed the following HTML (HelpMe.html) to the web server:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
         <title>Untitled</title>
    </head>
    <body>
    Help Me!
    </body>
    </html>When I attempt to render the URL in IE, I see the page just fine. The URL is use is:
    http://localhost/LottoMadness/HelpMe.htmlSo, I think my web server setup and usage is ok.
    >
    As an aside, what happens if (your MS IIS is running and) you click a direct link to..
    [http://localhost/LottoMadness/LottoMadness.jnlp|http://localhost/LottoMadness/LottoMadness.jnlp]
    When I click this link I get the error and exception I cited in my previous post.

  • Error while posting xml file to URL using URLConnection

    Hello everyone,
    I am facing an issue from long time related to URLConnection. If this would be resolved by your help then I would be very grateful to you.
    One application which posts xml file to URL hangs and after waiting for 5 mins it throws 504 error:
    java.io.IOException: Server returned HTTP response code: 504 for URL: http:hostname.
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:715)
    Same application is running fine without error on another environment from last 5 years. But on another env it is erroring out from the day 1.
    We have many workarounds in place none worked.
    I tried to use HttpClient from apache but that too hanged at URLConnection.getInputStream() method call.
    App is running on iPlanet web server 6.1 using JDK 1.4.0_03
    We still dont know why this program hangs at that particular line in only one env but many times it runs fine. That means 30% of the times it posts xml file without error but 70% times it errors out. So our program logic is to retry until post is successful.
    Once this issue is resolved we will remove the logic of trying again and agian.
    Please provide inputs.
    Thanks,
    Nitin

    The HTTP response 504 means that the server, acting as a gateway, has not received a response from an upstream server in the time it expected.
    I think this is problem is due to the remote server that receives the XML and takes too long to return a response to the local application that posted the XML.
    Try HttpClient and set the timeout variable of the HttpClient instance used.
    Here http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/PostXML.java?revision=480424&view=markup
    a Post XML sample.
    NB: HttpClient > setTimeout method is deprecated. See : http://jakarta.apache.org/commons/httpclient/apidocs/index.html for an alternative
    Hope That Helps

Maybe you are looking for

  • SYNC no longer in System Pref

    PHD worked for a time but now Sync is no longer found in System Preferences and the home icons on the tool bar at the top are gone. Workgroup Manager setup checks out OK; all other users with PHDs work just fine. Sync seems to be only from Network Ho

  • How do I roll back to Snow Leopard 10.6 from os X lion?

    I need to roll back to 10.6. Scrolling up/down is opposite of what it used to be, at least in mail. 4 fingers in Leopard would move to previous or next email now 4 or even 3 fingers just changes size of window and shows other windows. VMWare fusion d

  • Balance Sheet & Profit and Loss Account - SAP Standard Structure

    Hi all, Can anyone send me the SAP standard structure of Balance Sheet and Profit & Loss Account...... Here i have configured Financial Statement Verson in OB58 and framed structure for P&L and Balance Sheet.... But i dont know whether it is right or

  • Disable the black menu in iBooks

    Hi! Im goding to use an iPad as a info board, kind of. I know about the guided access but the problem is i would like to disable the iBooks menu, completely. I hate that gray area that shows when i draw on the screen where to disable and the user is

  • I can not print my invoice, what can I do?

    Hello, I am not able to print my invoice out of  "My Adobe". Pressing the print button leads to an mostly empty window with an "error" within it´s url. It seams to be an technical problem, but it is not possible to get any direct support contact. Can