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.nih.nci.cabig.ctms.lookandfeel.AssetServletTest.java
private void assertTestCssReturned() throws IOException, ServletException { servlet.service(request, response);//w ww.j ava 2 s . c om assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals("text/css", response.getContentType()); assertEquals("Content doesn't match test-only.css", "p { font-size: 120% }\n", response.getContentAsString()); }
From source file:net.sf.j2ep.responsehandlers.TraceResponseHandler.java
/** * Will either respond with data from the underlying server * or the proxy's own data.// w w w .java2 s . co m * @see net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.HttpServletResponse) */ public void process(HttpServletResponse response) throws IOException { if (proxyTargeted) { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("content-type", "message/http"); response.setHeader("Connection", "close"); String path = method.getPath(); String protocol = method.getParams().getVersion().toString(); PrintWriter writer = response.getWriter(); writer.println("TRACE " + path + " " + protocol); Header[] headers = method.getRequestHeaders(); for (int i = 0; i < headers.length; i++) { writer.print(headers[i]); } writer.flush(); writer.close(); } else { setHeaders(response); response.setStatus(getStatusCode()); sendStreamToClient(response); } }
From source file:com.parleys.server.frontend.web.ipad.filters.LoginFilter.java
@Override public void doFilter(final ServletRequest req, final ServletResponse response, final FilterChain chain) throws IOException { final HttpServletResponse res = (HttpServletResponse) response; final PrintWriter writer = res.getWriter(); res.setStatus(HttpServletResponse.SC_OK); res.setHeader("Cache-Control", "must-revalidate"); res.setHeader("Expires", "Fri, 30 Oct 1998 14:19:41 GMT"); try {// www . j a va2 s .c o m final String username = req.getParameter("username"); final String password = req.getParameter("password"); if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { final ParleysService bean = applicationContext.getBean(ParleysService.class); final Long userId = bean.getUserId(username, password); final String usernameAndPassword = username + ";" + password; final String encrypted = AESEncrypter.INSTANCE.encrypt(usernameAndPassword); final Cookie rememberMeCookie = new Cookie(PARLEYS_REMEMBER_ME_IPAD, encrypted); rememberMeCookie.setMaxAge(3600 * 24 * 7 * 26); // A half year res.addCookie(rememberMeCookie); writeUserId(writer, userId); } else { writeError(writer); } } catch (Exception e) { writeError(writer); } }
From source file:com.carolinarollergirls.scoreboard.jetty.StreamServlet.java
protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . ja v a 2 s .c o m File streamDir = new File(streamDirName); StringBuffer fileList = new StringBuffer(""); File[] fileArray = streamDir.listFiles(); if (null != fileArray) { Iterator<File> files = Arrays.asList(fileArray).iterator(); while (files.hasNext()) { File f = files.next(); if (f.isFile()) fileList.append(f.getName() + "\n"); } } setTextResponse(response, HttpServletResponse.SC_OK, fileList.toString()); } catch (FileNotFoundException fnfE) { setTextResponse(response, HttpServletResponse.SC_OK, ""); } catch (IllegalArgumentException iaE) { setTextResponse(response, HttpServletResponse.SC_BAD_REQUEST, iaE.getMessage()); } }
From source file:com.berrysys.ussdgw.HttpUtils.java
/** * Do post./*from ww w. j av a 2 s. com*/ * * @param req the req * @param resp the resp * @param dialogListener the dialog listener * @throws IOException Signals that an I/O exception has occurred. */ public static void doPost(HttpServletRequest req, HttpServletResponse resp, final DialogListener dialogListener) throws IOException { boolean available = GlobalNetworkInitiatedSemaphore.getInstance().getSemaphore().tryAcquire(); if (!available) { queueFullLogic(resp); return; } final String ussdAppUrl = req.getHeader("ussd-app-url"); log.trace(String.format("ussd-app-url: %s", ussdAppUrl)); final String payload = getPayload(req); log.trace(String.format("payload: %s", payload)); HawtDispatchUtil.getInstance().queueExecute(new Runnable() { @Override public void run() { processHttpRequest(payload, ussdAppUrl, dialogListener); } }); String response = "Request received successfully."; resp.setContentType("text/html"); resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().println(response); }
From source file:com.controller.email.GetEmailDetailServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww. j a va 2s .c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String mandrillEmailId = request.getParameter("mandrill_email_id"); if (StringUtils.isEmpty(mandrillEmailId)) { Map<String, String> responseMap = new HashMap<>(); responseMap.put("error", "mandrill_email_id is required request parameter"); response.getWriter().write(new Gson().toJson(responseMap)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } response.getWriter().write(new Gson().toJson(MandrillApiHandler.getEmailDetails(mandrillEmailId))); response.getWriter().flush(); response.setStatus(HttpServletResponse.SC_OK); return; } catch (URISyntaxException ex) { Logger.getLogger(GetEmailDetailServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:baggage.hypertoolkit.views.JSONResponse.java
public JSONResponse(boolean b) { this(new Boolean(b), HttpServletResponse.SC_OK); }
From source file:foam.dao.HTTPSink.java
@Override public void put(Object obj, Detachable sub) { HttpURLConnection conn = null; OutputStream os = null;/*www .j a v a 2 s .c o m*/ BufferedWriter writer = null; try { Outputter outputter = null; conn = (HttpURLConnection) new URL(url_).openConnection(); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); if (format_ == Format.JSON) { outputter = new foam.lib.json.Outputter(OutputterMode.NETWORK); conn.addRequestProperty("Accept", "application/json"); conn.addRequestProperty("Content-Type", "application/json"); } else if (format_ == Format.XML) { // TODO: make XML Outputter conn.addRequestProperty("Accept", "application/xml"); conn.addRequestProperty("Content-Type", "application/xml"); } conn.connect(); os = conn.getOutputStream(); writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); writer.write(outputter.stringify((FObject) obj)); writer.flush(); writer.close(); os.close(); // check response code int code = conn.getResponseCode(); if (code != HttpServletResponse.SC_OK) { throw new RuntimeException("Http server did not return 200."); } } catch (Throwable t) { throw new RuntimeException(t); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(os); if (conn != null) { conn.disconnect(); } } }
From source file:com.payu.ratel.tests.HealthcheckTest.java
@Test public void shouldReportServiceAviability() throws Exception { //when/*from w w w. j a va 2s. c om*/ String serviceAddress = strategiesProvider.getFetchStrategy() .fetchServiceAddress(TestService.class.getCanonicalName()); HttpClient client = new DefaultHttpClient(); HttpUriRequest request = new HttpHead(serviceAddress); HttpResponse response = client.execute(request); //then assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK); }
From source file:foam.nanos.blob.FileService.java
@Override protected void download(X x) { OutputStream os = null;/*from ww w.j a va 2 s . c o m*/ HttpServletRequest req = x.get(HttpServletRequest.class); HttpServletResponse resp = x.get(HttpServletResponse.class); try { String path = req.getRequestURI(); String id = path.replaceFirst("/service/" + nspec_.getName() + "/", ""); // find file from file dao File file = (File) fileDAO_.find_(x, id); if (file == null || file.getData() == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // check to see if current user has access to file owner if (userDAO_.find_(x, file.getOwner()) == null) { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } // get blob and blob size // TODO: figure out why delegate is not being set for IdentifiedBlob String blobId = ((IdentifiedBlob) file.getData()).getId(); Blob blob = getDelegate().find_(x, blobId); long size = blob.getSize(); // set response status, content type, content length resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(file.getMimeType()); resp.setHeader("Content-Length", Long.toString(size, 10)); resp.setHeader("Cache-Control", "public"); // output data to response os = resp.getOutputStream(); blob.read(os, 0, size); os.close(); } catch (Throwable t) { t.printStackTrace(); throw new RuntimeException(t); } finally { IOUtils.closeQuietly(os); } }