I am writing a Java code using Apache httpclient
to call SOAP web service. So far I have written the below piece of code which is working fine.
void post(String strURL, String strSoapAction, String strXMLFilename) throws Exception{
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
Here, strXMLFilename is SOAP request file taken from SOAP UI(I copied SOAP UI request xml and paste it in some new xml file and then used it). The above tests a service that takes String as an argument.
But now my question is will it be able to test a service that is taking File as an input? I need to send a File to the service.In SOAP UI, I am able to attach a file and test the service but not able to do the same with the above piece of code.
Please help.