如何在没有SOAP处理程序的情况下获取Soap头

时间:2016-05-31 13:59:27

标签: java web-services soap

我正在尝试在运行请求之前使用我的java代码编辑我的soap标头。我没有使用处理程序或jax-rs。我看到了WsdlUtils,但我无法想象如何在我的代码中使用它。请有人帮我这个

这是我的代码;

package soap.impl;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.xmlbeans.XmlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.eviware.soapui.SoapUI;
import com.eviware.soapui.StandaloneSoapUICore;
import com.eviware.soapui.config.impl.TestStepConfigImpl;
import com.eviware.soapui.impl.wsdl.WsdlHeaderPart;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.submit.filters.SoapHeadersRequestFilter;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils.SoapHeader;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner;
import com.eviware.soapui.model.TestPropertyHolder;
import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
import com.eviware.soapui.model.support.PropertiesMap;
import com.eviware.soapui.model.support.TestPropertyUtils;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestProperty;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestStepResult;
import com.eviware.soapui.model.testsuite.TestRunner.Status;
import com.eviware.soapui.model.testsuite.TestSuite;
import com.eviware.soapui.support.SoapUIException;
import com.eviware.soapui.support.types.StringToObjectMap;
import com.eviware.soapui.support.types.StringToStringsMap;

public class RunTestImpl{

    static Logger logger = LoggerFactory.getLogger(RunTestImpl.class);

public static void main(String[] args) throws XmlException, IOException, SoapUIException {


         logger.info("Into the Class for running test cases");

        String suiteName = "";
        String reportStr = "";
      InputData input=new InputData();
      TestPropertyHolder holder = PropertyExpansionUtils.getGlobalProperties();

      String testCaseName="";
      holder.setPropertyValue("CRK", "CRK987909000000000075");


        // variables for getting duration



      WsdlTestCaseRunner runner = null;

        List<TestSuite> suiteList = new ArrayList<TestSuite>();
        List<TestCase> caseList = new ArrayList<TestCase>();

        SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

        // specified soapUI project

        WsdlProject project1 = new WsdlProject("D://my-project.xml");




      WsdlTestSuite testSuite1= project1.getTestSuiteByName("my TestSuite");
      WsdlTestCase testCase1= testSuite1.getTestCaseByName("myTestCase");
      suiteList.add(testSuite1);




    runner=  testCase1.run(new StringToObjectMap(), false);

    List<TestStepResult> list= runner.getResults();
    StringToStringsMap headers1=null;
    for (TestStepResult testStepResult : list) {
    testStepResult).getRequestContent();
        byte[] rawReq=((MessageExchange)testStepResult).getRawRequestData();


        headers1 = ((MessageExchange)testStepResult).getRequestHeaders();
        String response = ((MessageExchange)testStepResult).getResponseContent();
        StringBuilder build=new StringBuilder();
        for (byte b : rawReq) {
            build.append((char)b);
        }
        System.out.println("build "+build.toString());
    }

    for (Map.Entry<String,List< String>> entry : headers1.entrySet()) {
        System.out.println("key"+entry.getKey());
        for (String string:entry.getValue()) {
            System.out.println("value "+string);

        }
    }








    //  }

        // string of the results
        System.out.println(reportStr);
    }

}

0 个答案:

没有答案