List of usage examples for javax.servlet ServletContext equals
public boolean equals(Object obj)
From source file:org.echocat.nodoodle.server.BaseUrlsDiscovery.java
public boolean isAvailable(URL url) { if (url == null) { throw new NullPointerException("The url is not defined."); }/*from ww w. j a va 2s. c om*/ final ServletContext servletContext = _servletContext; if (servletContext == null) { throw new IllegalStateException("The init() method was not yet called."); } if (CollectionUtils.isEmpty(_baseUrls)) { throw new IllegalArgumentException("No baseUrls property set."); } boolean baseUrlFound = false; final Iterator<URL> i = _baseUrls.iterator(); while (i.hasNext() && !baseUrlFound) { final URL baseUrl = i.next(); baseUrlFound = url.toExternalForm().startsWith(baseUrl.toExternalForm()); } final boolean result; if (baseUrlFound) { final String uriPath = url.getPath(); final ServletContext servletContextForUrl = servletContext.getContext(uriPath); result = servletContext.equals(servletContextForUrl); } else { result = false; } return result; }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Listener10() throws Exception { BaseServletContextListener scl1 = new BaseServletContextListener(); BaseServletContextListener scl2 = new BaseServletContextListener(); BaseServletContextListener scl3 = new BaseServletContextListener(); Dictionary<String, String> listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); registrations.add(getBundleContext().registerService(ServletContextListener.class, scl1, listenerProps)); listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); registrations.add(getBundleContext().registerService(ServletContextListener.class, scl2, listenerProps)); 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/*from w w w. j a v a 2 s . co m*/ .add(getBundleContext().registerService(ServletContextHelper.class, new ServletContextHelper() { }, contextProps)); listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)"); registrations.add(getBundleContext().registerService(ServletContextListener.class, scl3, listenerProps)); ServletContext servletContext1 = scl1.servletContext; ServletContext servletContext2 = scl2.servletContext; ServletContext servletContext3 = scl3.servletContext; Assert.assertNotNull(servletContext1); Assert.assertNotNull(servletContext2); Assert.assertNotNull(servletContext3); Assert.assertTrue(servletContext1.equals(servletContext1)); Assert.assertTrue(servletContext2.equals(servletContext2)); Assert.assertTrue(servletContext3.equals(servletContext3)); Assert.assertTrue(servletContext1.equals(servletContext2)); Assert.assertFalse(servletContext1.equals(servletContext3)); Assert.assertFalse(servletContext2.equals(servletContext3)); // Asserts two invocations return the same value Assert.assertEquals(servletContext1.hashCode(), servletContext1.hashCode()); Assert.assertEquals(servletContext2.hashCode(), servletContext2.hashCode()); Assert.assertEquals(servletContext3.hashCode(), servletContext3.hashCode()); Assert.assertEquals(servletContext1.hashCode(), servletContext2.hashCode()); Assert.assertNotEquals(servletContext1.hashCode(), servletContext3.hashCode()); Assert.assertNotEquals(servletContext2.hashCode(), servletContext3.hashCode()); }