Modify string soap+xml before send httpurlconnection - JAVAHow do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to split a string in JavaConverting 'ArrayList<String> to 'String[]' in JavaHow do I convert a String to an int in Java?What value we have to give for match in template tag?Read SOAP XML by ASMX web servcie functionSOAP response/Request then how to convert it in to PHPUnable to send parameters to SOAP method from Meteor's HTTP method

Schrodinger's Cat Isn't Meant To Be Taken Seriously, Right?

Problem with listing a directory to grep

Short story: Interstellar inspector senses "off" nature of planet hiding aggressive culture

Explaining "向けてじゃないよ"

Creating Chessboard with Javascript

When calculating averages, why can we treat exploding die as if they're independent?

Did "Dirty Harry" feel lucky?

How should Thaumaturgy's "three times as loud as normal" be interpreted?

I multiply the source, you (probably) multiply the output!

How to finish my PhD?

Are personality traits, ideals, bonds, and flaws required?

After a few interviews, What should I do after told to wait?

Why would an airport be depicted with symbology for runways longer than 8,069 feet even though it is reported on the sectional as 7,200 feet?

Why did Tony's Arc Reactor do this?

I won a car in a poker game. How is that taxed in Canada?

Get Emacs to jump to the start of a word after isearch

How to run NPCs with complicated mechanics?

More than three domains hosted on the same IP address

Extra arrow heads appearing tikz

How can faith be maintained in a world of living gods?

Did the Byzantines ever attempt to move their capital to Rome?

How would two worlds first establish an exchange rate between their currencies

Dragons and gems

Is every sentence we write or utter either true or false?



Modify string soap+xml before send httpurlconnection - JAVA


How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to split a string in JavaConverting 'ArrayList<String> to 'String[]' in JavaHow do I convert a String to an int in Java?What value we have to give for match in template tag?Read SOAP XML by ASMX web servcie functionSOAP response/Request then how to convert it in to PHPUnable to send parameters to SOAP method from Meteor's HTTP method






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a soap+xml file which use to send in HttpUrlConnection body. I need to edit some value before send the POST like below



sopaXML.xml :



<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="http://service.com/integration/">
<soap:Header>
<int:Options>
<int:UpdateLastModified>true</int:UpdateLastModified>
</int:Options>
</soap:Header>
<soap:Body>
<int:Execute>
<int:commandRequest xsi:type="int:TaskCreateCommand" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<int:TaskOrder>
<int:TypeCategory>Request</int:TypeCategory>
<int:Customer>
<int:Id>83</int:Id>
</int:Customer>
<int:Items>
<int:WoItem>
<int:Task>
<int:Id>16519</int:Id>
</int:Task>
<int:Comment>New Task 1</int:Comment>
</int:WoItem>
</int:Items>
</int:TaskOrder>
</int:commandRequest>
</int:Execute>
</soap:Body>
</soap:Envelope>


Need to change the value :



<int:TaskOrder>
<int:TypeCategory>Request</int:TypeCategory>
<int:Customer>
<int:Id>102</int:Id>
</int:Customer>
<int:Items>
<int:WoItem>
<int:Task>
<int:Id>20034</int:Id>
</int:Task>
<int:Comment>Modified New Task Here!</int:Comment>
</int:WoItem>
</int:Items>
</int:TaskOrder>


Code I have tried :



String url = "http://url/wsdk/Service.asmx";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type","application/soap+xml");
con.setRequestProperty("Cookie", "SessionId=0t10; path=/; HttpOnly");
con.setDoOutput(true)
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
XML xml = new XMLDocument(new File("src/main/resources/soapXML.xml"));
String xmlString = xml.toString();
System.out.println(xmlString);
InputStream stream = new ByteArrayInputStream(xmlString.getBytes());
SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, stream);
// How to modify the values
String modifiedxmlString = // modidfied soapXML string
wr.writeBytes(modifiedxmlString);
wr.flush();
wr.close();
String responseStatus = con.getResponseMessage();


