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_Listener7() throws Exception { BaseHttpSessionAttributeListener hsal1 = new BaseHttpSessionAttributeListener(); Servlet s1 = new BaseServlet("test_Listener7"); Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>(); try {//from w ww. j av a 2s . c om Dictionary<String, String> listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); registrations.add( getBundleContext().registerService(HttpSessionAttributeListener.class, hsal1, 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)); Map<String, List<String>> responseMap = requestAdvisor.request("s", null); Assert.assertTrue(hsal1.added.get()); Assert.assertFalse(hsal1.replaced.get()); Assert.assertFalse(hsal1.removed.get()); List<String> list = responseMap.get("Set-Cookie"); String sessionId = ""; for (String string : list) { if (string.startsWith("JSESSIONID=")) { sessionId = string; int pos = sessionId.indexOf(';'); if (pos != -1) { sessionId = sessionId.substring(0, pos); } } } Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>(); requestHeaders.put("Cookie", Arrays.asList(sessionId)); requestAdvisor.request("s", requestHeaders); Assert.assertTrue(hsal1.added.get()); Assert.assertTrue(hsal1.replaced.get()); Assert.assertFalse(hsal1.removed.get()); requestAdvisor.request("s", requestHeaders); Assert.assertTrue(hsal1.added.get()); Assert.assertTrue(hsal1.replaced.get()); Assert.assertTrue(hsal1.removed.get()); } finally { for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } } }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ServletContextHelper13() throws Exception { BundleContext bundleContext = getBundleContext(); Bundle bundle = bundleContext.getBundle(); // test that the helper handlesecurity is called before the filter by setting an attribute on the request ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) { @Override/*from w w w. j av a2 s.c o m*/ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException { request.setAttribute(getName(), Boolean.TRUE); return super.handleSecurity(request, response); } }; Filter f1 = new Filter() { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getAttribute(getName()) == Boolean.TRUE) { request.setAttribute(getName() + ".fromFilter", Boolean.TRUE); } chain.doFilter(request, response); } @Override public void destroy() { } }; Servlet s1 = new HttpServlet() { private static final long serialVersionUID = 1L; @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { res.getWriter().print(req.getAttribute(getName() + ".fromFilter")); } }; 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> filterProps = new Hashtable<String, String>(); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/*"); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)"); registrations.add(bundleContext.registerService(Filter.class, f1, filterProps)); 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(Boolean.TRUE.toString(), actual); } finally { for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } } }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
protected Dictionary getFakeAppliance() { Dictionary device = new Hashtable(); device.put(IAppliance.APPLIANCE_TYPE_PROPERTY, "com.indesit.ah.app.whitegood"); device.put(IAppliance.APPLIANCE_NAME_PROPERTY, "Pippo"); device.put(IAppliance.APPLIANCE_ICON_PROPERTY, "lavatrice.png"); device.put(IAppliance.APPLIANCE_LOCATION_PID_PROPERTY, "1"); device.put(IAppliance.APPLIANCE_CATEGORY_PID_PROPERTY, "1"); device.put(IAppliance.APPLIANCE_PID, "ah.app.Fake." + Integer.toString(fakeCounter++)); device.put("zigbee.device.profile.id", new Integer(49724)); device.put("zigbee.device.device.id", new Integer(2560)); return device; }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Sessions01() { final AtomicBoolean valueBound = new AtomicBoolean(false); final AtomicBoolean valueUnbound = new AtomicBoolean(false); final HttpSessionBindingListener bindingListener = new HttpSessionBindingListener() { @Override// w w w . j a v a 2 s.c o m public void valueUnbound(HttpSessionBindingEvent event) { valueUnbound.set(true); } @Override public void valueBound(HttpSessionBindingEvent event) { valueBound.set(true); } }; final AtomicBoolean sessionCreated = new AtomicBoolean(false); final AtomicBoolean sessionDestroyed = new AtomicBoolean(false); HttpSessionListener sessionListener = new HttpSessionListener() { @Override public void sessionDestroyed(HttpSessionEvent se) { sessionDestroyed.set(true); } @Override public void sessionCreated(HttpSessionEvent se) { sessionCreated.set(true); } }; HttpServlet sessionServlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); if (session.getAttribute("test.attribute") == null) { session.setAttribute("test.attribute", bindingListener); response.getWriter().print("created"); } else { session.invalidate(); response.getWriter().print("invalidated"); } } }; ServiceRegistration<Servlet> servletReg = null; ServiceRegistration<HttpSessionListener> sessionListenerReg = null; Dictionary<String, Object> servletProps = new Hashtable<String, Object>(); servletProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/sessions"); String actual = null; CookieHandler previous = CookieHandler.getDefault(); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); try { servletReg = getBundleContext().registerService(Servlet.class, sessionServlet, servletProps); Dictionary<String, String> listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); sessionListenerReg = getBundleContext().registerService(HttpSessionListener.class, sessionListener, listenerProps); sessionCreated.set(false); valueBound.set(false); sessionDestroyed.set(false); valueUnbound.set(false); // first call will create the session actual = requestAdvisor.request("sessions"); assertEquals("Wrong result", "created", actual); assertTrue("No sessionCreated called", sessionCreated.get()); assertTrue("No valueBound called", valueBound.get()); assertFalse("sessionDestroyed was called", sessionDestroyed.get()); assertFalse("valueUnbound was called", valueUnbound.get()); sessionCreated.set(false); valueBound.set(false); sessionDestroyed.set(false); valueUnbound.set(false); // second call will invalidate the session actual = requestAdvisor.request("sessions"); assertEquals("Wrong result", "invalidated", actual); assertFalse("sessionCreated was called", sessionCreated.get()); assertFalse("valueBound was called", valueBound.get()); assertTrue("No sessionDestroyed called", sessionDestroyed.get()); assertTrue("No valueUnbound called", valueUnbound.get()); sessionCreated.set(false); sessionDestroyed.set(false); valueBound.set(false); valueUnbound.set(false); // calling again should create the session again actual = requestAdvisor.request("sessions"); assertEquals("Wrong result", "created", actual); assertTrue("No sessionCreated called", sessionCreated.get()); assertTrue("No valueBound called", valueBound.get()); } catch (Exception e) { fail("Unexpected exception: " + e); } finally { if (servletReg != null) { servletReg.unregister(); } if (sessionListenerReg != null) { sessionListenerReg.unregister(); } CookieHandler.setDefault(previous); } }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
public void installAppliance(String appliancePid, Dictionary props) throws HacException { synchronized (lockHacService) { IManagedAppliance appliance = (IManagedAppliance) this.pid2appliance.get(appliancePid); if (appliance == null) { throw new HacException("an appliance can be installed only if has been already created"); }/* w ww .ja v a 2 s. c o m*/ if (!this.installingAppliances.contains(appliance)) { throw new HacException("an appliance can be installed only if has been already created"); } String factoryPid = (String) props.get(IAppliance.APPLIANCE_TYPE_PROPERTY); IApplianceFactory applianceFactory = this.getApplianceFactory(factoryPid); if (applianceFactory == null) { throw new HacException("unable to find a factory"); } try { Configuration c = this.getApplianceCAConfiguration(appliancePid); if (c == null) { c = this.configAdmin.createFactoryConfiguration(factoryPid, null); // FIXME: la seguente riga deve essere scommentata? // overwrite // any property service.pid // props.remove(Constants.SERVICE_PID); props.put("appliance.pid", appliancePid); LOG.debug("created configuration for appliance.pid " + appliancePid); } // remove the ah.status properties to force appliance // installation props.remove("ah.status"); c.update(props); this.installingAppliances.remove(appliance); } catch (Exception e) { LOG.debug(e.getMessage()); throw new HacException("unable to install appliance"); } } }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public synchronized Dictionary getInfosNew() { Vector activeDevices = new Vector(); Vector notActiveDevices = new Vector(); Vector disconnectedDevices = new Vector(); IAppliance[] peerAppliances = greenathomeEndPoint.getPeerAppliances(); for (int i = 0; i < peerAppliances.length; i++) { IAppliance ac = peerAppliances[i]; int availability = 0; int state = 0; int status = 0; boolean isStateChangable = true; String pid = ac.getPid(); String locationName = null; ICategory category = null;/*w w w .j ava 2s . c om*/ Hashtable props = new Hashtable(); // props.put("name", ac.getType()); // props.put("icon", ac.getIcon()); String classname = this.getClass().getName(); int lastdot = classname.lastIndexOf("."); if (lastdot != -1) { classname = classname.substring(lastdot + 1); } props.put("type", classname); props.put("id", pid); props.put("device_state_avail", new Boolean(isStateChangable)); props.put("device_state", new Integer(state)); props.put("availability", new Integer(availability)); props.put("device_status", new Integer(status)); if (locationName != null) { } if (category != null) { props.put("category", category); } // list only the devices that provides the power attribute String attribute = null; // PATCH if (attribute != null) { // double power = attribute.floatValue(); double power = 0; if (availability == 2) { props.put("value", new Double(power)); if (state == 1) { // Connected -> On // add into active list activeDevices.add(props); } else if (state == 0) { // Connected -> Off activeDevices.add(props); } else { // Connected -> NOT in On or in Off state notActiveDevices.add(props); } } else { // device disconnected if (isStateChangable) { disconnectedDevices.add(props); } } // sort the tables according the value field } Dictionary resultTable = new Hashtable(); resultTable.put("activeDevices", activeDevices); resultTable.put("notActiveDevices", notActiveDevices); resultTable.put("disconnectedDevices", disconnectedDevices); return resultTable; } return null; }
From source file:org.paxle.gui.impl.servlets.ConfigView.java
public void setPropertyValues(HttpServletRequest request, HttpServletResponse response, Context context, final boolean reset) throws Exception { final Dictionary<String, Object> props = new Hashtable<String, Object>(); final String pid = request.getParameter("pid"); if (pid == null) { context.put(ERROR_MSG, "No pid supplied."); return;//from w w w . j a va 2s .co m } final String bundleID = request.getParameter("bundleID"); if (bundleID == null) { context.put(ERROR_MSG, "No bundle-ID supplied."); return; } final ConfigTool configTool = (ConfigTool) context.get(ConfigTool.TOOL_NAME); if (configTool == null) { context.put(ERROR_MSG, "Config-Tool not found."); return; } final Configurable configurabel = configTool.getConfigurable(Integer.valueOf(bundleID), pid); if (configurabel == null) { context.put(ERROR_MSG, String.format("No configurable component found for bundle-ID '%s' and PID '%s'.", bundleID, pid)); return; } final Configuration config = configurabel.getConfiguration(); if (config == null) { context.put(ERROR_MSG, "Configuration object not found."); return; } final ObjectClassDefinition ocd = configurabel.getObjectClassDefinition(); if (ocd == null) { context.put(ERROR_MSG, String.format("No ObjectClassDefinition found for service with PID '%s'.", pid)); return; } final AttributeDefinition[] attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); if (attributes == null) { context.put(ERROR_MSG, String.format("No AttributeDefinitions found for service with PID '%s'.", pid)); return; } for (AttributeDefinition attribute : attributes) { String[] attributeDefaults = attribute.getDefaultValue(); // getting configured values String attributeID = attribute.getID(); String[] attributeValueStrings = request.getParameterValues(attributeID); // if no values were found use defaults for the initial configuration /* if (attributeValueStrings == null && attributeDefaults != null && attributeDefaults.length > 0) { attributeValueStrings = attributeDefaults; } */ final Object finalAttributeValues = convertAttributeValues(attribute, (reset) ? attributeDefaults : attributeValueStrings, context); if (finalAttributeValues != null) { props.put(attributeID, finalAttributeValues); } } // update configuration config.update(props); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ServletContextHelper1() throws Exception { BundleContext bundleContext = getBundleContext(); Bundle bundle = bundleContext.getBundle(); ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) { };/*from w w w . j a v a 2 s . co m*/ Dictionary<String, String> contextProps = new Hashtable<String, String>(); registrations .add(bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps)); servletContextHelper = new ServletContextHelper(bundle) { }; contextProps = new Hashtable<String, String>(); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "test.sch.one"); registrations .add(bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps)); servletContextHelper = new ServletContextHelper(bundle) { }; contextProps = new Hashtable<String, String>(); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/test-sch2"); registrations .add(bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps)); servletContextHelper = new ServletContextHelper(bundle) { }; contextProps = new Hashtable<String, String>(); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "Test SCH 3!"); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/test-sch3"); registrations .add(bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps)); servletContextHelper = new ServletContextHelper(bundle) { }; contextProps = new Hashtable<String, String>(); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "test.sch.four"); contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "test$sch$4"); registrations .add(bundleContext.registerService(ServletContextHelper.class, servletContextHelper, contextProps)); ServiceReference<HttpServiceRuntime> serviceReference = bundleContext .getServiceReference(HttpServiceRuntime.class); HttpServiceRuntime runtime = bundleContext.getService(serviceReference); RuntimeDTO runtimeDTO = runtime.getRuntimeDTO(); Assert.assertEquals(5, runtimeDTO.failedServletContextDTOs.length); for (ServiceRegistration<?> registration : registrations) { registration.unregister(); } registrations.clear(); runtimeDTO = runtime.getRuntimeDTO(); Assert.assertEquals(0, runtimeDTO.failedServletContextDTOs.length); }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public void installAppliance(Dictionary props) throws ApplianceException { // TODO probabilmente e' necessario separeare la installAppliance in // set Properties dell'appliance (con accesso ai cluster) synchronized (lockGatH) { String appliancePid = (String) props.get(IAppliance.APPLIANCE_PID); if (appliancePid == null) throw new ApplianceException("appliancePid not set"); try {// w ww . ja va 2s .co m // !!! Energy@home webui compatibility Dictionary c = this.hacService.getManagedConfiguration(appliancePid); props.put(IAppliance.APPLIANCE_TYPE_PROPERTY, c.get(IAppliance.APPLIANCE_TYPE_PROPERTY)); this.hacService.installAppliance(appliancePid, props); } catch (HacException e) { log.error(e); throw new ApplianceException(e.getMessage()); } } }