Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

In this page you can find the example usage for java.util Dictionary put.

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Servlet16() throws Exception {
    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override/*from   w ww .j a v  a 2  s .c o  m*/
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException, ServletException {

            Part part = req.getPart("file");
            Assert.assertNotNull(part);

            String submittedFileName = part.getSubmittedFileName();
            String contentType = part.getContentType();
            long size = part.getSize();

            PrintWriter writer = resp.getWriter();

            writer.write(submittedFileName);
            writer.write("|");
            writer.write(contentType);
            writer.write("|" + size);
        }
    };

    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S16");
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Servlet16/*");
    props.put("equinox.http.multipartSupported", Boolean.TRUE);
    registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));

    Map<String, List<Object>> map = new HashMap<String, List<Object>>();

    map.put("file", Arrays.<Object>asList(getClass().getResource("resource1.txt")));

    Map<String, List<String>> result = requestAdvisor.upload("Servlet16/do", map);

    Assert.assertEquals("200", result.get("responseCode").get(0));
    Assert.assertEquals("resource1.txt|text/plain|1", result.get("responseBody").get(0));
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Servlet17() throws Exception {
    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override/*from  w  ww .ja v a 2  s.c  om*/
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException, ServletException {

            Part part = req.getPart("file");
            Assert.assertNotNull(part);

            String submittedFileName = getSubmittedFileName(part);
            String contentType = part.getContentType();
            long size = part.getSize();

            PrintWriter writer = resp.getWriter();

            writer.write(submittedFileName);
            writer.write("|");
            writer.write(contentType);
            writer.write("|" + size);
        }
    };

    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S16");
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Servlet16/*");
    props.put("equinox.http.multipartSupported", Boolean.TRUE);
    registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));

    Map<String, List<Object>> map = new HashMap<String, List<Object>>();

    map.put("file", Arrays.<Object>asList(getClass().getResource("blue.png")));

    Map<String, List<String>> result = requestAdvisor.upload("Servlet16/do", map);

    Assert.assertEquals("200", result.get("responseCode").get(0));
    Assert.assertEquals("blue.png|image/png|292", result.get("responseBody").get(0));
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Listener3() throws Exception {
    BundleContext bundleContext = getBundleContext();
    Bundle bundle = bundleContext.getBundle();

    ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) {
    };//from  w  ww  . ja  v  a 2  s  .c om
    BaseServletContextListener scl1 = new BaseServletContextListener();
    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {
        Dictionary<String, String> contextProps = new Hashtable<String, String>();
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/a");
        registrations.add(
                bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps));

        Dictionary<String, String> listenerProps = new Hashtable<String, String>();
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
        registrations.add(bundleContext.registerService(ServletContextListener.class, scl1, listenerProps));

        Assert.assertTrue(scl1.initialized.get());
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
        Assert.assertTrue(scl1.destroyed.get());
    }
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Listener5() throws Exception {

    BaseServletRequestListener srl1 = new BaseServletRequestListener();

    Servlet s1 = new BaseServlet("a");

    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {/*from w  ww  . ja v  a  2 s.com*/
        Dictionary<String, String> listenerProps = new Hashtable<String, String>();
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
        registrations
                .add(getBundleContext().registerService(ServletRequestListener.class, srl1, listenerProps));

        Dictionary<String, String> servletProps1 = new Hashtable<String, String>();
        servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1");
        servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s");
        registrations.add(getBundleContext().registerService(Servlet.class, s1, servletProps1));

        requestAdvisor.request("s");

        Assert.assertTrue(srl1.initialized.get());
        Assert.assertTrue(srl1.destroyed.get());
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
    }
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Listener6() throws Exception {

    BaseServletRequestAttributeListener sral1 = new BaseServletRequestAttributeListener();

    Servlet s1 = new BaseServlet("a");

    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {/* w ww .  j a  v a 2  s .c om*/
        Dictionary<String, String> listenerProps = new Hashtable<String, String>();
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
        registrations.add(getBundleContext().registerService(ServletRequestAttributeListener.class, sral1,
                listenerProps));

        Dictionary<String, String> servletProps1 = new Hashtable<String, String>();
        servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1");
        servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s");
        registrations.add(getBundleContext().registerService(Servlet.class, s1, servletProps1));

        requestAdvisor.request("s");

        Assert.assertTrue(sral1.added.get());
        Assert.assertTrue(sral1.replaced.get());
        Assert.assertTrue(sral1.removed.get());
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
    }
}

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.
 *///w  ww . j  a va  2  s.  c  om
