6

My purpose is to create a Soap UI project with a given wsdl URL, save it and send requests all via Java methods. I a getting org.apache.http.client.ClientProtocolException..... Caused by: org.apache.http.ProtocolException: Content-Length header already present error when I am trying to submit request by setting username and password for an operation. Find my Java method to send requests.

public void runSoap() throws Exception
{
        String projectFile = "SoapUIProjects/TestProjectA-soapui-project.xml";
    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
    WsdlProject project = new WsdlProject(projectFile);

    int c = project.getInterfaceCount();
    System.out.println("The interface count   ="+c);

    for(int i=0;i<c;i++)
    {
        WsdlInterface wsdl = (WsdlInterface) project.getInterfaceAt(i);
        String soapVersion = wsdl.getSoapVersion().toString();
        int opc = wsdl.getOperationCount();
        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);

                //Assigning correct u/p to an operation: Generate
                if(opName.equals("Generate"))
                {
                    System.out.println("The operation is Generate.");
                    req.setUsername("u1");//Setting username
                    req.setPassword("u1");//Setting password
               }

               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);
        }
    }
}

SoapUI Window

Also refer to the image attached. Can somebody suggest me where am I going wrong and how to resolve this problem?

WilQu
  • 7,131
  • 6
  • 30
  • 38
priti
  • 639
  • 3
  • 8
  • 25
  • Glad to know that you could solved this. Could you please post your complete code here so that it can benefit others? Also, Have you parameterized your request and response. It will be very helpful if you can provide details as to how you have done it. Also, could you please let us know where/how to provide the end point. Thanks, Mike. – Mike Jun 15 '13 at 11:42
  • Hi Mike, for the complete code, please refer to [this](http://pritikaur23.wordpress.com/2013/06/16/saving-a-soapui-project-and-sending-requests-using-soapui-api/) link. You can provide the end point for the requests using the following `req.setEndpoint(“your_end_Point”);` Thanks – priti Jun 16 '13 at 10:57

3 Answers3

13

I got the answer to my question. I had to set the 'Authorisation Type' explicitly and programmatically and the code to do so is this - req.setAuthType("Preemptive");

By giving this, the request is being sent and I am not getting any exceptions.

priti
  • 639
  • 3
  • 8
  • 25
4

In my search to fix this same error, I found that the solution was to enable "Authenticate Preemptively" option (go into preferences-> http settings and check the 'Authenticate Preemptively' box.)

Adriano
  • 259
  • 3
  • 5
0

1) In my case http configured in properties instead https. I replaced http with https then its working.

https://localhost:8102/WebService/test

2) Check Authorization username and Password

3) Select Pre-emptive auth: Authenticate pre-emptively

enter image description here

Narayan Yerrabachu
  • 1,714
  • 1
  • 19
  • 31