Search in sources :

Example 1 with HttpHandler

use of com.alibaba.dubbo.remoting.http.HttpHandler in project dubbo by alibaba.

the class JettyHttpBinderTest method shouldAbleHandleRequestForJettyBinder.

@Test
public void shouldAbleHandleRequestForJettyBinder() throws Exception {
    int port = TestUtil.getFreePort();
    URL url = new URL("http", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    HttpServer httpServer = new JettyHttpServer(url, new HttpHandler() {

        @Override
        public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.getWriter().write("Jetty");
        }
    });
    String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString();
    assertThat(response, is("Jetty"));
    httpServer.close();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHandler(com.alibaba.dubbo.remoting.http.HttpHandler) HttpServer(com.alibaba.dubbo.remoting.http.HttpServer) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 2 with HttpHandler

use of com.alibaba.dubbo.remoting.http.HttpHandler in project dubbo by alibaba.

the class TomcatHttpBinderTest method shouldAbleHandleRequestForTomcatBinder.

@Test
public void shouldAbleHandleRequestForTomcatBinder() throws Exception {
    int port = TestUtil.getFreePort();
    URL url = new URL("http", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    HttpServer httpServer = new TomcatHttpBinder().bind(url, new HttpHandler() {

        @Override
        public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.getWriter().write("Tomcat");
        }
    });
    String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString();
    assertThat(response, is("Tomcat"));
    httpServer.close();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHandler(com.alibaba.dubbo.remoting.http.HttpHandler) HttpServer(com.alibaba.dubbo.remoting.http.HttpServer) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)2 HttpHandler (com.alibaba.dubbo.remoting.http.HttpHandler)2 HttpServer (com.alibaba.dubbo.remoting.http.HttpServer)2 IOException (java.io.IOException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Test (org.junit.Test)2