public void test_ErrorPage7() throws Exception {
    final int status = 422;

    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {

            resp.setStatus(status);

            PrintWriter printWriter = new PrintWriter(resp.getOutputStream());

            printWriter.println("{");
            printWriter.println("error: 'An error message',");
            printWriter.println("code: 'An error code'");
            printWriter.println("}");

            printWriter.flush();
        }
    };

    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E7");
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage7/*");
    registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));
    props = new Hashtable<String, Object>();
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E7.error");
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, String.valueOf(status));
    registrations.add(
            getBundleContext().registerService(Servlet.class, new ErrorServlet(String.valueOf(status)), props));

    Map<String, List<String>> response = requestAdvisor.request("TestErrorPage7/a", null);

    String responseCode = response.get("responseCode").get(0);
    String responseBody = response.get("responseBody").get(0);

    Assert.assertEquals(String.valueOf(status), responseCode);
    Assert.assertNotEquals(status + " : " + status + " : ERROR : /TestErrorPage7/a", responseBody);
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Listener2() throws Exception {
    BundleContext bundleContext = getBundleContext();
    Bundle bundle = bundleContext.getBundle();

    ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) {
    };// www  . j a  va  2  s . co  m
    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {
        Dictionary<String, String> contextProps = new Hashtable<String, String>();
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/a");
        registrations.add(
                bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps));

        BaseServletContextListener scl1 = new BaseServletContextListener();
        Dictionary<String, String> listenerProps = new Hashtable<String, String>();
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
        listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
        ServiceRegistration<ServletContextListener> registration = getBundleContext()
                .registerService(ServletContextListener.class, scl1, listenerProps);
        registration.unregister();

        Assert.assertTrue(scl1.initialized.get());
        Assert.assertTrue(scl1.destroyed.get());
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
    }
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_ServletContextHelper8() throws Exception {
    String expected = "b";

    BundleContext bundleContext = getBundleContext();
    Bundle bundle = bundleContext.getBundle();
    ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) {
    };//from  w ww  .  j  ava2  s .  co  m
    Servlet s1 = new BaseServlet("b");

    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {
        Dictionary<String, String> contextProps = new Hashtable<String, String>();
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/a");
        registrations.add(
                bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps));

        Dictionary<String, String> servletProps = new Hashtable<String, String>();
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1");
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s1");
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
        registrations.add(bundleContext.registerService(Servlet.class, s1, servletProps));

        String actual = requestAdvisor.request("a/s1");

        Assert.assertEquals(expected, actual);
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
    }
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_ServletContextHelper7() throws Exception {
    String expected = "a";

    BundleContext bundleContext = getBundleContext();
    Bundle bundle = bundleContext.getBundle();

    ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) {
    };//from w w w  .j av a2 s. c  om
    Servlet s1 = new BaseServlet("a");

    Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
    try {
        Dictionary<String, String> contextProps = new Hashtable<String, String>();
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
        contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/");
        registrations.add(
                bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps));

        Dictionary<String, String> servletProps = new Hashtable<String, String>();
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1");
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s1");
        servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
        registrations.add(bundleContext.registerService(Servlet.class, s1, servletProps));

        String actual = requestAdvisor.request("s1");

        Assert.assertEquals(expected, actual);
    } finally {
        for (ServiceRegistration<?> registration : registrations) {
            registration.unregister();
        }
    }
}

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void testWBServletDefaultContextAdaptor1() throws Exception {
    Dictionary<String, String> helperProps = new Hashtable<String, String>();
    helperProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "testContext" + getName());
    helperProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/testContext");
    helperProps.put(TEST_PATH_CUSTOMIZER_NAME, getName());
    ServiceRegistration<ServletContextHelper> helperReg = getBundleContext()
            .registerService(ServletContextHelper.class, new TestServletContextHelperFactory(), helperProps);

    ServiceRegistration<ContextPathCustomizer> pathAdaptorReg = null;
    try {//www  .  j a  v a 2s.  c  om
        Map<String, String> params = new HashMap<String, String>();
        params.put(TEST_PROTOTYPE_NAME, getName());
        params.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, '/' + getName());
        params.put(STATUS_PARAM, getName());
        params.put("servlet.init." + TEST_PATH_CUSTOMIZER_NAME, getName());
        String actual = doRequest(CONFIGURE, params);
        Assert.assertEquals(getName(), actual);

        actual = requestAdvisor.request(getName());
        Assert.assertEquals(getName(), actual);

        ContextPathCustomizer pathAdaptor = new TestContextPathAdaptor("("
                + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + "testContext" + getName() + ")",
                null, getName());
        pathAdaptorReg = getBundleContext().registerService(ContextPathCustomizer.class, pathAdaptor, null);

        actual = requestAdvisor.request("testContext/" + getName());
        Assert.assertEquals(getName(), actual);

        pathAdaptorReg.unregister();
        pathAdaptorReg = null;

        actual = requestAdvisor.request(getName());
        Assert.assertEquals(getName(), actual);
    } finally {
        helperReg.unregister();
        if (pathAdaptorReg != null) {
            pathAdaptorReg.unregister();
        }
    }
}