Saving output from JavaScript

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
I found some JavaScript that will give me the IP Address of the local machine where I am running tests and this code works quite nicely.

CODE

function GetIPAddress(input, context) {
var ip = java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip.getHostAddress());

return (ipStr);
}


The problem is that I need to save the return value for later use in an XML Data Bank and the Python code I usually employ as shown below does not work (the error message is "Traceback (innermost last): File "<string>", line 9, in showMe TypeError: getXMLFromString(): 1st arg can't be coerced to String[]). I would think I might need to return a string array from the GetIPAddress function in order for the showMe function to work as expected, but I am not sure how to do it. Help!

CODE

from com.parasoft.api import *
from soaptest.api import *
from java.util import *
from java.text import *
from java.lang import *

def showMe(input, context):
return SOAPUtil.getXMLFromString([input])
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Hi jstrom,

    It looks like you have two scripts here, in different languages - we just need to put them together. The error is likely caused by the fact that the input argument is not actually a string (you can cast it to a string with something like str(input)).
    Here's the full working example in Jython which should give you the desired information:

    CODE
    from com.parasoft.api import *
    from soaptest.api import *
    from java.lang import *
    from java.net import *

    def getgetIPAddress(input, context):
        ip = InetAddress.getLocalHost()
        ipStr = String(ip.getHostAddress())
        return SOAPUtil.getXMLFromString([ipStr]);

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Works like a charm, many thanks!
Sign In or Register to comment.