List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.
Click Source Link
From source file:davmail.caldav.CaldavConnection.java
/** * Send Http error response for exception * * @param e exception// w w w . jav a2s . c om * @throws IOException on error */ public void sendErr(Exception e) throws IOException { String message = e.getMessage(); if (message == null) { message = e.toString(); } if (e instanceof HttpNotFoundException) { sendErr(HttpStatus.SC_NOT_FOUND, message); } else if (e instanceof HttpPreconditionFailedException) { sendErr(HttpStatus.SC_PRECONDITION_FAILED, message); } else { sendErr(HttpStatus.SC_SERVICE_UNAVAILABLE, message); } }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
/** * Verifies that a 404 status code is returned when the operation returns null. * Note that the response body is not empty: it contains the HTML error that is usually * displayed in the browser/*from w w w . j a v a 2 s . co m*/ */ @Test public void testGetOperationNull1() throws Exception { String url = URL_RESOURCE1 + "/pathGetOperationNull1"; GetMethod method = new GetMethod(url); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NOT_FOUND); byte[] responseBody = method.getResponseBody(); assertNotNull(responseBody); String htmlResponse = new String(responseBody); assertNotNull(htmlResponse); }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
/** * Verifies that a 404 status code is returned when the operation returns null. * Note that the response body is not empty: it contains the HTML error that is usually * displayed in the browser//from w ww . jav a 2 s .c om */ @Test public void testGetOperationNull2() throws Exception { String url = URL_RESOURCE1 + "/pathGetOperationNull2"; GetMethod method = new GetMethod(url); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NOT_FOUND); byte[] responseBody = method.getResponseBody(); assertNotNull(responseBody); String htmlResponse = new String(responseBody); assertNotNull(htmlResponse); }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
/** * Verifies that a 404 status code is returned when the operation returns null. * Note that the response body is not empty: it contains the HTML error that is usually * displayed in the browser//from ww w. j a v a2s. c o m */ @Test public void testGetOperationNull3() throws Exception { String url = URL_RESOURCE1 + "/pathGetOperationNull3"; GetMethod method = new GetMethod(url); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NOT_FOUND); byte[] responseBody = method.getResponseBody(); assertNotNull(responseBody); String htmlResponse = new String(responseBody); assertNotNull(htmlResponse); }
From source file:davmail.exchange.dav.DavExchangeSession.java
@Override public void deleteItem(String folderPath, String itemName) throws IOException { String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName)); int status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); if (status == HttpStatus.SC_NOT_FOUND && isMainCalendar(folderPath)) { // retry in tasks folder eventPath = URIUtil.encodePath(getFolderPath(TASKS) + '/' + convertItemNameToEML(itemName)); status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); }// w w w . j a va2 s .co m if (status == HttpStatus.SC_NOT_FOUND) { LOGGER.debug("Unable to delete " + itemName + ": item not found"); } }
From source file:davmail.exchange.dav.DavExchangeSession.java
@Override protected void moveToTrash(ExchangeSession.Message message) throws IOException { String destination = URIUtil.encodePath(deleteditemsUrl) + '/' + UUID.randomUUID().toString(); LOGGER.debug("Deleting : " + message.permanentUrl + " to " + destination); MoveMethod method = new MoveMethod(encodeAndFixUrl(message.permanentUrl), destination, false); method.addRequestHeader("Allow-rename", "t"); int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method); // do not throw error if already deleted if (status != HttpStatus.SC_CREATED && status != HttpStatus.SC_NOT_FOUND) { throw DavGatewayHttpClientFacade.buildHttpException(method); }/* www. ja v a 2s . co m*/ if (method.getResponseHeader("Location") != null) { destination = method.getResponseHeader("Location").getValue(); } LOGGER.debug("Deleted to :" + destination); }
From source file:net.xmind.share.jobs.UploadJob.java
private IStatus promptError(int uploadStatus, IStatus error) { int code = error.getCode(); String message = null;//from w w w . j ava 2 s . c o m boolean tryAgainAllowed = true; if (uploadStatus == UploadSession.PREPARING) { if (code > 0) { if (code == HttpStatus.SC_UNAUTHORIZED) { resignin(); return Status.CANCEL_STATUS; } } } else if (uploadStatus == UploadSession.UPLOADING) { if (code > 0) { if (code == HttpStatus.SC_NOT_FOUND) { return Status.CANCEL_STATUS; } else if (code == UploadSession.CODE_VERIFICATION_FAILURE) { message = Messages.ErrorDialog_Unauthorized_message; tryAgainAllowed = false; } } } if (message == null) message = Messages.ErrorDialog_message; promptErrorMessage(message, tryAgainAllowed); return error; }
From source file:opendap.bes.dap4Responders.FileAccess.java
public void sendNormativeRepresentation(HttpServletRequest req, HttpServletResponse response) throws Exception { String requestedResourceId = ReqInfo.getLocalUrl(req); String resourceID = getResourceId(requestedResourceId, false); BesApi besApi = getBesApi();// ww w . j ava2 s . com ResourceInfo dsi = new BESResource(resourceID, besApi); if (dsi.sourceExists()) { if (!dsi.isNode()) { if (dsi.sourceIsAccesible()) { if (dsi.isDataset()) { if (allowDirectDataSourceAccess()) { sendDatasetFile(resourceID, response); } else { log.warn("respondToHttpGetRequest() - Sending Access Denied for resource: " + Scrub.completeURL(resourceID)); sendDirectAccessDenied(req, response); } } else { String errMsg = "Unable to locate BES resource: " + Scrub.completeURL(resourceID); log.info("respondToHttpGetRequest() - {}", errMsg); sendHttpErrorResponse(HttpStatus.SC_NOT_FOUND, errMsg, "docs", response); } } else { String errMsg = "BES data source {} is not accessible." + Scrub.completeURL(resourceID); log.info("respondToHttpGetRequest() - {}", errMsg); sendHttpErrorResponse(HttpStatus.SC_NOT_FOUND, errMsg, "docs", response); } } else { String errMsg = "You may not downloadJobOutput nodes/directories, only files." + Scrub.completeURL(resourceID); log.info("respondToHttpGetRequest() - {}", errMsg); sendHttpErrorResponse(HttpStatus.SC_FORBIDDEN, errMsg, "docs", response); } } else { String errMsg = "Unable to locate BES resource: " + Scrub.completeURL(resourceID); log.info("matches() - {}", errMsg); sendHttpErrorResponse(HttpStatus.SC_NOT_FOUND, errMsg, "docs", response); } }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsHttpClientRemotePeer.java
public Item retrieveItem(String path, boolean propsOnly) throws ItemNotFoundException, StorageException { // TODO: propsOnly is ignored, use HTTP HEAD? String originatingUrlString = getAbsoluteUrl(path); GetMethod get = new GetMethod(originatingUrlString); try {/*from w w w .j a v a2s .com*/ try { logger.info("Fetching item [{}] from remote location {}", path, originatingUrlString); int response = executeMethod(get); if (response == HttpStatus.SC_OK) { // ProxiedItemProperties properties = // constructItemPropertiesFromGetResponse(path, // originatingUrlString, get); Item result = new Item(); ItemProperties ip = null; // is it a file? // TODO: fix for #93 ticket? // Asking GET methods getPath() after execution will // result // in ACTUAL // path after eventual redirection. So, it will end with // "/" // if it is a dir. if (!get.getPath().endsWith(ItemProperties.PATH_SEPARATOR)) { // if (get.getResponseHeader("last-modified") != null) { File tmpFile = File.createTempFile(FilenameUtils.getName(path), null); tmpFile.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tmpFile); try { InputStream is = get.getResponseBodyAsStream(); if (get.getResponseHeader("Content-Encoding") != null && "gzip".equals(get.getResponseHeader("Content-Encoding").getValue())) { is = new GZIPInputStream(is); } IOUtils.copy(is, fos); fos.flush(); } finally { fos.close(); } tmpFile.setLastModified(makeDateFromHeader(get.getResponseHeader("last-modified"))); ip = getProxiedItemPropertiesFactory().expandItemProperties(path, tmpFile, true); result.setStream(new DeleteOnCloseFileInputStream(tmpFile)); } else { // TODO: dirty hack, I am creating a dir named after the // directory retrieval just to get item properties!!! // Fix this! File tmpdir = new File(System.getProperty("java.io.tmpdir"), FilenameUtils.getName(path)); tmpdir.mkdir(); ip = getProxiedItemPropertiesFactory().expandItemProperties(path, tmpdir, true); tmpdir.delete(); result.setStream(null); } result.setProperties(ip); result.getProperties().setRemoteUrl(originatingUrlString); return result; } else { if (response == HttpStatus.SC_NOT_FOUND) { throw new ItemNotFoundException(path); } else { throw new StorageException("The method execution returned result code " + response); } } } catch (MalformedURLException ex) { throw new StorageException("The path " + path + " is malformed!", ex); } catch (IOException ex) { throw new StorageException("IO Error during response stream handling!", ex); } } finally { get.releaseConnection(); } }
From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoaders.java
/** * Helper method that makes sure the site exists on the server and loads it in the benchmark DB * * @param eventOutputMsg//from w w w . j a va 2s . c o m * @return the collaboration site's document library id * @throws Exception */ private String getCollaborationSiteDoclib(StringBuilder eventOutputMsg) throws Exception { // Check if the collaboration site exists on server using the REST api RestSiteModel colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).getSite(); if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) { // The collaboration site doesn't exist, create it colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).createSite(); } // Store the collaboration site in benchmark's DB SiteData colabSiteData = siteDataService.getSite(collabSiteId); if (colabSiteData == null) { // Store site info in Benchmark's DB colabSiteData = new SiteData(); colabSiteData.setSiteId(collabSiteId); colabSiteData.setTitle(colabSite.getTitle()); colabSiteData.setGuid(colabSite.getGuid()); colabSiteData.setDescription(colabSite.getDescription()); colabSiteData.setSitePreset(colabSite.getPreset()); colabSiteData.setVisibility(colabSite.getVisibility().toString()); colabSiteData.setCreationState(Created); siteDataService.addSite(colabSiteData); eventOutputMsg.append(" Added site \"" + collabSiteId + "\" as created.\n"); } // Get site's document library RestSiteContainerModel documentLibrary = restCoreAPI.withCoreAPI().usingSite(collabSiteId) .getSiteContainer("documentLibrary"); return documentLibrary.getId(); }