List of usage examples for javax.servlet.http HttpServletResponse SC_OK
int SC_OK
To view the source code for javax.servlet.http HttpServletResponse SC_OK.
Click Source Link
From source file:org.jboss.as.test.clustering.cluster.singleton.SingletonServiceTestCase.java
@Test public void testSingletonService( @ArquillianResource(NodeServiceServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(NodeServiceServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { // Needed to be able to inject ArquillianResource stop(CONTAINER_2);/*from www . ja v a 2s. co m*/ try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_1))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute( new HttpGet(NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.QUORUM_SERVICE_NAME))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(NodeServiceServlet.NODE_HEADER)); } finally { HttpClientUtils.closeQuietly(response); } start(CONTAINER_2); response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } stop(CONTAINER_2); response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_1))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute( new HttpGet(NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.QUORUM_SERVICE_NAME))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(NodeServiceServlet.NODE_HEADER)); } finally { HttpClientUtils.closeQuietly(response); } start(CONTAINER_2); response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } stop(CONTAINER_1); response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute( new HttpGet(NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.QUORUM_SERVICE_NAME))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(NodeServiceServlet.NODE_HEADER)); } finally { HttpClientUtils.closeQuietly(response); } start(CONTAINER_1); response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL1, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.DEFAULT_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet( NodeServiceServlet.createURI(baseURL2, NodeServiceActivator.QUORUM_SERVICE_NAME, NODE_2))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } }
From source file:com.pymegest.applicationserver.api.FamiliaController.java
@RequestMapping(value = { "/Familia" }, method = RequestMethod.GET) public void findAll(HttpServletRequest request, HttpServletResponse response) { try {/*from w w w. ja va 2 s.com*/ List<Familia> familias = familiaDAO.findAll(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json; chaset=UTF-8"); ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(familias); response.getWriter().println(json); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8;"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:org.bedework.calsvc.scheduling.hosts.IscheduleClient.java
/** Get the freebusy for the recipients specified in the event object, * e.g. start, end, organizer etc./*from w w w. j av a 2 s .c o m*/ * * @param hi * @param ei * @return Response * @throws CalFacadeException */ public Response getFreeBusy(final HostInfo hi, final EventInfo ei) throws CalFacadeException { discover(hi); IscheduleOut iout = makeFreeBusyRequest(hi, ei); Response resp = new Response(); try { send(iout, hi, resp); if (resp.getResponseCode() != HttpServletResponse.SC_OK) { return resp; } /* We expect something like... * * <C:schedule-response xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"> <C:response> <C:recipient>mailto:bernard@example.com</C:recipient> <C:request-status>2.0;Success</C:request-status> <C:calendar-data>BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Example Corp.//CalDAV Server//EN METHOD:REPLY BEGIN:VFREEBUSY DTSTAMP:20040901T200200Z ORGANIZER:mailto:lisa@example.com DTSTART:20040902T000000Z DTEND:20040903T000000Z UID:34222-232@example.com ATTENDEE;CN=Bernard Desruisseaux:mailto:bernard@ example.com FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20040902T000000Z/ 20040902T090000Z,20040902T170000Z/20040903T000000Z END:VFREEBUSY END:VCALENDAR </C:calendar-data> </C:response> <C:response> <C:recipient>mailto:cyrus@example.com</C:recipient> <C:request-status>2.0;Success</C:request-status> <C:calendar-data>BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Example Corp.//CalDAV Server//EN METHOD:REPLY BEGIN:VFREEBUSY DTSTAMP:20040901T200200Z ORGANIZER:mailto:lisa@example.com DTSTART:20040902T000000Z DTEND:20040903T000000Z UID:34222-232@example.com ATTENDEE;CN=Cyrus Daboo:mailto:cyrus@example.com FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20040902T000000Z/ 20040902T090000Z,20040902T170000Z/20040903T000000Z FREEBUSY;FBTYPE=BUSY:20040902T120000Z/20040902T130000Z END:VFREEBUSY END:VCALENDAR </C:calendar-data> </C:response> </C:schedule-response> */ parseResponse(hi, resp); return resp; } finally { try { if (resp.getClient() != null) { resp.getClient().release(); } } catch (Throwable t) { } } }
From source file:io.fabric8.agent.download.DownloadManagerTest.java
@Test public void testDownloadUsingAuthenticatedProxy() throws Exception { Server server = new Server(0); server.setHandler(new AbstractHandler() { @Override// w w w. j a v a2 s . c o m public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String proxyAuth = request.getHeader("Proxy-Authorization"); if (proxyAuth == null || proxyAuth.trim().equals("")) { response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED); response.addHeader("Proxy-Authenticate", "Basic realm=\"Proxy Server\""); baseRequest.setHandled(true); } else { response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getOutputStream().write(new byte[] { 0x42 }); response.getOutputStream().close(); } } }); server.start(); Properties custom = new Properties(); custom.setProperty("org.ops4j.pax.url.mvn.proxySupport", "true"); String settings = createMavenSettingsWithProxy(server.getConnectors()[0].getLocalPort()); DownloadManager dm = createDownloadManager("http://relevant.not/maven2@id=central", settings, custom); try { StreamProvider df = download(dm, "mvn:x.y/z/1.0"); assertNotNull(df); assertNotNull(df.getUrl()); assertNotNull(df.getFile()); assertEquals("z-1.0.jar", df.getFile().getName()); LOG.info("Downloaded URL={}, FILE={}", df.getUrl(), df.getFile()); } finally { server.stop(); } }
From source file:com.pymegest.applicationserver.api.UsuarioController.java
@RequestMapping(value = { "/Usuario" }, method = RequestMethod.GET) public void findAll(HttpServletRequest request, HttpServletResponse response) { try {/*from www . j a v a2 s .c o m*/ List<Usuario> usuarios = usuarioDAO.findAll(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json; chaset=UTF-8"); ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(usuarios); response.getWriter().println(json); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8;"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTReport.java
/** * The get method get resources of a produced report * Urls in this case look like /report/uniqueidentifier?file=filename *//*from ww w. j a v a 2 s. c o m*/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Get the uri of the resource String uuid = restUtils.extractRepositoryUri(req.getPathInfo()); if (uuid.startsWith("/")) uuid = uuid.substring(1); // Find the report in session... HttpSession session = req.getSession(); Report report = (Report) session.getAttribute(uuid); if (report == null) { restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp, "Report not found (uuid not found in session)"); return; } String file = req.getParameter("file"); if (file != null) { if (!report.getAttachments().containsKey(file)) { restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp, "Report not found (requested file not available for this report)"); return; } else { DataSource ds = (DataSource) report.getAttachments().get(file); restUtils.sendFile(ds, resp); return; } } else { // Send the report description... // Please not that here we may decide to send back a final format based on the accepted // content type.... resp.setContentType("text/xml; charset=UTF-8"); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, report.toXml()); } }
From source file:com.thoughtworks.go.agent.UrlBasedArtifactsRepository.java
@Override public void upload(StreamConsumer console, File file, String destPath, String buildId) { if (!file.exists()) { String message = "Failed to find " + file.getAbsolutePath(); consumeLineWithPrefix(console, message); throw bomb(message); }//from w ww.j a v a 2s . c om int publishingAttempts = 0; Throwable lastException = null; while (publishingAttempts < PUBLISH_MAX_RETRIES) { File tmpDir = null; try { publishingAttempts++; tmpDir = FileUtil.createTempFolder(); File dataToUpload = new File(tmpDir, file.getName() + ".zip"); zipUtil.zip(file, dataToUpload, Deflater.BEST_SPEED); long size; if (file.isDirectory()) { size = FileUtils.sizeOfDirectory(file); } else { size = file.length(); } consumeLineWithPrefix(console, format("Uploading artifacts from %s to %s", file.getAbsolutePath(), getDestPath(destPath))); String normalizedDestPath = normalizePath(destPath); String url = getUploadUrl(buildId, normalizedDestPath, publishingAttempts); int statusCode = httpService.upload(url, size, dataToUpload, artifactChecksums(file, normalizedDestPath)); if (statusCode == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE) { String message = format( "Artifact upload for file %s (Size: %s) was denied by the server. This usually happens when server runs out of disk space.", file.getAbsolutePath(), size); consumeLineWithPrefix(console, message); LOGGER.error( "[Artifact Upload] Artifact upload was denied by the server. This usually happens when server runs out of disk space."); publishingAttempts = PUBLISH_MAX_RETRIES; throw bomb(message + ". HTTP return code is " + statusCode); } if (statusCode < HttpServletResponse.SC_OK || statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES) { throw bomb( "Failed to upload " + file.getAbsolutePath() + ". HTTP return code is " + statusCode); } return; } catch (Throwable e) { String message = "Failed to upload " + file.getAbsolutePath(); LOGGER.error(message, e); consumeLineWithPrefix(console, message); lastException = e; } finally { FileUtil.deleteFolder(tmpDir); } } if (lastException != null) { throw new RuntimeException(lastException); } }
From source file:com.pymegest.applicationserver.api.ProductoController.java
@RequestMapping(value = { "/Producto" }, method = RequestMethod.GET) public void findAll(HttpServletRequest request, HttpServletResponse response) { try {//from w w w. j av a 2 s . co m List<Producto> productos = productoDAO.findAll(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json; chaset=UTF-8"); ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(productos); response.getWriter().println(json); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8;"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:com.pymegest.applicationserver.api.EmpleadoController.java
@RequestMapping(value = { "/Empleado" }, method = RequestMethod.GET) public void findAll(HttpServletRequest request, HttpServletResponse response) { try {/*from w w w. j a v a 2s . com*/ List<Empleado> empleado = empleadoDAO.findAll(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json; chaset=UTF-8"); ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(empleado); response.getWriter().println(json); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8;"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:org.jboss.as.test.clustering.cluster.web.expiration.SessionExpirationTestCase.java
@Test public void test( @ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException, InterruptedException { DefaultHttpClient client = org.jboss.as.test.http.util.HttpClientUtils.relaxedCookieHttpClient(); try {//from w w w .j a v a2 s. co m // This should trigger session creation event, but not added attribute event HttpResponse response = client .execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a"))); try { Assert.assertTrue(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.CREATED_SESSIONS).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and bound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "1"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // Make sure remove attribute event is not fired since attribute does not exist response = client.execute(new HttpGet(SessionOperationServlet.createRemoveURI(baseURL2, "b"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute replaced event, as well as valueBound/valueUnbound binding events response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "2"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REPLACED_ATTRIBUTES).getValue()); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute removed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "3", "4"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("3", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("4", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute removed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createRemoveURI(baseURL1, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("4", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL2, "a", "5"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("5", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger session destroyed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createInvalidateURI(baseURL1))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.DESTROYED_SESSIONS).getValue()); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("5", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL2, "a", "6"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.CREATED_SESSIONS).getValue()); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("6", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should not trigger any events response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a", "7"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("6", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should not trigger any events response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("7", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // Trigger session timeout in 1 second response = client.execute(new HttpGet(SessionOperationServlet.createTimeoutURI(baseURL1, 1))); String sessionId = null; try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); sessionId = response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(); } finally { HttpClientUtils.closeQuietly(response); } // Trigger timeout of sessionId Thread.sleep(2000); // Timeout should trigger session destroyed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL1, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(sessionId, response.getFirstHeader(SessionOperationServlet.DESTROYED_SESSIONS).getValue()); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.CREATED_SESSIONS).getValue()); Assert.assertEquals("7", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } finally { HttpClientUtils.closeQuietly(client); } }