List of usage examples for javax.servlet.http HttpServletResponse SC_NO_CONTENT
int SC_NO_CONTENT
To view the source code for javax.servlet.http HttpServletResponse SC_NO_CONTENT.
Click Source Link
From source file:com.imaginary.home.device.hue.HueMethod.java
public void delete(@Nonnull String resource) throws HueException { Logger std = Hue.getLogger(HueMethod.class); Logger wire = Hue.getWireLogger(HueMethod.class); if (std.isTraceEnabled()) { std.trace("enter - " + HueMethod.class.getName() + ".delete(" + resource + ")"); }/*from ww w .ja v a 2s .co m*/ if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource); } try { HttpClient client = getClient(); HttpDelete method = new HttpDelete(hue.getAPIEndpoint() + resource); method.addHeader("Content-Type", "application/json"); if (wire.isDebugEnabled()) { wire.debug(method.getRequestLine().toString()); for (Header header : method.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); } HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { std.error("DELETE: Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); if (std.isTraceEnabled()) { e.printStackTrace(); } throw new HueException(e); } if (std.isDebugEnabled()) { std.debug("DELETE: HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() != HttpServletResponse.SC_OK && status.getStatusCode() != HttpServletResponse.SC_NO_CONTENT && status.getStatusCode() != HttpServletResponse.SC_ACCEPTED) { std.error("DELETE: Expected OK or NO_CONTENT or ACCEPTED for DELETE request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new HueException(status.getStatusCode(), "An error was returned without explanation"); } String body; try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new HueException(status.getStatusCode(), e.getMessage()); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); throw new HueException(status.getStatusCode(), body); } } finally { if (std.isTraceEnabled()) { std.trace("exit - " + HueMethod.class.getName() + ".delete()"); } if (wire.isDebugEnabled()) { wire.debug("<<< [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } }
From source file:org.alfresco.services.TextRepoContentGetter.java
public GetTextContentResponse getTextContent(Long nodeId, QName propertyQName, Long modifiedSince) throws AuthenticationException, IOException, org.alfresco.httpclient.AuthenticationException { StringBuilder url = new StringBuilder(128); url.append(GET_CONTENT);/*from w ww . ja va 2 s .c om*/ StringBuilder args = new StringBuilder(128); if (nodeId != null) { args.append("?"); args.append("nodeId"); args.append("="); args.append(nodeId); } else { throw new NullPointerException("getTextContent(): nodeId cannot be null."); } if (propertyQName != null) { if (args.length() == 0) { args.append("?"); } else { args.append("&"); } args.append("propertyQName"); args.append("="); args.append(URLEncoder.encode(propertyQName.toString())); } url.append(args); GetRequest req = new GetRequest(url.toString()); if (modifiedSince != null) { Map<String, String> headers = new HashMap<String, String>(1, 1.0f); headers.put("If-Modified-Since", String.valueOf(DateUtil.formatDate(new Date(modifiedSince)))); req.setHeaders(headers); } Response response = repoClient.sendRequest(req); if (response.getStatus() != HttpServletResponse.SC_NOT_MODIFIED && response.getStatus() != HttpServletResponse.SC_NO_CONTENT && response.getStatus() != HttpServletResponse.SC_OK) { throw new AlfrescoRuntimeException("GetTextContentResponse return status is " + response.getStatus()); } return new GetTextContentResponse(response); }
From source file:de.mpg.mpdl.inge.pidcache.web.MainServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache POST request"); if (req.getParameter("url") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed."); }/* w w w .java 2s. co m*/ try { if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService cacheService = new PidCacheService(); String xmlOutput = null; if (GwdgPidService.GWDG_PIDSERVICE_CREATE.equals(req.getPathInfo())) { xmlOutput = cacheService.create(req.getParameter("url")); } else if (GwdgPidService.GWDG_PIDSERVICE_EDIT.equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } xmlOutput = cacheService.update(req.getParameter("pid"), req.getParameter("url")); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } resp.setStatus(cacheService.getStatus()); resp.encodeRedirectURL(cacheService.getLocation()); resp.addHeader("Location", cacheService.getLocation()); resp.getWriter().append(xmlOutput); } catch (Exception e) { throw new ServletException("Error processing request", e); } }
From source file:com.evolveum.midpoint.gui.impl.util.ReportPeerQueryInterceptor.java
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { if (!checkRequest(request, response, OPERATION_DELETE_REPORT)) { return;/* w w w .ja v a 2s . c o m*/ } String fileName = getFileName(request); StringBuilder buildfilePath = new StringBuilder(EXPORT_DIR).append(fileName); String filePath = buildfilePath.toString(); File reportFile = new File(filePath); if (!isFileAndExists(reportFile, fileName, response, OPERATION_DELETE_REPORT)) { return; } reportFile.delete(); response.setStatus(HttpServletResponse.SC_NO_CONTENT); LOGGER.trace("Deletion of the file {} has finished.", fileName); }
From source file:org.eclipse.orion.server.servlets.PreferencesServlet.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MetadataInfo info = getNode(req, resp); if (info == null) { //should not fail on delete when resource doesn't exist resp.setStatus(HttpServletResponse.SC_NO_CONTENT); return;//from w ww . j av a 2 s .co m } String key = req.getParameter("key"); try { String prefix = getPrefix(req); //if a key is specified write that single value, otherwise write the entire node boolean changed = false; if (key != null) { prefix = prefix + '/' + key; changed = info.setProperty(prefix.toString(), null) != null; } else { //can't overwrite base user settings via preference servlet if (prefix.startsWith("user/")) { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } changed = removeMatchingProperties(info, prefix.toString()); } if (changed) save(info); resp.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (Exception e) { handleException(resp, NLS.bind("Failed to retrieve preferences for path {0}", req.getPathInfo()), e); return; } }
From source file:org.opencastproject.inspection.impl.endpoints.MediaInspectionRestEndpoint.java
@GET @Produces(MediaType.TEXT_XML)//from ww w . j ava2 s .com @Path("inspect") @RestQuery(name = "inspect", description = "Analyze a given media file, returning a receipt to check on the status and outcome of the job", restParameters = { @RestParameter(description = "Location of the media file.", isRequired = false, name = "uri", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "XML encoded receipt is returned.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "Service unavailabe or not currently present", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE), @RestResponse(description = "Problem retrieving media file or invalid media file or URL.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "") public Response inspectTrack(@QueryParam("uri") URI uri) { checkNotNull(service); try { Job job = service.inspect(uri); return Response.ok(new JaxbJob(job)).build(); } catch (Exception e) { logger.info(e.getMessage()); return Response.serverError().build(); } }
From source file:com.homesnap.webserver.AbstractRestApi.java
protected JSONObject deleteRequestJSONObject(String urn, int returnCodeExpected) { Client client = Client.create();/*from ww w . j a v a2 s .co m*/ WebResource webResource = client.resource("http://" + server + ":" + port + urn); ClientResponse response = webResource.accept("application/json").delete(ClientResponse.class); Assert.assertEquals(returnCodeExpected, response.getStatus()); if (returnCodeExpected == HttpServletResponse.SC_NO_CONTENT || returnCodeExpected == HttpServletResponse.SC_NOT_ACCEPTABLE || returnCodeExpected == HttpServletResponse.SC_NOT_IMPLEMENTED) { return null; } String json = null; try { json = response.getEntity(String.class); return JSonTools.fromJson(json); } catch (JSONException e) { e.printStackTrace(); Assert.fail("Problem with JSON [" + json + "] :" + e.getMessage()); } return null; }
From source file:com.pymegest.applicationserver.api.SessionController.java
@RequestMapping(value = { "/Session" }, method = RequestMethod.DELETE) public void delete(HttpServletRequest httpServletRequest, HttpServletResponse response) { try {/* w w w. ja v a2 s. c o m*/ httpServletRequest.getSession(true).invalidate(); response.setStatus(HttpServletResponse.SC_NO_CONTENT); } 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.github.woonsan.katharsis.invoker.KatharsisInvoker.java
private void dispatchRequest(KatharsisInvokerContext invokerContext) throws Exception { BaseResponse<?> katharsisResponse = null; boolean passToMethodMatcher = false; InputStream in = null;// w w w .ja v a 2 s .c o m try { JsonPath jsonPath = new PathBuilder(resourceRegistry).buildPath(invokerContext.getRequestPath()); RequestParams requestParams = createRequestParams(invokerContext); in = invokerContext.getRequestEntityStream(); RequestBody requestBody = inputStreamToBody(in); String method = invokerContext.getRequestMethod(); katharsisResponse = requestDispatcher.dispatchRequest(jsonPath, method, requestParams, requestBody); } catch (KatharsisMappableException e) { if (log.isDebugEnabled()) { log.warn("Error occurred while dispatching katharsis request. " + e, e); } else { log.warn("Error occurred while dispatching katharsis request. " + e); } katharsisResponse = new KatharsisExceptionMapper().toErrorResponse(e); } catch (KatharsisMatchingException e) { passToMethodMatcher = true; } finally { closeQuietly(in); if (katharsisResponse != null) { invokerContext.setResponseStatus(katharsisResponse.getHttpStatus()); invokerContext.setResponseContentType(JsonApiMediaType.APPLICATION_JSON_API); ByteArrayOutputStream baos = null; OutputStream out = null; try { // first write to a buffer first because objectMapper may fail while writing. baos = new ByteArrayOutputStream(BUFFER_SIZE); objectMapper.writeValue(baos, katharsisResponse); out = invokerContext.getResponseOutputStream(); out.write(baos.toByteArray()); out.flush(); } finally { closeQuietly(baos); closeQuietly(out); } } else { invokerContext.setResponseStatus(HttpServletResponse.SC_NO_CONTENT); } } }
From source file:org.opencastproject.episode.endpoint.EpisodeRestService.java
@POST @Path("add") @RestQuery(name = "add", description = "Adds a mediapackage to the episode service.", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, type = RestParameter.Type.TEXT, defaultValue = "${this.sampleMediaPackage}", description = "The media package to add to the search index.") }, reponses = { @RestResponse(description = "The mediapackage was added, no content to return.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "There has been an internal error and the mediapackage could not be added", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "No content is returned.") public Response add(@FormParam("mediapackage") MediaPackageImpl mediaPackage) throws EpisodeServiceException { try {//w w w . ja v a2s .com episodeService.add(mediaPackage); return Response.noContent().build(); } catch (Exception e) { throw new WebApplicationException(e, Response.Status.BAD_REQUEST); } }