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:com.google.api.server.spi.EndpointsServletTest.java
@Test public void echo() throws IOException { req.setRequestURI("/_ah/api/test/v2/echo"); req.setMethod("POST"); req.setParameter("x", "1"); servlet.service(req, resp);/* w w w.ja v a2 s .com*/ assertThat(resp.getStatus()).isEqualTo(HttpServletResponse.SC_OK); ObjectMapper mapper = ObjectMapperUtil.createStandardObjectMapper(); ObjectNode actual = mapper.readValue(resp.getContentAsString(), ObjectNode.class); assertThat(actual.size()).isEqualTo(1); assertThat(actual.get("x").asInt()).isEqualTo(1); }
From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java
private String doGet(HttpClient httpClient, HttpContext httpContext, String location) throws IOException { return doGet(httpClient, httpContext, location, HttpServletResponse.SC_OK); }
From source file:org.obm.healthcheck.server.HealthCheckServletDefaultHandlersTest.java
@Test public void testGetJavaVersion() throws Exception { HttpResponse response = get("/java/version"); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK); assertThat(IO.toString(response.getEntity().getContent())).isEqualTo(System.getProperty("java.version")); }
From source file:hr.diskobolos.controller.MembershipCategoryController.java
/** * REST service responsible for creation of membership category data * * @param membershipCategory/*from www .j av a2 s. c o m*/ * @param request * @param response * @return * @throws JSONException */ @RequestMapping(value = "/create", method = RequestMethod.POST) @ResponseBody @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')") public String createMembershipCategorysData(@RequestBody MembershipCategory membershipCategory, HttpServletRequest request, HttpServletResponse response) throws JSONException { try { membershipCategoryService.persist(membershipCategory); response.setStatus(HttpServletResponse.SC_OK); return new JSONObject().put("result", 200).toString(); } catch (Exception e) { logger.error("Error during creation of membership category data: ", e.getMessage()); return ErrorHandlerUtils.handleAjaxError(request, response); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.ConfigServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { LOGGER.trace("doPost : Setting MMX Configuration"); response.setContentType(CONTENT_TYPE_JSON); PrintWriter out = response.getWriter(); String postBody = PushServlet.getRequestBody(req); if (postBody != null && !postBody.trim().isEmpty()) { LOGGER.trace("doPost : Received Configuration : {}", postBody); SerializableConfig config = GsonData.getGson().fromJson(postBody, SerializableConfig.class); MMXConfiguration configuration = MMXConfiguration.getConfiguration(); Set<String> keys = config.configs.keySet(); for (String key : keys) { //set the value for this configuration // see if this is an XMPP configuration if (MMXConfiguration.isXmppProperty(key)) { JiveGlobals.setProperty(key, config.configs.get(key)); } else { configuration.setValue(key, config.configs.get(key)); }/*from ww w . ja v a 2s.com*/ } response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.nif.NIFMultiController.java
/** * Generates a csv file from experiments//from w w w . j a v a 2s . co m * @param request * @param response * @return * @throws Exception */ public ModelAndView getExperimentsCSVFile(HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("Controller for csv file with creating experiments for NIF"); OutputStream out = null; int headerBufferSize = 8096; response.setHeader("Content-Type", "text/csv"); response.setContentType("text/csv"); response.setHeader("Content-Disposition", "attachment;filename=EEGbase_experiments.csv"); log.debug("Creating output stream"); response.setStatus(HttpServletResponse.SC_OK); response.setBufferSize(headerBufferSize); log.debug("Generating csv"); out = csvFactory.generateExperimentsCsvFile(); ByteArrayOutputStream bout = (ByteArrayOutputStream) out; response.getOutputStream().write(bout.toByteArray()); return null; }
From source file:com.imaginary.home.cloud.api.call.LocationCall.java
static public void main(String... args) throws Exception { if (args.length < 1) { System.err.println("You must specify an action"); System.exit(-1);/*from w ww . j a v a 2 s . c o m*/ return; } String action = args[0]; if (action.equalsIgnoreCase("initializePairing")) { if (args.length < 5) { System.err.println("You must specify a location ID"); System.exit(-2); return; } String endpoint = args[1]; String locationId = args[2]; String apiKeyId = args[3]; String apiKeySecret = args[4]; HashMap<String, Object> act = new HashMap<String, Object>(); act.put("action", "initializePairing"); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //noinspection deprecation HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, "Imaginary Home"); HttpClient client = new DefaultHttpClient(params); HttpPut method = new HttpPut(endpoint + "/location/" + locationId); long timestamp = System.currentTimeMillis(); method.addHeader("Content-Type", "application/json"); method.addHeader("x-imaginary-version", CloudService.VERSION); method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp)); method.addHeader("x-imaginary-api-key", apiKeyId); method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"), "put:/location/" + locationId + ":" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION)); //noinspection deprecation method.setEntity(new StringEntity((new JSONObject(act)).toString(), "application/json", "UTF-8")); HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { e.printStackTrace(); throw new CommunicationException(e); } if (status.getStatusCode() == HttpServletResponse.SC_OK) { String json = EntityUtils.toString(response.getEntity()); JSONObject u = new JSONObject(json); System.out.println((u.has("pairingCode") && !u.isNull("pairingCode")) ? u.getString("pairingCode") : "--no code--"); } else { System.err.println("Failed to initialize pairing (" + status.getStatusCode() + ": " + EntityUtils.toString(response.getEntity())); System.exit(status.getStatusCode()); } } else if (action.equalsIgnoreCase("create")) { if (args.length < 7) { System.err.println("create ENDPOINT NAME DESCRIPTION TIMEZONE API_KEY_ID API_KEY_SECRET"); System.exit(-2); return; } String endpoint = args[1]; String name = args[2]; String description = args[3]; String tz = args[4]; String apiKeyId = args[5]; String apiKeySecret = args[6]; HashMap<String, Object> lstate = new HashMap<String, Object>(); lstate.put("name", name); lstate.put("description", description); lstate.put("timeZone", tz); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //noinspection deprecation HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, "Imaginary Home"); HttpClient client = new DefaultHttpClient(params); HttpPost method = new HttpPost(endpoint + "/location"); long timestamp = System.currentTimeMillis(); System.out.println( "Signing: " + "post:/location:" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION); method.addHeader("Content-Type", "application/json"); method.addHeader("x-imaginary-version", CloudService.VERSION); method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp)); method.addHeader("x-imaginary-api-key", apiKeyId); method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"), "post:/location:" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION)); //noinspection deprecation method.setEntity(new StringEntity((new JSONObject(lstate)).toString(), "application/json", "UTF-8")); HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { e.printStackTrace(); throw new CommunicationException(e); } if (status.getStatusCode() == HttpServletResponse.SC_CREATED) { String json = EntityUtils.toString(response.getEntity()); JSONObject u = new JSONObject(json); System.out.println((u.has("locationId") && !u.isNull("locationId")) ? u.getString("locationId") : "--no location--"); } else { System.err.println("Failed to create location (" + status.getStatusCode() + ": " + EntityUtils.toString(response.getEntity())); System.exit(status.getStatusCode()); } } else { System.err.println("No such action: " + action); System.exit(-3); } }
From source file:nl.dtls.fairdatapoint.api.controller.MetadataControllerTest.java
/** * Check supported accept headers.// w ww .j a va2s.c o m * * @throws Exception */ @Test public void supportedAcceptHeaders() throws Exception { MockHttpServletRequest request; MockHttpServletResponse response; Object handler; request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); request.setMethod("GET"); request.addHeader(HttpHeaders.ACCEPT, "text/turtle"); request.setRequestURI("/textmining"); handler = handlerMapping.getHandler(request).getHandler(); handlerAdapter.handle(request, response, handler); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); request.addHeader(HttpHeaders.ACCEPT, "text/n3"); handler = handlerMapping.getHandler(request).getHandler(); handlerAdapter.handle(request, response, handler); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); request.setRequestURI("/textmining/gene-disease-association_lumc"); request.addHeader(HttpHeaders.ACCEPT, "application/ld+json"); handler = handlerMapping.getHandler(request).getHandler(); handlerAdapter.handle(request, response, handler); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); request.addHeader(HttpHeaders.ACCEPT, "application/rdf+xml"); handler = handlerMapping.getHandler(request).getHandler(); handlerAdapter.handle(request, response, handler); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); }
From source file:com.fpmislata.banco.presentation.controladores.SucursalBancariaController.java
@RequestMapping(value = { "/sucursalbancaria" }, method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public void insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody String jsonEntrada) { try {//from w ww. ja v a 2s . com SucursalBancaria sucursalBancaria = (SucursalBancaria) jsonTransformer.fromJsonToObject(jsonEntrada, SucursalBancaria.class); sucursalBancariaService.insert(sucursalBancaria); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonTransformer.ObjectToJson(sucursalBancaria)); } 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(SucursalBancariaController.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(SucursalBancariaController.class.getName()).log(Level.SEVERE, "Error devolviendo la traza", ex2); } } }
From source file:org.apache.servicemix.http.security.HttpSecurityTest.java
protected void testAuthenticate(final String username, final String password) throws Exception { HttpClient client = new HttpClient(); client.getState().setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(username, password)); PostMethod method = new PostMethod("http://localhost:8192/Service/"); try {//from w w w .j a v a 2 s . c om method.setDoAuthentication(true); method.setRequestEntity(new StringRequestEntity("<hello>world</hello>")); int state = client.executeMethod(method); FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err); if (state != HttpServletResponse.SC_OK && state != HttpServletResponse.SC_ACCEPTED) { throw new IllegalStateException("Http status: " + state); } } finally { method.releaseConnection(); } }