Forum Discussion

vikranthsanka15's avatar
vikranthsanka15
Occasional Contributor
10 years ago

copying the SOAP Response into a notepad

I have a webservice ,on running the webservice request my Soap response gets me a Random 16 digit MemberNumber.I save this MemberNumber from response into a notepad using the following groovy code


def request = context.expand( '${CreateMember#Response# //ns2:CreateMemberResponse[1]/ns2:CreateMemberResult[1]/ns2:Epsilon[1]/ns2:Response[1]/ns2:GetMemberLookupReply[1]/ns2:Members[1]/ns2:Member[1]/ns2:MemberNumber[1]}')

new File( "C:/Users/vikranth_sanka/Desktop/membernumber.txt" ).write(request, "UTF-8" )


1.on running this script membernumber is saved into this notepad(membernumber.txt)
2.When I run the same script again, this time new data overwrites the previously saved data in the notepad(i.e., membernumber.txt)
3.My Requirement is whenever I execute the Script the newly generated membernumber from my SOAP response should be appended to the data in the notepad(that means all the membernumbers generated from soap response should be stored in the same notepad seperated by a delimiter or space)


Please help me guys.
Thanks in Advance.

5 Replies

  • vikranthsanka15's avatar
    vikranthsanka15
    Occasional Contributor
    Hi PaulM ,

    Thanks for the reply can you please elaborate How can I use File.Append() in my code.

    I want to know If I have to use any Import statements in my Groovy code before using File.Append().

    I have tried following code but getting an Exception

    File.Append("C:/Users/vikranth_sanka/Desktop/membernumber.txt").write(request, "UTF-8" )

    Exception Im getting is:
    groovy.lang.MissingMethodException: No signature of method: static java.io.File.Append() is applicable for argument types: (java.lang.String) values: [C:/Users/vikranth_sanka/Desktop/membernumber.txt] Possible solutions: append(java.lang.Object, java.lang.String), append(java.lang.Object), append([B), append(java.io.InputStream), canRead(), any() error at line: 16
  • vikranthsanka15's avatar
    vikranthsanka15
    Occasional Contributor
    Thanks PaulM

    new File("C:/Users/vikranth_sanka/Desktop/membernumber.txt").append(request, "UTF-8" );

    This is working fine
    But appending the new data in the same line. Can you please tell me how to append the data in the new line.
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    For a new line add a new line marker at the beginning (Typically either \\n (Linux) or \\r\\n (Windows))


    There is examples on StackOverflow that will likely help you out a lot and probably make it easier and more efficient.