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:gov.nist.appvet.tool.synchtest.util.ReportUtil.java
/** * This method returns report information to the AppVet ToolAdapter as ASCII * text and cannot attach a file to the response. *///from ww w . j av a2 s . co m public static boolean sendPDFInHttpResponse(HttpServletResponse response, String reportText, ToolStatus reportStatus) { try { File reportFile = new File(reportFilePath); String mimeType = new MimetypesFileTypeMap().getContentType(reportFile); log.debug("Sending mimetype: " + mimeType); response.setContentType(mimeType); response.setHeader("Content-Disposition", "attachment;filename=" + reportFile.getName()); response.setStatus(HttpServletResponse.SC_OK); // HTTP 200 response.setHeader("apprisk", reportStatus.name()); FileInputStream inputStream = new FileInputStream(reportFile); //read the file try { int c; while ((c = inputStream.read()) != -1) { response.getWriter().write(c); } } finally { if (inputStream != null) inputStream.close(); response.getWriter().close(); } // PrintWriter out = response.getWriter(); // out.println(reportText); // out.flush(); // out.close(); log.info("Returned report"); return true; } catch (IOException e) { log.error("Report not sent: " + e.toString()); return false; } }
From source file:org.xmatthew.spy2servers.component.web.ComponentsViewServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = request.getServletPath(); String parameter = request.getParameter("type"); if (StringUtils.isBlank(parameter)) { parameter = "spy"; }// w ww. ja va2 s.c om StringBuffer sbuff = new StringBuffer(1000); sbuff.append("<a href='").append(path).append("?type=spy'>").append("SpyComponents").append("</a> "); sbuff.append("<a href='").append(path).append("?type=alert'>").append("AlertComponents") .append("</a> "); sbuff.append("<a href='").append(path).append("?type=channel'>").append("ChannelAwareComponents") .append("</a> "); sbuff.append("<a href='").append(path).append("?type=rule'>").append("AlertRule").append("</a><br>"); if (componentContext == null) { componentContext = getComponentContext(); } response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); List<Component> components = componentContext.getComponents(); int size = components.size(); List<SpyComponent> spyComponents = new ArrayList<SpyComponent>(size); List<AlertComponent> alertComponents = new ArrayList<AlertComponent>(size); List<MessageAlertChannelActiveAwareComponent> channelAwareComponents; channelAwareComponents = new ArrayList<MessageAlertChannelActiveAwareComponent>(size); CoreComponent coreComponent = null; for (Component component : components) { if (component instanceof SpyComponent) { spyComponents.add((SpyComponent) component); } else if (component instanceof AlertComponent) { alertComponents.add((AlertComponent) component); } else if (component instanceof MessageAlertChannelActiveAwareComponent) { channelAwareComponents.add((MessageAlertChannelActiveAwareComponent) component); } else if (component instanceof CoreComponent) { coreComponent = (CoreComponent) component; } } sbuff.append("<b>Components list:</b><br><br><br>"); if ("spy".equals(parameter)) { getSpyHtmlView(spyComponents, sbuff); } else if ("alert".equals(parameter)) { getAlertHtmlView(alertComponents, sbuff); } else if ("channel".equals(parameter)) { getChannelHtmlView(channelAwareComponents, sbuff); } else if ("rule".equals(parameter)) { if (coreComponent != null) { getAlertRuleHtmlView(coreComponent.getAlertRule(), sbuff); } } response.getWriter().println(sbuff); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTJobSummary.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Get the uri of the resource String url = restUtils.extractRepositoryUri(req.getPathInfo()); if (log.isDebugEnabled()) { log.debug("getting job summary for " + url); }//from ww w. ja v a2 s. c om if (url == null) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "malformed url: " + url); } if (isValidUri(url)) { JobSummary[] summaries = new JobSummary[0]; try { summaries = reportSchedulerService.getReportJobs(url); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "could not locate jobs for report in uri: " + url + axisFault.getLocalizedMessage()); } if (summaries == null) { restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); } else { if (log.isDebugEnabled()) { log.debug("found " + summaries.length + "job summaries for report: " + req.getPathInfo()); } restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, generateSummeryReport(summaries)); } } else throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "bad report uri"); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTJob.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Get the uri of the resource long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo())); // get the resources.... try {/*from ww w . j ava 2 s .com*/ reportSchedulerService.deleteJob(jobId); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage()); } String xml = null; //m.writeResourceDescriptor(job); // send the xml... restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); }
From source file:com.ecyrd.jspwiki.dav.WikiDavServlet.java
@Override protected void doOptions(HttpServletRequest req, HttpServletResponse res) { log.debug("DAV doOptions for path " + req.getPathInfo()); res.setHeader("DAV", "1"); // We support only Class 1 res.setHeader("Allow", "GET, PUT, POST, OPTIONS, PROPFIND, PROPPATCH, MOVE, COPY, DELETE"); res.setStatus(HttpServletResponse.SC_OK); }
From source file:fi.vm.kapa.identification.testservice.TestServiceAuthenticated.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_23); cfg.setDirectoryForTemplateLoading(new File("/opt/templates")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); Map<String, String> values = new HashMap<>(); putIfNotBlank(values, "KAPA_HETU", convertASCIItoUTF8(request.getHeader("nationalIdentificationNumber"))); putIfNotBlank(values, "KAPA_ETUNIMET", convertASCIItoUTF8(request.getHeader("FirstName"))); putIfNotBlank(values, "KAPA_SUKUNIMI", convertASCIItoUTF8(request.getHeader("sn"))); putIfNotBlank(values, "KAPA_PERSON_IDENTIFIER", convertASCIItoUTF8(request.getHeader("PersonIdentifier"))); putIfNotBlank(values, "KAPA_DATE_OF_BIRTH", convertASCIItoUTF8(request.getHeader("DateOfBirth"))); putIfNotBlank(values, "KAPA_FAMILY_NAME", convertASCIItoUTF8(request.getHeader("FamilyName"))); putIfNotBlank(values, "KAPA_KATU", convertASCIItoUTF8(request.getHeader("VakinainenKotimainenLahiosoiteS"))); putIfNotBlank(values, "KAPA_POSTINUMERO", convertASCIItoUTF8(request.getHeader("VakinainenKotimainenLahiosoitePostinumero"))); putIfNotBlank(values, "KAPA_PTP", convertASCIItoUTF8(request.getHeader("VakinainenKotimainenLahiosoitePostitoimipaikkaS"))); putIfNotBlank(values, "KAPA_TOKEN", convertASCIItoUTF8(request.getHeader("authenticationToken"))); Template output = cfg.getTemplate("tunnistautunut.ftlh"); response.setCharacterEncoding("UTF-8"); try {/*from www.j a v a 2 s. c om*/ output.process(values, response.getWriter()); response.setStatus(HttpServletResponse.SC_OK); } catch (TemplateException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } response.getWriter().flush(); response.getWriter().close(); }
From source file:com.fpmislata.banco.presentation.controladores.EntidadBancariaController.java
@RequestMapping(value = { "/entidadbancaria" }, method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public void insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody String jsonEntrada) { try {// w w w .j a v a 2 s . com EntidadBancaria entidadBancaria = (EntidadBancaria) jsonTransformer.fromJsonToObject(jsonEntrada, EntidadBancaria.class); entidadBancariaService.insert(entidadBancaria); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonTransformer.ObjectToJson(entidadBancaria)); } catch (BusinessException ex) { List<BusinessMessage> bussinessMessage = ex.getBusinessMessages(); String jsonSalida = jsonTransformer.ObjectToJson(bussinessMessage); //System.out.println(jsonSalida); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); try { httpServletResponse.getWriter().println(jsonSalida); } catch (IOException ex1) { Logger.getLogger(EntidadBancariaController.class.getName()).log(Level.SEVERE, "Error devolviendo Lista de Mensajes", ex1); } } catch (Exception ex1) { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { ex1.printStackTrace(httpServletResponse.getWriter()); } catch (IOException ex2) { Logger.getLogger(EntidadBancariaController.class.getName()).log(Level.SEVERE, "Error devolviendo la traza", ex2); } } }
From source file:org.codemucker.testserver.TestServerTest.java
@SuppressWarnings("serial") @Test/*from w w w. j a v a2 s . co m*/ public void ensure_can_add_servlet_to_running_server() throws Exception { final Collection<CapturedRequest> capturedRequests = new Vector<CapturedRequest>(); server.start(); server.addServlet("/my/test/path2", new TestServlet() { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { capturedRequests.add(new CapturedRequest(req)); resp.setStatus(HttpServletResponse.SC_OK); } }); final String url = "http://" + server.getHost() + ":" + server.getHttpPort() + "/my/test/path2"; //check we can hit the servlet final HttpClient client = HttpClientBuilder.create().build(); final HttpGet get = new HttpGet(url); final HttpResponse resp = client.execute(get); assertEquals(HttpServletResponse.SC_OK, resp.getStatusLine().getStatusCode()); assertEquals(1, capturedRequests.size()); }
From source file:org.jboss.as.test.clustering.cluster.web.NonDistributableTestCase.java
@Test public void test(@ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = SimpleServlet.createURI(baseURL1); URI uri2 = SimpleServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(uri1)); try {/*from w w w . j av a2 s . co m*/ Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Session identifier should contain the route for this node Assert.assertEquals(NODE_1, entry.getValue()); // Session identifier seen by servlet should *not* contain the route Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); // Session should not be replicated Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Session identifier should contain the route for this node Assert.assertEquals(NODE_2, entry.getValue()); // Session identifier seen by servlet should *not* contain the route Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } } }
From source file:io.lavagna.web.security.login.PersonaLogin.java
@Override public boolean doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!("POST".equalsIgnoreCase(req.getMethod()) && req.getParameterMap().containsKey("assertion"))) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return true; }/*from w ww .jav a 2 s . com*/ String audience = configurationRepository.getValue(Key.PERSONA_AUDIENCE); MultiValueMap<String, String> toPost = new LinkedMultiValueMap<>(); toPost.add("assertion", req.getParameter("assertion")); toPost.add("audience", audience); VerifierResponse verifier = restTemplate.postForObject("https://verifier.login.persona.org/verify", toPost, VerifierResponse.class); if ("okay".equals(verifier.status) && audience.equals(verifier.audience) && userRepository.userExistsAndEnabled(USER_PROVIDER, verifier.email)) { String url = Redirector.cleanupRequestedUrl(req.getParameter("reqUrl")); UserSession.setUser(userRepository.findUserByName(USER_PROVIDER, verifier.email), req, resp, userRepository); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); JsonObject jsonObject = new JsonObject(); jsonObject.add("redirectTo", new JsonPrimitive(url)); resp.getWriter().write(jsonObject.toString()); } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return true; }