Skip to content

Instantly share code, notes, and snippets.

@djangofan
Created May 22, 2012 04:38
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save djangofan/2766613 to your computer and use it in GitHub Desktop.
Save djangofan/2766613 to your computer and use it in GitHub Desktop.
Using RestAssured to do a SOAP web service request
package test.ra;
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.path.xml.XmlPath.*;
import java.util.HashMap;
import java.util.Map;
public class SOAPDictionary {
public static void main(String[] args) {
// http://services.aonaware.com/DictService/DictService.asmx?op=Define
// http://services.aonaware.com/DictService/DictService.asmx?wsdl
baseURI = "http://services.aonaware.com";
port = 80;
String word = "hand";
String myEnvelope = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap12:Body>" +
"<Define xmlns=\"http://services.aonaware.com/webservices/\">" +
"<word>" + word + "</word>" +
"</Define>" +
"</soap12:Body>" +
"</soap12:Envelope>";
Map<String, String> authhdrs = new HashMap<String, String>();
authhdrs.put("SOAPAction", "Define");
//authhdrs.put("Content-Length", Integer.toString( myEnvelope.length() ) );
String xml = given().request().headers(authhdrs)
.contentType("application/soap+xml; charset=UTF-8;").body( myEnvelope )
.when().post( "/DictService/DictService.asmx" ).andReturn().asString();
String prettyXML = with(xml).prettyPrint();
System.out.println( prettyXML );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment