我试图在Eclipse中编译并运行以下代码,但它不起作用。目标是使用特定单词在字典Web服务http://services.aonaware.com/DictService/DictService.asmx?WSDL上发出请求,并将该单词的定义返回给用户。你能帮忙解决一下吗?我认为缺少一些插件,因为它在import语句附近显示错误。
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.path.xml.XmlPath.*;
import com.jayway.restassured.path.xml.element.Node;
// RestAssured source: http://grepcode.com/file/repo1.maven.org/maven2/com.jayway.restassured/rest-assured/1.6/com/jayway/restassured/RestAssured.java#RestAssured
// URL: http://services.aonaware.com/DictService/DictService.asmx/Define?word=string
// WSDL: http://services.aonaware.com/DictService/DictService.asmx?WSDL
public class RATest {
public static void main(String[] args) {
baseURI = "http://services.aonaware.com";
port = 80;
String defCandidate = "fastidious";
String xml = get("/DictService/DictService.asmx/Define?word=" + defCandidate ).andReturn().asString();
int items = from(xml).get("WordDefinition.Definitions.Definition.size()");
System.out.println("\n\n");
System.out.println("Number of definitions returned: " + items);
for( int i=0; i<items ; i++ ) {
int defNum = i + 1;
Node def = from(xml).get("WordDefinition.Definitions.Definition[" + i + "]");
String returnedWord = def.getNode("Word").value();
String dictName = def.getNode("Dictionary").getNode("Name").value();
String definition = def.getNode("WordDefinition").value();
System.out.println("Definition " + defNum + ": ");
System.out.println("Word: " + returnedWord );
System.out.println("Dictionary: " + dictName );
System.out.println("Definition: " + definition );
}
}
}