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.craftercms.security.authentication.impl.RestLogoutSuccessHandlerTest.java
@Test public void testHandle() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/logout.json"); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); handler.handle(context, mock(Authentication.class)); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(EXPECTED_RESPONSE_CONTENT, response.getContentAsString()); }
From source file:au.edu.uq.cmm.paul.servlet.FileView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws IOException { File file = (File) model.get("file"); String contentType = (String) model.get("contentType"); try (FileInputStream fis = new FileInputStream(file)) { response.setContentType(contentType); long length = file.length(); if (length <= Integer.MAX_VALUE) { response.setContentLength((int) length); }/*ww w. j av a 2 s. co m*/ response.setStatus(HttpServletResponse.SC_OK); try (OutputStream os = response.getOutputStream()) { byte[] buffer = new byte[8192]; int nosRead; while ((nosRead = fis.read(buffer)) > 0) { os.write(buffer, 0, nosRead); } } } catch (FileNotFoundException ex) { LOG.info("Cannot access file: " + ex.getLocalizedMessage()); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }
From source file:com.create.security.OAuth2LogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String token = request.getHeader(HEADER_AUTHORIZATION); if (token != null && token.startsWith(BEARER_AUTHENTICATION)) { OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token.split(" ")[0]); if (oAuth2AccessToken != null) { tokenStore.removeAccessToken(oAuth2AccessToken); }/* www .jav a 2 s . c o m*/ } response.setStatus(HttpServletResponse.SC_OK); }
From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); if (request.getQueryString() != null && request.getQueryString().equals("wsdl")) { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/xml"); writeWsdl(writer);// w ww .ja va2 s.c o m } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentType("text/html"); writer.append("404: page not found"); } writer.flush(); writer.close(); }
From source file:gov.nih.nci.nbia.servlet.DownloadServletVersion.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String os = request.getParameter(osParam); String urlForDownload = null; if (os.startsWith("windows")) { urlForDownload = winUrl;//from ww w. ja v a2 s . c o m } else if (os.startsWith("mac")) { urlForDownload = macUrl; } else if (os.equals("CentOS")) { urlForDownload = centOsUrl; } else if (os.equals("Ubuntu")) { urlForDownload = ubuntuUrl; } String forcedGrade = null; try { forcedGrade = NCIAConfig.getDownloaderAppForcedUpgrade(); } catch (RuntimeException ex) { forcedGrade = "false"; //ex.printStackTrace(); } response.setStatus(HttpServletResponse.SC_OK); List<String> readLines = new ArrayList<String>(); readLines.add(NCIAConfig.getLatestDownloaderVersion()); readLines.add(urlForDownload); readLines.add(NCIAConfig.getEncryptionKey()); readLines.add(forcedGrade); readLines.add(helpDeskLink); readLines.add(wikiLink); OutputStream outStream = response.getOutputStream(); IOUtils.writeLines(readLines, System.getProperty("line.separator"), outStream); outStream.close(); }
From source file:org.everit.osgi.authentication.cas.tests.SampleApp.java
public static void pingCasLoginUrl(final BundleContext bundleContext) throws Exception { CloseableHttpClient httpClient = new SecureHttpClient(null, bundleContext).getHttpClient(); HttpGet httpGet = new HttpGet(CAS_LOGIN_URL + "?" + LOCALE); HttpResponse httpResponse = null;//from w w w .j a v a 2s. c om try { httpResponse = httpClient.execute(httpGet); Assert.assertEquals(CAS_PING_FAILURE_MESSAGE, HttpServletResponse.SC_OK, httpResponse.getStatusLine().getStatusCode()); } catch (Exception e) { e.printStackTrace(); Assert.fail(CAS_PING_FAILURE_MESSAGE); } finally { if (httpResponse != null) { EntityUtils.consume(httpResponse.getEntity()); } httpClient.close(); } }
From source file:de.mpg.imeji.presentation.servlet.ExportServlet.java
/** * {@inheritDoc}/*from w ww . j a v a2 s. co m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { SessionBean session = getSessionBean(req, resp); String instanceName = session.getInstanceName(); User user = session.getUser(); try { ExportManager exportManager = new ExportManager(resp.getOutputStream(), user, req.getParameterMap()); String exportName = instanceName + "_"; exportName += new Date().toString().replace(" ", "_").replace(":", "-"); if (exportManager.getContentType().equalsIgnoreCase("application/xml")) { exportName += ".xml"; } if (exportManager.getContentType().equalsIgnoreCase("application/zip")) { exportName += ".zip"; } resp.setHeader("Connection", "close"); resp.setHeader("Content-Type", exportManager.getContentType()); resp.setHeader("Content-disposition", "filename=" + exportName); resp.setStatus(HttpServletResponse.SC_OK); SearchResult result = exportManager.search(); exportManager.export(result); resp.getOutputStream().flush(); } catch (HttpResponseException he) { resp.sendError(he.getStatusCode(), he.getMessage()); } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:org.apache.servicemix.http.WsdlRoundtripTest.java
public void test() throws Exception { GetMethod get = new GetMethod("http://localhost:8192/Service/?wsdl"); int state = new HttpClient().executeMethod(get); assertEquals(HttpServletResponse.SC_OK, state); Document doc = (Document) new SourceTransformer() .toDOMNode(new StringSource(get.getResponseBodyAsString())); // Test WSDL//from w ww. ja v a 2s .c o m WSDLFactory factory = WSDLFactory.newInstance(); WSDLReader reader = factory.newWSDLReader(); Definition def; def = reader.readWSDL("http://localhost:8192/Service/?wsdl", doc); StringWriter writer = new StringWriter(); factory.newWSDLWriter().writeWSDL(def, writer); log.info(writer.toString()); Binding b = (Binding) def.getBindings().values().iterator().next(); BindingOperation bop = (BindingOperation) b.getBindingOperations().iterator().next(); assertEquals(1, bop.getExtensibilityElements().size()); ExtensibilityElement ee = (ExtensibilityElement) bop.getExtensibilityElements().iterator().next(); assertTrue(ee instanceof SOAPOperation); assertEquals("", ((SOAPOperation) ee).getSoapActionURI()); }
From source file:com.coroptis.coidi.rp.services.impl.HttpTranportServiceImpl.java
@Override public Map<String, String> doPost(final String url, final Map<String, String> map) { Preconditions.checkNotNull(url, "URL"); try {//from w w w. j a v a 2 s . c o m HttpPost post = new HttpPost(url); post.getParams().setBooleanParameter(AllClientPNames.HANDLE_REDIRECTS, false); post.setEntity(new UrlEncodedFormEntity(httpService.toList(map), "UTF-8")); HttpResponse httpResponse = httpService.getHttpClient().execute(post); String resp = EntityUtils.toString(httpResponse.getEntity()); if (HttpServletResponse.SC_OK == httpResponse.getStatusLine().getStatusCode()) { logger.debug("HTTP status code '{}' response: {}", httpResponse.getStatusLine().getStatusCode(), resp); return httpService.convertToMap(resp); } else { logger.error("HTTP status code '{}' invalid response: {}", httpResponse.getStatusLine().getStatusCode(), resp); throw new CoidiException( "Unable to process response code '" + httpResponse.getStatusLine().getStatusCode() + "'"); } } catch (ParseException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } }
From source file:biz.taoconsulting.dominodav.methods.OPTIONS.java
/** * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action() *//*ww w . j a v a 2s. c o m*/ protected void action() { // Options have a path associated -- and do we need to reply repository // specific // ToDo: Resource Specific Options!!! String methods = this.getRepository().getAvailableMethods(); LOGGER.debug("Methods: " + methods); this.getResp().addHeader("Allow", methods); this.setHTTPStatus(HttpServletResponse.SC_OK); // We are good here this.getResp().setContentLength(0); }