How to changes the existing value from string of soap+xml and post that modified string in HttpURLconnection?










share|improve this question
































    0















    I have a soap+xml file which use to send in HttpUrlConnection body. I need to edit some value before send the POST like below



    sopaXML.xml :



    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="http://service.com/integration/">
    <soap:Header>
    <int:Options>
    <int:UpdateLastModified>true</int:UpdateLastModified>
    </int:Options>
    </soap:Header>
    <soap:Body>
    <int:Execute>
    <int:commandRequest xsi:type="int:TaskCreateCommand" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <int:TaskOrder>
    <int:TypeCategory>Request</int:TypeCategory>
    <int:Customer>
    <int:Id>83</int:Id>
    </int:Customer>
    <int:Items>
    <int:WoItem>
    <int:Task>
    <int:Id>16519</int:Id>
    </int:Task>
    <int:Comment>New Task 1</int:Comment>
    </int:WoItem>
    </int:Items>
    </int:TaskOrder>
    </int:commandRequest>
    </int:Execute>
    </soap:Body>
    </soap:Envelope>


    Need to change the value :



    <int:TaskOrder>
    <int:TypeCategory>Request</int:TypeCategory>
    <int:Customer>
    <int:Id>102</int:Id>
    </int:Customer>
    <int:Items>
    <int:WoItem>
    <int:Task>
    <int:Id>20034</int:Id>
    </int:Task>
    <int:Comment>Modified New Task Here!</int:Comment>
    </int:WoItem>
    </int:Items>
    </int:TaskOrder>


    Code I have tried :



    String url = "http://url/wsdk/Service.asmx";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-Type","application/soap+xml");
    con.setRequestProperty("Cookie", "SessionId=0t10; path=/; HttpOnly");
    con.setDoOutput(true)
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    XML xml = new XMLDocument(new File("src/main/resources/soapXML.xml"));
    String xmlString = xml.toString();
    System.out.println(xmlString);
    InputStream stream = new ByteArrayInputStream(xmlString.getBytes());
    SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, stream);
    // How to modify the values
    String modifiedxmlString = // modidfied soapXML string
    wr.writeBytes(modifiedxmlString);
    wr.flush();
    wr.close();
    String responseStatus = con.getResponseMessage();


    How to changes the existing value from string of soap+xml and post that modified string in HttpURLconnection?










    share|improve this question




























      0












      0








      0








      I have a soap+xml file which use to send in HttpUrlConnection body. I need to edit some value before send the POST like below



      sopaXML.xml :



      <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="http://service.com/integration/">
      <soap:Header>
      <int:Options>
      <int:UpdateLastModified>true</int:UpdateLastModified>
      </int:Options>
      </soap:Header>
      <soap:Body>
      <int:Execute>
      <int:commandRequest xsi:type="int:TaskCreateCommand" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <int:TaskOrder>
      <int:TypeCategory>Request</int:TypeCategory>
      <int:Customer>
      <int:Id>83</int:Id>
      </int:Customer>
      <int:Items>
      <int:WoItem>
      <int:Task>
      <int:Id>16519</int:Id>
      </int:Task>
      <int:Comment>New Task 1</int:Comment>
      </int:WoItem>
      </int:Items>
      </int:TaskOrder>
      </int:commandRequest>
      </int:Execute>
      </soap:Body>
      </soap:Envelope>


      Need to change the value :



      <int:TaskOrder>
      <int:TypeCategory>Request</int:TypeCategory>
      <int:Customer>
      <int:Id>102</int:Id>
      </int:Customer>
      <int:Items>
      <int:WoItem>
      <int:Task>
      <int:Id>20034</int:Id>
      </int:Task>
      <int:Comment>Modified New Task Here!</int:Comment>
      </int:WoItem>
      </int:Items>
      </int:TaskOrder>


      Code I have tried :



      String url = "http://url/wsdk/Service.asmx";
      URL obj = new URL(url);
      HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      con.setRequestMethod("POST");
      con.setRequestProperty("Content-Type","application/soap+xml");
      con.setRequestProperty("Cookie", "SessionId=0t10; path=/; HttpOnly");
      con.setDoOutput(true)
      DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      XML xml = new XMLDocument(new File("src/main/resources/soapXML.xml"));
      String xmlString = xml.toString();
      System.out.println(xmlString);
      InputStream stream = new ByteArrayInputStream(xmlString.getBytes());
      SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, stream);
      // How to modify the values
      String modifiedxmlString = // modidfied soapXML string
      wr.writeBytes(modifiedxmlString);
      wr.flush();
      wr.close();
      String responseStatus = con.getResponseMessage();


      How to changes the existing value from string of soap+xml and post that modified string in HttpURLconnection?










      share|improve this question
















      I have a soap+xml file which use to send in HttpUrlConnection body. I need to edit some value before send the POST like below



      sopaXML.xml :



      <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="http://service.com/integration/">
      <soap:Header>
      <int:Options>
      <int:UpdateLastModified>true</int:UpdateLastModified>
      </int:Options>
      </soap:Header>
      <soap:Body>
      <int:Execute>
      <int:commandRequest xsi:type="int:TaskCreateCommand" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <int:TaskOrder>
      <int:TypeCategory>Request</int:TypeCategory>
      <int:Customer>
      <int:Id>83</int:Id>
      </int:Customer>
      <int:Items>
      <int:WoItem>
      <int:Task>
      <int:Id>16519</int:Id>
      </int:Task>
      <int:Comment>New Task 1</int:Comment>
      </int:WoItem>
      </int:Items>
      </int:TaskOrder>
      </int:commandRequest>
      </int:Execute>
      </soap:Body>
      </soap:Envelope>


      Need to change the value :



      <int:TaskOrder>
      <int:TypeCategory>Request</int:TypeCategory>
      <int:Customer>
      <int:Id>102</int:Id>
      </int:Customer>
      <int:Items>
      <int:WoItem>
      <int:Task>
      <int:Id>20034</int:Id>
      </int:Task>
      <int:Comment>Modified New Task Here!</int:Comment>
      </int:WoItem>
      </int:Items>
      </int:TaskOrder>


      Code I have tried :



      String url = "http://url/wsdk/Service.asmx";
      URL obj = new URL(url);
      HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      con.setRequestMethod("POST");
      con.setRequestProperty("Content-Type","application/soap+xml");
      con.setRequestProperty("Cookie", "SessionId=0t10; path=/; HttpOnly");
      con.setDoOutput(true)
      DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      XML xml = new XMLDocument(new File("src/main/resources/soapXML.xml"));
      String xmlString = xml.toString();
      System.out.println(xmlString);
      InputStream stream = new ByteArrayInputStream(xmlString.getBytes());
      SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, stream);
      // How to modify the values
      String modifiedxmlString = // modidfied soapXML string
      wr.writeBytes(modifiedxmlString);
      wr.flush();
      wr.close();
      String responseStatus = con.getResponseMessage();


      How to changes the existing value from string of soap+xml and post that modified string in HttpURLconnection?







      java xml soap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 8:48







      MMMMS

















      asked Mar 28 at 7:09









      MMMMSMMMMS

      9466 gold badges24 silver badges59 bronze badges




      9466 gold badges24 silver badges59 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          try below given code.



          Note: Its hint not a compiled code



          You have SOAPMessage object by which you can get soap body



          SOAPMessage sm = ----- 
          SOAPBody body = sm.getSOAPBody();

          private void updateNodeValue(List<String> nodeNamesWhichYouWantToUpdate, SOAPBody body)
          for(String nodeName : nodeNamesWhichYouWantToUpdate)
          NodeList nodeList = body.getElementsByTagName(nodeName);
          int length = nodeList.getLength();
          for (int i = 0; i < length; i++)
          Node node = (Node) nodeList.item(i);
          node.setTextContent("updateNodeValue");









          share|improve this answer

























          • If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

            – MMMMS
            Mar 28 at 11:42











          • Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

            – MMMMS
            Mar 28 at 12:15










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391944%2fmodify-string-soapxml-before-send-httpurlconnection-java%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0
















          try below given code.



          Note: Its hint not a compiled code



          You have SOAPMessage object by which you can get soap body



          SOAPMessage sm = ----- 
          SOAPBody body = sm.getSOAPBody();

          private void updateNodeValue(List<String> nodeNamesWhichYouWantToUpdate, SOAPBody body)
          for(String nodeName : nodeNamesWhichYouWantToUpdate)
          NodeList nodeList = body.getElementsByTagName(nodeName);
          int length = nodeList.getLength();
          for (int i = 0; i < length; i++)
          Node node = (Node) nodeList.item(i);
          node.setTextContent("updateNodeValue");









          share|improve this answer

























          • If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

            – MMMMS
            Mar 28 at 11:42











          • Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

            – MMMMS
            Mar 28 at 12:15















          0
















          try below given code.



          Note: Its hint not a compiled code



          You have SOAPMessage object by which you can get soap body



          SOAPMessage sm = ----- 
          SOAPBody body = sm.getSOAPBody();

          private void updateNodeValue(List<String> nodeNamesWhichYouWantToUpdate, SOAPBody body)
          for(String nodeName : nodeNamesWhichYouWantToUpdate)
          NodeList nodeList = body.getElementsByTagName(nodeName);
          int length = nodeList.getLength();
          for (int i = 0; i < length; i++)
          Node node = (Node) nodeList.item(i);
          node.setTextContent("updateNodeValue");









          share|improve this answer

























          • If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

            – MMMMS
            Mar 28 at 11:42











          • Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

            – MMMMS
            Mar 28 at 12:15













          0














          0










          0









          try below given code.



          Note: Its hint not a compiled code



          You have SOAPMessage object by which you can get soap body



          SOAPMessage sm = ----- 
          SOAPBody body = sm.getSOAPBody();

          private void updateNodeValue(List<String> nodeNamesWhichYouWantToUpdate, SOAPBody body)
          for(String nodeName : nodeNamesWhichYouWantToUpdate)
          NodeList nodeList = body.getElementsByTagName(nodeName);
          int length = nodeList.getLength();
          for (int i = 0; i < length; i++)
          Node node = (Node) nodeList.item(i);
          node.setTextContent("updateNodeValue");









          share|improve this answer













          try below given code.



          Note: Its hint not a compiled code



          You have SOAPMessage object by which you can get soap body



          SOAPMessage sm = ----- 
          SOAPBody body = sm.getSOAPBody();

          private void updateNodeValue(List<String> nodeNamesWhichYouWantToUpdate, SOAPBody body)
          for(String nodeName : nodeNamesWhichYouWantToUpdate)
          NodeList nodeList = body.getElementsByTagName(nodeName);
          int length = nodeList.getLength();
          for (int i = 0; i < length; i++)
          Node node = (Node) nodeList.item(i);
          node.setTextContent("updateNodeValue");










          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 8:59









          Arun KumarArun Kumar

          10014 bronze badges




          10014 bronze badges















          • If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

            – MMMMS
            Mar 28 at 11:42











          • Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

            – MMMMS
            Mar 28 at 12:15

















          • If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

            – MMMMS
            Mar 28 at 11:42











          • Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

            – MMMMS
            Mar 28 at 12:15
















          If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

          – MMMMS
          Mar 28 at 11:42





          If I pass List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("Customer","WoItem"); then it gives nodeList 0

          – MMMMS
          Mar 28 at 11:42













          Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

          – MMMMS
          Mar 28 at 12:15





          Finally Changed into List<String> nodeNamesWhichYouWantToUpdate= Arrays.asList("int:Customer","int:WoItem"); now Entered into node.setTextContent("updateNodeValue"); but does not update value.

          – MMMMS
          Mar 28 at 12:15








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391944%2fmodify-string-soapxml-before-send-httpurlconnection-java%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현