我的目的是創建一個具有給定wsdl URL的SOAP UI項目,保存並通過Java方法發送請求。我試圖通過設置操作的用戶名和密碼提交請求時出現org.apache.http.client.ClientProtocolException..... Caused by: org.apache.http.ProtocolException: Content-Length header already present
錯誤。找到我的Java方法來發送請求。ClientProtocolException當試圖通過設置用戶名和密碼通過Java提交SOAP WsdlRequest請求
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);
}
}
}
也可參考附圖像。有人可以建議我在哪裏出錯,以及如何解決這個問題?
很高興認識你可以解決這個問題。你能不能在這裏發佈你的完整代碼,這樣可以使其他人受益?另外,你是否參數化了你的請求和響應。如果您可以提供有關您如何完成的詳細信息,將會非常有幫助。另外,請讓我們知道在哪裏/如何提供終點。 謝謝,邁克。 – Mike
嗨邁克,完整的代碼,請參考[this](http://pritikaur23.wordpress.com/2013/06/16/saving-a-soapui-project-and-sending-requests-using-soapui- api /)鏈接。您可以使用以下'req.setEndpoint(「your_end_Point」);'Thanks – priti