List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Servlet13() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override/*from w w w . j a va 2 s .c o m*/ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.write(req.getQueryString()); writer.write("|"); writer.write(req.getParameter("p")); writer.write("|"); writer.write(Arrays.toString(req.getParameterValues("p"))); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S13"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Servlet13/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); String result = requestAdvisor.request("Servlet13/a?p=1&p=2"); Assert.assertEquals("p=1&p=2|1|[1, 2]", result); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ErrorPage8() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override//from w w w . ja va 2 s. c o m protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { throw new RuntimeException(); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E8"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage8/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E8.error"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, RuntimeException.class.getName()); registrations.add(getBundleContext().registerService(Servlet.class, new ErrorServlet("500"), props)); Map<String, List<String>> response = requestAdvisor.request("TestErrorPage8/a", null); String responseCode = response.get("responseCode").get(0); String responseBody = response.get("responseBody").get(0); Assert.assertEquals("500", responseCode); Assert.assertEquals("500 : 500 : ERROR : /TestErrorPage8/a", responseBody); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ErrorPage9() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override//from w ww . j av a2 s.co m protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { throw new IOException(); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E9"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage9/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E9.error"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, IOException.class.getName()); registrations.add(getBundleContext().registerService(Servlet.class, new ErrorServlet("500"), props)); Map<String, List<String>> response = requestAdvisor.request("TestErrorPage9/a", null); String responseCode = response.get("responseCode").get(0); String responseBody = response.get("responseBody").get(0); Assert.assertEquals("500", responseCode); Assert.assertEquals("500 : 500 : ERROR : /TestErrorPage9/a", responseBody); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ErrorPage10() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override//from w w w . j a v a 2s. c o m protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write("some output"); resp.flushBuffer(); throw new IOException(); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E10"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage10/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); try { requestAdvisor.request("TestErrorPage10/a"); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); return; } Assert.fail("Expecting java.io.IOException: Premature EOF"); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
/** * This test should also not hit the error servlet as we've only set the * status. As per the Servlet spec this should not trigger error handling. *//*from w w w . ja v a 2 s .c om*/ public void test_ErrorPage6() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("Hello!"); response.setStatus(444); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E6"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage6/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E6.error"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, "444"); registrations.add(getBundleContext().registerService(Servlet.class, new ErrorServlet("444"), props)); Map<String, List<String>> response = requestAdvisor.request("TestErrorPage6/a", null); String responseCode = response.get("responseCode").get(0); String responseBody = response.get("responseBody").get(0); Assert.assertEquals("444", responseCode); Assert.assertNotEquals("444 : 444 : ERROR : /TestErrorPage6/a", responseBody); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Async1() throws Exception { Servlet s1 = new BaseAsyncServlet("test_Listener8"); Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>(); try {/*w w w. j av a2s. c o m*/ Dictionary<String, Object> servletProps1 = new Hashtable<String, Object>(); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1"); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s"); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true); registrations.add(getBundleContext().registerService(Servlet.class, s1, servletProps1)); String output1 = requestAdvisor.request("s"); Assert.assertTrue(output1, output1.endsWith("test_Listener8")); } finally { for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } } }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_BufferedOutput() throws Exception { Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>(); try {/*from w ww . ja v a 2 s .c o m*/ Dictionary<String, String> servletProps1 = new Hashtable<String, String>(); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S9"); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s9"); registrations .add(getBundleContext().registerService(Servlet.class, new BufferedServlet(), servletProps1)); Map<String, List<String>> response = requestAdvisor.request("s9", Collections.<String, List<String>>emptyMap()); String responseCode = response.get("responseCode").get(0); Assert.assertEquals("200", responseCode); } finally { for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } } }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Filter21() throws Exception { // Make sure exact path matching is honored by filters registrations String expected = "a"; TestFilter testFilter1 = new TestFilter(); TestFilter testFilter2 = new TestFilter(); Servlet testServlet = new BaseServlet(expected); Dictionary<String, String> props = new Hashtable<String, String>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME, "F1"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/hello"); registrations.add(getBundleContext().registerService(Filter.class, testFilter1, props)); props = new Hashtable<String, String>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME, "F2"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/hello/*"); registrations.add(getBundleContext().registerService(Filter.class, testFilter2, props)); props = new Hashtable<String, String>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/hello/*"); registrations.add(getBundleContext().registerService(Servlet.class, testServlet, props)); String actual = requestAdvisor.request("hello"); Assert.assertEquals(expected, actual); Assert.assertTrue("testFilter1 did not get called.", testFilter1.getCalled()); Assert.assertTrue("testFilter2 did not get called.", testFilter2.getCalled()); testFilter1.clear();/*w ww. j a v a 2s . c om*/ testFilter2.clear(); actual = requestAdvisor.request("hello/test"); Assert.assertEquals(expected, actual); Assert.assertFalse("testFilter1 got called.", testFilter1.getCalled()); Assert.assertTrue("testFilter2 did not get called.", testFilter2.getCalled()); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void testServletContextUnsupportedOperations() { final AtomicReference<ServletContext> contextHolder = new AtomicReference<ServletContext>(); Servlet unsupportedServlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override/*from ww w.j a v a 2s . c o m*/ public void init(ServletConfig config) throws ServletException { contextHolder.set(config.getServletContext()); } }; ServiceRegistration<Servlet> servletReg = null; Dictionary<String, Object> servletProps = new Hashtable<String, Object>(); servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/sessions"); try { servletReg = getBundleContext().registerService(Servlet.class, unsupportedServlet, servletProps); } catch (Exception e) { fail("Unexpected exception: " + e); } finally { if (servletReg != null) { servletReg.unregister(); } } ServletContext context = contextHolder.get(); assertNotNull("Null context.", context); for (Method m : getUnsupportedMethods()) { checkMethod(m, context); } }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Listener8() throws Exception { BaseHttpSessionIdListener hsil1 = new BaseHttpSessionIdListener(); Servlet s1 = new BaseChangeSessionIdServlet("test_Listener8"); Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>(); try {/*from w w w.j ava 2 s .c o m*/ Dictionary<String, String> listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); registrations .add(getBundleContext().registerService(HttpSessionIdListener.class, hsil1, listenerProps)); Dictionary<String, String> servletProps1 = new Hashtable<String, String>(); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S8"); servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s"); registrations.add(getBundleContext().registerService(Servlet.class, s1, servletProps1)); requestAdvisor.request("s"); Assert.assertTrue(hsil1.changed.get()); } finally { for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } } }