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:org.nuxeo.ecm.core.storage.sql.net.TestNetServer.java
@Test public void test() throws Exception { assertNull(NetServer.instance);/*from ww w. ja v a 2s .c om*/ ServerDescriptor descr = new ServerDescriptor(); descr.host = "127.0.0.1"; descr.port = TEST_PORT; descr.path = TEST_CTX; NetServer.add(descr, "aa", new DummyServlet("aa"), TEST_PATH + "aa"); checkServlet(descr, "aa", "1", HttpStatus.SC_OK); // add another servlet NetServer.add(descr, "bb", new DummyServlet("bb"), TEST_PATH + "bb"); checkServlet(descr, "bb", "2", HttpStatus.SC_OK); // remove first servlet NetServer.remove(descr, "aa"); checkServlet(descr, "aa", "3", HttpStatus.SC_NOT_FOUND); checkServlet(descr, "bb", "4", HttpStatus.SC_OK); // remove second servlet NetServer.remove(descr, "bb"); checkServlet(descr, "aa", "5", HttpStatus.SC_NOT_FOUND); checkServlet(descr, "bb", "6", HttpStatus.SC_NOT_FOUND); // shutdown occurred assertNull(NetServer.instance); }
From source file:org.nuxeo.ecm.core.storage.sql.net.TestNetServer.java
protected static void checkServlet(ServerDescriptor descr, String name, String val, int expectedStatus) throws IOException, HttpException { GetMethod m = new GetMethod(descr.getUrl() + TEST_PATH + name + "?q=" + val); try {/* w ww . ja v a 2 s. c o m*/ int status = httpClient.executeMethod(m); assertEquals(expectedStatus, status); if (status != HttpStatus.SC_OK) { return; } String res = m.getResponseBodyAsString(); assertEquals(name + " " + val, res); } catch (ConnectException e) { if (expectedStatus != HttpStatus.SC_NOT_FOUND) { throw e; } } finally { m.releaseConnection(); } }
From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java
/** * Verifies if a specific named bucket exists. * * @param objectID/*from www . j av a2 s . co m*/ */ public boolean objectExists(String objectID) { boolean objectExists = false; String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase; log.debug(url); HeadMethod headMethod = new HeadMethod(url); String contentMD5 = ""; String stringToSign = StringGenerator.getStringToSign(HTTPMethod.HEAD, contentMD5, DEFAULT_CONTENT_TYPE, this.bucketName, objectID, new Date()); try { headMethod.addRequestHeader("Authorization", StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret)); headMethod.addRequestHeader("x-amz-date", StringGenerator.getCurrentDateString()); headMethod.setPath("/" + objectID); HttpClient client = new HttpClient(); int returnCode = client.executeMethod(headMethod); log.debug(headMethod.getResponseBodyAsString()); // only for logging if (returnCode == HttpStatus.SC_OK) { objectExists = true; } else if (returnCode == HttpStatus.SC_NOT_FOUND) { objectExists = false; log.debug("Object " + objectID + " does not exist"); } else { String connectionMsg = "Scality connection problem. Object could not be verified"; log.debug(connectionMsg); throw new RuntimeException(connectionMsg); } headMethod.releaseConnection(); } catch (SignatureException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return objectExists; }
From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java
/** * Retrieves the content-length of the remote object * * @param objectID//from ww w . jav a 2 s . co m */ public long getContentLength(String objectID) { String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase; log.debug(url); HeadMethod headMethod = new HeadMethod(url); String contentMD5 = ""; String stringToSign = StringGenerator.getStringToSign(HTTPMethod.HEAD, contentMD5, DEFAULT_CONTENT_TYPE, this.bucketName, objectID, new Date()); long contentLength = 0; try { headMethod.addRequestHeader("Authorization", StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret)); headMethod.addRequestHeader("x-amz-date", StringGenerator.getCurrentDateString()); headMethod.setPath("/" + objectID); HttpClient client = new HttpClient(); int returnCode = client.executeMethod(headMethod); // specific header if (returnCode == HttpStatus.SC_OK) { Header contentLengthHeader = headMethod.getResponseHeader("Content-Length"); contentLength = Long.parseLong(contentLengthHeader.getValue()); } else if (returnCode == HttpStatus.SC_NOT_FOUND) { log.debug("Object " + objectID + " does not exist"); } else { String connectionMsg = "Scality connection problem. Object could not be verified"; log.debug(connectionMsg); throw new RuntimeException(connectionMsg); } headMethod.releaseConnection(); } catch (NumberFormatException e) { throw new RuntimeException(e); } catch (SignatureException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return contentLength; }
From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java
/** * Deletes an object using its digest string. * * @param objectID/*www . j a v a 2s .co m*/ */ protected void removeBinary(String objectID) { String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase; log.debug(url); DeleteMethod deleteMethod = new DeleteMethod(url); String contentMD5 = ""; // date to be provided to the cloud server Date currentDate = new Date(); String cloudDateString = StringGenerator.getCloudFormattedDateString(currentDate); String stringToSign = StringGenerator.getStringToSign(HTTPMethod.DELETE, contentMD5, DEFAULT_CONTENT_TYPE, this.bucketName, objectID, currentDate); try { deleteMethod.addRequestHeader("Authorization", StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret)); deleteMethod.addRequestHeader("x-amz-date", cloudDateString); deleteMethod.setPath("/" + objectID); HttpClient client = new HttpClient(); int returnCode = client.executeMethod(deleteMethod); log.debug(deleteMethod.getResponseBodyAsString()); // only for logging if (returnCode == HttpStatus.SC_NO_CONTENT) { log.info("Object " + objectID + " deleted"); } else if (returnCode == HttpStatus.SC_NOT_FOUND) { log.debug("Object " + objectID + " does not exist"); } else { String connectionMsg = "Scality connection problem. Object could not be verified"; log.debug(connectionMsg); throw new RuntimeException(connectionMsg); } deleteMethod.releaseConnection(); } catch (SignatureException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java
/** * Verifies if a specific named bucket exists. * * @param bucketName//from ww w .j av a 2 s .c o m */ public boolean bucketExists(String bucketName) { boolean bucketExists = false; String remoteFileName = "";// no file needed to check the bucket String url = PROTOCOL_PREFIX + bucketName + "." + this.hostBase; log.debug(url); GetMethod getMethod = new GetMethod(url); String contentMD5 = ""; String stringToSign = StringGenerator.getStringToSign(HTTPMethod.GET, contentMD5, DEFAULT_CONTENT_TYPE, bucketName, remoteFileName, new Date()); try { getMethod.addRequestHeader("Authorization", StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret)); getMethod.addRequestHeader("x-amz-date", StringGenerator.getCurrentDateString()); HttpClient client = new HttpClient(); int returnCode = client.executeMethod(getMethod); if (returnCode == HttpStatus.SC_OK) { bucketExists = true; } else if (returnCode == HttpStatus.SC_NOT_FOUND) { log.debug(getMethod.getResponseBodyAsString()); log.debug("Bucket " + bucketName + " does not exist"); } else { log.debug(getMethod.getResponseBodyAsString()); log.debug("Connection problem"); } getMethod.releaseConnection(); } catch (SignatureException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return bucketExists; }
From source file:org.nuxeo.ecm.tokenauth.servlet.TokenAuthenticationServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Don't provide token for anonymous user unless 'allowAnonymous' parameter is explicitly set to true in // the authentication plugin configuration Principal principal = req.getUserPrincipal(); if (principal instanceof NuxeoPrincipal && ((NuxeoPrincipal) principal).isAnonymous()) { PluggableAuthenticationService authenticationService = (PluggableAuthenticationService) Framework .getRuntime().getComponent(PluggableAuthenticationService.NAME); AuthenticationPluginDescriptor tokenAuthPluginDesc = authenticationService .getDescriptor(TOKEN_AUTH_PLUGIN_NAME); if (tokenAuthPluginDesc == null || !(Boolean .valueOf(tokenAuthPluginDesc.getParameters().get(TokenAuthenticator.ALLOW_ANONYMOUS_KEY)))) { log.debug("Anonymous user is not allowed to acquire an authentication token."); resp.sendError(HttpStatus.SC_UNAUTHORIZED); return; }//from w w w . j a v a 2 s .c om } // Get request parameters String applicationName = req.getParameter(APPLICATION_NAME_PARAM); String deviceId = req.getParameter(DEVICE_ID_PARAM); String deviceDescription = req.getParameter(DEVICE_DESCRIPTION_PARAM); String permission = req.getParameter(PERMISSION_PARAM); String revokeParam = req.getParameter(REVOKE_PARAM); boolean revoke = Boolean.valueOf(revokeParam); // If one of the required parameters is null or empty, send an // error with the 400 status if (!revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(permission))) { log.error( "The following request parameters are mandatory to acquire an authentication token: applicationName, deviceId, permission."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId))) { log.error( "The following request parameters are mandatory to revoke an authentication token: applicationName, deviceId."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } // Decode parameters applicationName = URIUtil.decode(applicationName); deviceId = URIUtil.decode(deviceId); if (!StringUtils.isEmpty(deviceDescription)) { deviceDescription = URIUtil.decode(deviceDescription); } if (!StringUtils.isEmpty(permission)) { permission = URIUtil.decode(permission); } // Get user name from request Principal if (principal == null) { resp.sendError(HttpStatus.SC_UNAUTHORIZED); return; } String userName = principal.getName(); // Write response String response = null; int statusCode; TokenAuthenticationService tokenAuthService = Framework.getLocalService(TokenAuthenticationService.class); try { // Token acquisition: acquire token and write it to the response // body if (!revoke) { response = tokenAuthService.acquireToken(userName, applicationName, deviceId, deviceDescription, permission); statusCode = 201; } // Token revocation else { String token = tokenAuthService.getToken(userName, applicationName, deviceId); if (token == null) { response = String.format( "No token found for userName %s, applicationName %s and deviceId %s; nothing to do.", userName, applicationName, deviceId); statusCode = 400; } else { tokenAuthService.revokeToken(token); response = String.format("Token revoked for userName %s, applicationName %s and deviceId %s.", userName, applicationName, deviceId); statusCode = 202; } } sendTextResponse(resp, response, statusCode); } catch (TokenAuthenticationException e) { // Should never happen as parameters have already been checked resp.sendError(HttpStatus.SC_NOT_FOUND); } }
From source file:org.nuxeo.ecm.webdav.WebDavClientTest.java
@Test public void testNotFoundVirtualRoot() throws Exception { DavMethod method = new PropFindMethod(TEST_URI + "/nosuchpath", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0);// w ww . j a v a 2 s . c o m int status = client.executeMethod(method); assertEquals(HttpStatus.SC_NOT_FOUND, status); }
From source file:org.nuxeo.ecm.webdav.WebDavClientTest.java
@Test public void testNotFoundRegularPath() throws Exception { DavMethod method = new PropFindMethod(ROOT_URI + "/nosuchpath", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0);//from w w w .j a v a 2 s. com int status = client.executeMethod(method); assertEquals(HttpStatus.SC_NOT_FOUND, status); }
From source file:org.nuxeo.ecm.webdav.WebDavClientTest.java
@Test public void testDeleteMissingFile() throws Exception { String name = "nosuchfile.txt"; HttpMethod method = new DeleteMethod(ROOT_URI + name); int status = client.executeMethod(method); assertEquals(HttpStatus.SC_NOT_FOUND, status); }