1 17 18 package org.apache.geronimo.jetty6; 19 20 import java.io.BufferedReader ; 21 import java.io.InputStreamReader ; 22 import java.net.HttpURLConnection ; 23 import java.net.URL ; 24 25 import org.apache.geronimo.jetty6.app.MockWebServiceContainer; 26 27 30 public class ContainerTest extends AbstractWebModuleTest { 31 32 public void testHTTPConnector() throws Exception { 33 34 HttpURLConnection connection = (HttpURLConnection ) new URL ("http://localhost:5678").openConnection(); 35 try { 36 connection.getInputStream(); 37 fail(); 38 } catch (Exception e) { 39 assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode()); 41 connection.disconnect(); 42 } 43 } 44 45 public void testWebServiceHandler() throws Exception { 46 47 String contextPath = "/foo/webservice.ws"; 48 MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer(); 49 container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl); 50 51 HttpURLConnection connection = (HttpURLConnection ) new URL ("http://localhost:5678" + contextPath).openConnection(); 52 try { 53 BufferedReader reader = new BufferedReader (new InputStreamReader (connection.getInputStream())); 54 assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); 55 assertEquals("Hello World", reader.readLine()); 56 } finally { 57 connection.disconnect(); 58 } 59 container.removeWebService(contextPath); 60 connection = (HttpURLConnection ) new URL ("http://localhost:5678" + contextPath).openConnection(); 61 try { 62 connection.getInputStream(); 63 fail(); 64 } catch (Exception e) { 65 assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode()); 67 connection.disconnect(); 68 } 69 } 70 public void test2WebServiceHandlers() throws Exception { 71 72 String contextPath = "/foo/webservice.ws"; 73 MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer(); 74 container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl); 75 76 String contextPath2 = "/bar/webservice.ws"; 77 MockWebServiceContainer webServiceInvoker2 = new MockWebServiceContainer(); 78 container.addWebService(contextPath2, null, webServiceInvoker2, null, null, null, null,cl); 79 80 HttpURLConnection connection = (HttpURLConnection ) new URL ("http://localhost:5678" + contextPath).openConnection(); 81 try { 82 BufferedReader reader = new BufferedReader (new InputStreamReader (connection.getInputStream())); 83 assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); 84 assertEquals("Hello World", reader.readLine()); 85 } finally { 86 connection.disconnect(); 87 } 88 container.removeWebService(contextPath); 89 connection = (HttpURLConnection ) new URL ("http://localhost:5678" + contextPath).openConnection(); 90 try { 91 connection.getInputStream(); 92 fail(); 93 } catch (Exception e) { 94 assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode()); 96 connection.disconnect(); 97 } 98 } 99 100 } 101 | Popular Tags |