List of usage examples for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT
int SC_NO_CONTENT
To view the source code for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.
Click Source Link
From source file:org.alfresco.dataprep.SitePagesService.java
/** * Remove an event/*from ww w . j a va 2 s .co m*/ * @param userName String user name * @param password String user password * @param siteName String site name * @param what String what * @param where String event location * @param from Date event start date * @param to Date event end date * @param timeStart String event start time * @param timeEnd String event time finish * @param allDay boolean all day event * @return boolean true if event is removed * @throws RuntimeException if site is not found */ public boolean removeEvent(final String userName, final String password, final String siteName, final String what, final String where, Date from, Date to, String timeStart, String timeEnd, final boolean allDay) { if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName) || StringUtils.isEmpty(what) || StringUtils.isEmpty(from.toString()) || StringUtils.isEmpty(to.toString())) { throw new IllegalArgumentException("Parameter missing"); } String eventName = getEventName(userName, password, siteName, what, where, from, to, timeStart, timeEnd, allDay); if (StringUtils.isEmpty(eventName)) { throw new RuntimeException("Event not found"); } AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); String reqURL = client.getAlfrescoUrl() + "alfresco/s/calendar/event/" + siteName + "/" + eventName; HttpDelete request = new HttpDelete(reqURL); HttpResponse response = client.executeRequest(userName, password, request); switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_NO_CONTENT: return true; case HttpStatus.SC_NOT_FOUND: throw new RuntimeException("Invalid site " + siteName); default: logger.error("Unable to delete event: " + response.toString()); break; } return false; }
From source file:org.alfresco.dataprep.SitePagesService.java
/** * Delete wiki page//from www.j a va2 s. c om * @param userName String user name * @param password String password * @param siteName String site name * @param wikiTitle String wiki title * @return true if wiki is removed (204 Status) */ public boolean deleteWikiPage(final String userName, final String password, final String siteName, String wikiTitle) { if (wikiTitle.contains(" ")) { wikiTitle = wikiTitle.replaceAll(" ", "_"); } AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); String url = client.getAlfrescoUrl() + "alfresco/s/slingshot/wiki/page/" + siteName + "/" + wikiTitle; HttpDelete delete = new HttpDelete(url); HttpResponse response = client.executeRequest(userName, password, delete); switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_NO_CONTENT: return true; case HttpStatus.SC_NOT_FOUND: throw new RuntimeException("Wiki " + wikiTitle + " or site " + siteName + " doesn't exists"); default: logger.error("Unable to delete wiki page: " + response.toString()); break; } return false; }
From source file:org.alfresco.repo.web.scripts.solr.NodeContentGet.java
/** * * @param req WebScriptRequest/*from ww w. j av a 2 s. c o m*/ * @param res WebScriptResponse * @throws IOException */ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { ContentReader textReader = null; Exception transformException = null; String nodeIDString = req.getParameter("nodeId"); if (nodeIDString == null) { throw new WebScriptException("nodeID parameter is required for GetNodeContent"); } long nodeId = Long.valueOf(nodeIDString).longValue(); String propertyQName = req.getParameter("propertyQName"); QName propertyName = null; if (propertyQName == null) { propertyName = ContentModel.PROP_CONTENT; } else { propertyName = QName.createQName(propertyQName); } Pair<Long, NodeRef> pair = nodeDAO.getNodePair(nodeId); if (pair == null) { // If the node does not exists we treat it as if it has no content // We could be trying to update the content of a node in the index that has been deleted. res.setStatus(HttpStatus.SC_NO_CONTENT); return; } NodeRef nodeRef = pair.getSecond(); // check If-Modified-Since header and set Last-Modified header as appropriate Date modified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED); // May be null - if so treat as just changed if (modified == null) { modified = new Date(); } long modifiedSince = -1; String modifiedSinceStr = req.getHeader("If-Modified-Since"); if (modifiedSinceStr != null) { try { modifiedSince = dateFormat.parse(modifiedSinceStr).getTime(); } catch (Throwable e) { if (logger.isWarnEnabled()) { logger.warn("Browser sent badly-formatted If-Modified-Since header: " + modifiedSinceStr); } } if (modifiedSince > 0L) { // round the date to the ignore millisecond value which is not supplied by header long modDate = (modified.getTime() / 1000L) * 1000L; if (modDate <= modifiedSince) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } } ContentReader reader = contentService.getReader(nodeRef, propertyName); if (reader == null) { res.setStatus(HttpStatus.SC_NO_CONTENT); return; } try { // get the transformer TransformationOptions options = new TransformationOptions(); options.setUse("index"); options.setSourceNodeRef(nodeRef); transformerDebug.pushAvailable(reader.getContentUrl(), reader.getMimetype(), MimetypeMap.MIMETYPE_TEXT_PLAIN, options); long sourceSize = reader.getSize(); List<ContentTransformer> transformers = contentService.getActiveTransformers(reader.getMimetype(), sourceSize, MimetypeMap.MIMETYPE_TEXT_PLAIN, options); transformerDebug.availableTransformers(transformers, sourceSize, options, "SolrIndexer"); if (transformers.isEmpty()) { res.setHeader(TRANSFORM_STATUS_HEADER, "noTransform"); res.setStatus(HttpStatus.SC_NO_CONTENT); return; } ContentTransformer transformer = transformers.get(0); // Perform transformation catering for mimetype AND encoding ContentWriter writer = contentService.getTempWriter(); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); // Expect transformers to produce UTF-8 try { long start = System.currentTimeMillis(); transformer.transform(reader, writer, options); long transformDuration = System.currentTimeMillis() - start; res.setHeader(TRANSFORM_DURATION_HEADER, String.valueOf(transformDuration)); } catch (ContentIOException | UnsupportedTransformationException e) { transformException = e; } if (transformException == null) { // point the reader to the new-written content textReader = writer.getReader(); // Check that the reader is a view onto something concrete if (textReader == null || !textReader.exists()) { transformException = new ContentIOException( "The transformation did not write any content, yet: \n" + " transformer: " + transformer + "\n" + " temp writer: " + writer); } } if (transformException != null) { res.setHeader(TRANSFORM_STATUS_HEADER, "transformFailed"); res.setHeader(TRANSFORM_EXCEPTION_HEADER, transformException.getMessage()); res.setStatus(HttpStatus.SC_NO_CONTENT); } else { res.setStatus(HttpStatus.SC_OK); streamContentImpl(req, res, textReader, null, null, false, modified, String.valueOf(modified.getTime()), null, null); } } finally { transformerDebug.popAvailable(); } }
From source file:org.alfresco.services.solr.GetTextContentResponse.java
private void setStatus() { int status = response.getStatus(); if (status == HttpStatus.SC_NOT_MODIFIED) { this.status = SolrApiContentStatus.NOT_MODIFIED; } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { this.status = SolrApiContentStatus.GENERAL_FAILURE; } else if (status == HttpStatus.SC_OK) { this.status = SolrApiContentStatus.OK; } else if (status == HttpStatus.SC_NO_CONTENT) { if (transformStatusStr == null) { this.status = SolrApiContentStatus.UNKNOWN; } else {/*from www . ja v a2 s. c om*/ if (transformStatusStr.equals("noTransform")) { this.status = SolrApiContentStatus.NO_TRANSFORM; } else if (transformStatusStr.equals("transformFailed")) { this.status = SolrApiContentStatus.TRANSFORM_FAILED; } else { this.status = SolrApiContentStatus.UNKNOWN; } } } }
From source file:org.apache.cloudstack.network.element.SspClient.java
public boolean deleteTenantNetwork(String tenantNetworkUuid) { DeleteMethod method = deleteMethod;/*from w w w . j a v a 2 s.c o m*/ method.setPath("/ssp.v1/tenant-networks/" + tenantNetworkUuid); executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) { return true; } return false; }
From source file:org.apache.cloudstack.network.element.SspClient.java
public boolean deleteTenantPort(String tenantPortUuid) { DeleteMethod method = deleteMethod;/*from w ww.j av a 2 s.c o m*/ method.setPath("/ssp.v1/tenant-ports/" + tenantPortUuid); executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) { return true; } return false; }
From source file:org.apache.cloudstack.network.element.SspClientTest.java
@Test public void deleteNetworkTest() throws Exception { String tenant_net_uuid = UUID.randomUUID().toString(); when(_deleteMethod.getURI()).thenReturn(getUri()); when(_deleteMethod.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); sspClient.deleteTenantNetwork(tenant_net_uuid); }
From source file:org.apache.cloudstack.network.opendaylight.api.resources.Action.java
protected void executeDelete(final String uri) throws NeutronRestApiException { try {//from ww w .j a v a 2 s . co m validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(DeleteMethod.class); DeleteMethod deleteMethod = (DeleteMethod) neutronRestApi.createMethod(url, uri); try { deleteMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); String encodedCredentials = encodeCredentials(); deleteMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(deleteMethod); if (deleteMethod.getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage = responseToErrorMessage(deleteMethod); deleteMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to create object : " + errorMessage); } } catch (NeutronRestApiException e) { s_logger.error( "NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { deleteMethod.releaseConnection(); } }
From source file:org.apache.excalibur.source.factories.HTTPClientSource.java
/** * According to RFC2616 (HTTP 1.1) valid responses for a HTTP DELETE * are 200 (OK), 202 (Accepted) and 204 (No Content). * * @param response response code from the HTTP PUT * @return true if upload was successful, false otherwise. *//* w w w. ja va 2 s .c o m*/ private boolean deleteSuccessful(final int response) { return response == HttpStatus.SC_OK || response == HttpStatus.SC_ACCEPTED || response == HttpStatus.SC_NO_CONTENT; }
From source file:org.apache.hadoop.fs.swift.snative.SwiftNativeFileSystemStore.java
/** * List a directory./*from w w w.j av a2 s .c om*/ * This is O(n) for the number of objects in this path. * * @param path path to list * @param nameOnly should the status be minimal (name) or should * the (expensive) operation be made to ask for it. * @return the filestats of all the entities in the directory -or * an empty list if no objects were found listed under that prefix * @throws IOException IO problems */ private List<FileStatus> listDirectory(SwiftObjectPath path, boolean recursive, boolean nameOnly) throws IOException { final byte[] bytes; final ArrayList<FileStatus> files = new ArrayList<FileStatus>(); try { if (recursive) { bytes = swiftRestClient.findObjectsByPrefix(path, null); } else { bytes = swiftRestClient.listObjectsInDirectory(path); } } catch (FileNotFoundException e) { if (LOG.isDebugEnabled()) { LOG.debug("" + "File/Directory not found " + path); } if (SwiftUtils.isRootDir(path)) { return Collections.emptyList(); } else { throw e; } } catch (SwiftInvalidResponseException e) { //bad HTTP error code if (e.getStatusCode() == HttpStatus.SC_NO_CONTENT) { //this can come back on a root list if the container is empty if (SwiftUtils.isRootDir(path)) { return Collections.emptyList(); } else { //NO_CONTENT returned on something other than the root directory; //see if it is there, and convert to empty list or not found //depending on whether the entry exists. FileStatus stat = getObjectMetadata(getCorrectSwiftPath(path)); if (SwiftUtils.isDirectory(stat)) { //it's an empty directory. state that return Collections.emptyList(); } else { //it's a file -return that as the status files.add(stat); return files; } } } else { //a different status code: rethrow immediately throw e; } } //the byte array contains the files separated by newlines final StringTokenizer tokenizer = new StringTokenizer(new String(bytes), "\n"); Map<String, Boolean> names = new HashMap<String, Boolean>(); //insert own name as one to skip names.put(path.getObject(), true); while (tokenizer.hasMoreTokens()) { String pathInSwift = tokenizer.nextToken(); if (LOG.isDebugEnabled()) { LOG.debug("entry: " + pathInSwift); } if (!pathInSwift.startsWith("/")) { pathInSwift = "/".concat(pathInSwift); } Path childPath = new Path(pathInSwift); if (!names.containsKey(pathInSwift)) { names.put(pathInSwift, true); names.put(pathInSwift + "/", true); //For each entry, get the metadata. try { FileStatus metadata; if (nameOnly) { metadata = new SwiftFileStatus(0, false, 0, 0, 0, childPath); } else { metadata = getObjectMetadata(childPath); } files.add(metadata); } catch (FileNotFoundException e) { //get Object metadata failed LOG.info("Object " + childPath + " was deleted during directory listing"); } } else { //hash map LOG.debug("skipping adding self to path"); } } return files; }