Forum Discussion

PaulDonny's avatar
PaulDonny
Regular Contributor
12 years ago

Getting Request Content

I need to get the request content from the operations in my Project. I have full access, I would prefer it not be in string format (This eliminates getProperty('Request');). I really need it to be in Document format if possible. I am digging through a lot of different functions and can't find a decent solution.


I've mainly been dealing with it at the testStep level but about to start looking into the operation level of it. Thanks for any assistance.

1 Reply

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    So I haven't really been able to find a decent way to do this. I am using the following methods for it if anyone else is interested in it.

        public static void main(String[] args) throws Exception {
    WsdlProject project = buildProject();
    buildTestCases(project);
    for (Interface iface:project.getInterfaceList()) {
    for (Operation op:iface.getOperationList()) {
    for (Request req:op.getRequestList()) {
    Document doc = loadXMLFromString(req.getRequestContent());
    //This is where the document parsing would be done
    System.out.println(doc.getFirstChild());
    }
    }
    }

    //project.saveAs("Test.xml");
    System.exit(0);
    }


    build project just builds the project, scans my WSDL directory and uses WsdlInterfaceFactory.importWsdl to import them.

        private static WsdlProject buildProject() throws Exception {
    File WSDLDir = new File(new File("").getAbsolutePath() + "\\Data\\WSDLs\\");
    WsdlProject project = new WsdlProject();
    project.setName("This is a new project");
    WsdlInterface iface = null;
    for (File wsdl : WSDLDir.listFiles()) {
    iface = WsdlInterfaceFactory.importWsdl(project, wsdl.toString(), true)[0];
    }
    return project;
    }


    buildTestCases builds the testSuite TestCase and Test Steps and adds one step for each operation from the WSDL

        private static void buildTestCases(WsdlProject project) {
    WsdlTestSuite TS = project.addNewTestSuite("Test");
    WsdlTestCase TC = TS.addNewTestCase("Test");
    TS.setName("Test");
    for (Interface inface : project.getInterfaceList()) {
    for (Operation op : inface.getAllOperations()) {
    TestStepConfig TStepC = WsdlTestRequestStepFactory.createConfig((WsdlOperation) op, op.getName());
    TC.addTestStep(TStepC);
    }
    }
    }


    And loadXMLFromString sets the xml to a ByteArrayInputStream to be parsed by the DocumentBuilderFactory to give me a Document that can be used by w3c.dom

        private static Document loadXMLFromString(String xml) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xml.getBytes()));
    }