1

Following the last post of this discussion, I've created a client to send a request to a SOAP RPC web service.

First of all I've created the XML Project file through this method:

public static void runSoap() throws Exception {

    String projectFile = "C:/Test/TestProjectA-soapui-project.xml";
    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
    WsdlProject project = new WsdlProject(projectFile);
    int c = project.getInterfaceCount();

    for(int i=0;i<c;i++) {
        WsdlInterface wsdl = (WsdlInterface) project.getInterfaceAt(i);
        String soapVersion = wsdl.getSoapVersion().toString();

        System.out.println("The SOAP version ="+soapVersion);
        System.out.println("The binding name = "+wsdl.getBindingName());

        int opc = wsdl.getOperationCount();
        System.out.println("Operation count ="+opc);

        String result="";

        for(int j=0;j<opc;j++){
            WsdlOperation op = wsdl.getOperationAt(j);
            String opName = op.getName();

            System.out.println("OPERATION:"+opName);

            WsdlRequest req = op.getRequestByName("Req_"+soapVersion+"_"+opName);

            req.setEndpoint("<my_WSDL_ENDPOINT>");

            WsdlSubmitContext wsdlSubmitContext = new WsdlSubmitContext(req);
            WsdlSubmit<?> submit = (WsdlSubmit<?>) req.submit(wsdlSubmitContext, false);
            Response response = submit.getResponse();
            result = response.getContentAsString();

            System.out.println("The result ="+result);

        }

    }

After the xml creation I've launched the next code to try to call the login operation. This operations has 3 parts:

  1. user
  2. pwd
  3. keycartella

This is the code to send the request, but I don't know the method to call to assign the value to the 3 message parts above:

public static void sendRequest() throws XmlException, IOException, SoapUIException, SubmitException{
    String projectFile = "C:/Test/TestProjectA-soapui-project.xml";
    WsdlProject project = new WsdlProject(projectFile);
    WsdlInterface wsdl = (WsdlInterface) project.getInterfaceAt(0);
    String soapVersion = wsdl.getSoapVersion().toString();
    WsdlOperation op = 
              (WsdlOperation) wsdl.getOperationByName( "login" );
    WsdlRequest req = op.getRequestByName("Req_"+soapVersion+"_"+ "login");

    req.setEndpoint("<my_WSDL_ENDPOINT>");

    WsdlSubmitContext wsdlSubmitContext = new WsdlSubmitContext(req);

    WsdlSubmit<?> submit = (WsdlSubmit<?>) req.submit(wsdlSubmitContext, false);

    Response response = submit.getResponse();
    String result = response.getContentAsString();

    System.out.println("The result ="+result);
}

To be clear the SOAP envelope body is:

<soapenv:Body>
  <urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <user xsi:type="xsd:string">?</user>
     <pwd xsi:type="xsd:string">?</pwd>
     <keycartella xsi:type="xsd:string">?</keycartella>
  </urn:login>

I'd like to substitute the default "?" with a real value via Java code, not changing the XML file.

Community
  • 1
  • 1
Akamaccio
  • 79
  • 5
  • Have you able to solve this issue ? i encounted exactly above – Pujan Dec 17 '15 at 03:34
  • 1
    I've solved the problem using Netbeans instead of Eclipse. You need to follow this procedure http://stackoverflow.com/questions/30162388/netbeans-8-0-2-ide-is-not-opening-after-installing-jax-rpc-web-service-plugin[/link] and you will be able to compile a client. If during compile you receive an error, add javamail-mailapi-1.4.jar and javax.xml.rpc-3.1.jar to your project libs. This might solve the issue. – Akamaccio Dec 21 '15 at 14:33

0 Answers0