⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 restclienttest.java

📁 Yahoo!search API. 用于搜索引擎接口
💻 JAVA
字号:
package com.yahoo.rest;import junit.framework.TestCase;import org.mortbay.http.HttpContext;import org.mortbay.http.HttpServer;import org.mortbay.http.SocketListener;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.HashMap;public class RestClientTest extends TestCase {    private HttpServer server;    public void testFoo() {        try {            BufferedReader reader = new BufferedReader(new InputStreamReader(RestClient.call("http://localhost:8081/tests/echo", new HashMap())));            String read;            while((read = reader.readLine()) != null) {                System.out.println(read);            }        }        catch (IOException e) {            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.        }        catch (RestException e) {            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.        }    }    protected void setUp() throws Exception {        server = new HttpServer(true);        SocketListener listener = new SocketListener();        listener.setPort(8081);        server.addListener(listener);        HttpContext echoContext = new HttpContext();        echoContext.setHosts(new String[]{"localhost"});        echoContext.setContextPath("/tests/echo");        echoContext.addHandler(new EchoHandler());        server.addContext(echoContext);        server.start();    }    protected void tearDown() throws Exception {        server.stop(true);        server = null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -