List of usage examples for java.net HttpURLConnection HTTP_NOT_FOUND
int HTTP_NOT_FOUND
To view the source code for java.net HttpURLConnection HTTP_NOT_FOUND.
Click Source Link
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the create method.//from ww w . jav a 2 s . co m * * @throws GenieException For any problem */ @Test public void testCreateApplication() throws GenieException { final String id = UUID.randomUUID().toString(); final Application app = new Application.Builder(APP_1_NAME, APP_1_USER, APP_1_VERSION, ApplicationStatus.ACTIVE).withId(id).build(); final String createdId = this.appService.createApplication(app); Assert.assertThat(createdId, Matchers.is(id)); final Application created = this.appService.getApplication(id); Assert.assertNotNull(created); Assert.assertEquals(id, created.getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_NAME, created.getName()); Assert.assertEquals(APP_1_USER, created.getUser()); Assert.assertEquals(ApplicationStatus.ACTIVE, created.getStatus()); this.appService.deleteApplication(id); try { this.appService.getApplication(id); Assert.fail("Should have thrown exception"); } catch (final GenieException ge) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ge.getErrorCode()); } }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Delete the all tags from a given job. * * @param id The id of the job to delete the tags from. * Not null/empty/blank./*w ww. j a v a2 s . co m*/ * @return Empty set if successful * @throws GenieException For any error */ @DELETE @Path("/{id}/tags") @ApiOperation(value = "Remove all tags from a job", notes = "Remove all the tags from the job with given id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job for id does not exist."), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid id supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> removeAllTagsForJob( @ApiParam(value = "Id of the job to delete from.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.jobService.removeAllTagsForJob(id); }
From source file:com.cloudant.client.org.lightcouch.CouchDbClient.java
/** * Execute a HTTP request and handle common error cases. * * @param connection the HttpConnection request to execute * @return the executed HttpConnection/* w ww . ja va 2 s .c o m*/ * @throws CouchDbException for HTTP error codes or if an IOException was thrown */ public HttpConnection execute(HttpConnection connection) { //set our HttpUrlFactory on the connection connection.connectionFactory = factory; // all CouchClient requests want to receive application/json responses connection.requestProperties.put("Accept", "application/json"); connection.responseInterceptors.addAll(this.responseInterceptors); connection.requestInterceptors.addAll(this.requestInterceptors); InputStream es = null; // error stream - response from server for a 500 etc // first try to execute our request and get the input stream with the server's response // we want to catch IOException because HttpUrlConnection throws these for non-success // responses (eg 404 throws a FileNotFoundException) but we need to map to our own // specific exceptions try { try { connection = connection.execute(); } catch (HttpConnectionInterceptorException e) { CouchDbException exception = new CouchDbException(connection.getConnection().getResponseMessage(), connection.getConnection().getResponseCode()); exception.error = e.error; exception.reason = e.reason; throw exception; } int code = connection.getConnection().getResponseCode(); String response = connection.getConnection().getResponseMessage(); // everything ok? return the stream if (code / 100 == 2) { // success [200,299] return connection; } else { final CouchDbException ex; switch (code) { case HttpURLConnection.HTTP_NOT_FOUND: //404 ex = new NoDocumentException(response); break; case HttpURLConnection.HTTP_CONFLICT: //409 ex = new DocumentConflictException(response); break; case HttpURLConnection.HTTP_PRECON_FAILED: //412 ex = new PreconditionFailedException(response); break; default: ex = new CouchDbException(response, code); break; } es = connection.getConnection().getErrorStream(); //if there is an error stream try to deserialize into the typed exception if (es != null) { //read the error stream into memory byte[] errorResponse = IOUtils.toByteArray(es); Class<? extends CouchDbException> exceptionClass = ex.getClass(); //treat the error as JSON and try to deserialize try { //Register an InstanceCreator that returns the existing exception so we can //just populate the fields, but not ignore the constructor. //Uses a new Gson so we don't accidentally recycle an exception. Gson g = new GsonBuilder() .registerTypeAdapter(exceptionClass, new InstanceCreator<CouchDbException>() { @Override public CouchDbException createInstance(Type type) { return ex; } }).create(); //now populate the exception with the error/reason other info from JSON g.fromJson(new InputStreamReader(new ByteArrayInputStream(errorResponse), "UTF-8"), exceptionClass); } catch (JsonParseException e) { //the error stream was not JSON so just set the string content as the error // field on ex before we throw it ex.error = new String(errorResponse, "UTF-8"); } } throw ex; } } catch (IOException ioe) { throw new CouchDbException("Error retrieving server response", ioe); } finally { close(es); } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Add new tags to a given command./*w w w. j a v a2 s . c om*/ * * @param id The id of the command to add the tags to. Not * null/empty/blank. * @param tags The tags to add. Not null/empty/blank. * @return The active tags for this command. * @throws GenieException For any error */ @POST @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new tags to a command", notes = "Add the supplied tags to the command with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> addTagsForCommand( @ApiParam(value = "Id of the command to add configuration to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to add.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.commandConfigService.addTagsForCommand(id, tags); }
From source file:org.eclipse.hono.deviceregistry.FileBasedCredentialsService.java
@Override public void update(final String tenantId, final JsonObject newCredentials, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(newCredentials); Objects.requireNonNull(resultHandler); if (getConfig().isModificationEnabled()) { final String authId = newCredentials.getString(CredentialsConstants.FIELD_AUTH_ID); final String type = newCredentials.getString(CredentialsConstants.FIELD_TYPE); log.debug("updating credentials for device [tenant-id: {}, auth-id: {}, type: {}]", tenantId, authId, type);//from w ww . ja v a2s .co m final Map<String, JsonArray> credentialsForTenant = getCredentialsForTenant(tenantId); if (credentialsForTenant == null) { resultHandler .handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { final JsonArray credentialsForAuthId = credentialsForTenant.get(authId); if (credentialsForAuthId == null) { resultHandler.handle( Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { // find credentials of given type boolean removed = false; final Iterator<Object> credentialsIterator = credentialsForAuthId.iterator(); while (credentialsIterator.hasNext()) { final JsonObject creds = (JsonObject) credentialsIterator.next(); if (creds.getString(CredentialsConstants.FIELD_TYPE).equals(type)) { credentialsIterator.remove(); removed = true; break; } } if (removed) { credentialsForAuthId.add(newCredentials); dirty = true; resultHandler.handle( Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NO_CONTENT))); } else { resultHandler.handle( Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } } } } else { resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_FORBIDDEN))); } }
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImplIntegrationTests.java
/** * Test the create method when no id is entered. * * @throws GenieException For any problem */// w w w . ja v a 2 s. c om @Test public void testCreateClusterNoId() throws GenieException { final Set<String> configs = Sets.newHashSet("a config", "another config", "yet another config"); final Set<String> dependencies = Sets.newHashSet("a dependency"); final Cluster cluster = new Cluster.Builder(CLUSTER_1_NAME, CLUSTER_1_USER, CLUSTER_1_VERSION, ClusterStatus.OUT_OF_SERVICE).withConfigs(configs).withDependencies(dependencies).build(); final String id = this.service.createCluster(cluster); final Cluster created = this.service.getCluster(id); Assert.assertEquals(CLUSTER_1_NAME, created.getName()); Assert.assertEquals(CLUSTER_1_USER, created.getUser()); Assert.assertEquals(ClusterStatus.OUT_OF_SERVICE, created.getStatus()); Assert.assertEquals(3, created.getConfigs().size()); Assert.assertEquals(1, created.getDependencies().size()); this.service.deleteCluster(created.getId().orElseThrow(IllegalArgumentException::new)); try { this.service.getCluster(created.getId().orElseThrow(IllegalArgumentException::new)); Assert.fail("Should have thrown exception"); } catch (final GenieException ge) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ge.getErrorCode()); } }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the create method when no id is entered. * * @throws GenieException For any problem *//*from ww w. jav a2s . com*/ @Test public void testCreateApplicationNoId() throws GenieException { final Application app = new Application.Builder(APP_1_NAME, APP_1_USER, APP_1_VERSION, ApplicationStatus.ACTIVE).build(); final String id = this.appService.createApplication(app); final Application created = this.appService.getApplication(id); Assert.assertNotNull(created); Assert.assertEquals(APP_1_NAME, created.getName()); Assert.assertEquals(APP_1_USER, created.getUser()); Assert.assertEquals(ApplicationStatus.ACTIVE, created.getStatus()); this.appService.deleteApplication(created.getId().orElseThrow(IllegalArgumentException::new)); try { this.appService.getApplication(created.getId().orElseThrow(IllegalArgumentException::new)); Assert.fail(); } catch (final GenieException ge) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ge.getErrorCode()); } }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Add new jar files for a given application. * * @param id The id of the application to add the jar file to. Not * null/empty/blank./* w ww. ja v a 2 s . c o m*/ * @param jars The jar files to add. Not null. * @return The active set of application jars. * @throws GenieException For any error */ @POST @Path("/{id}/jars") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new jar files to an application", notes = "Add the supplied jar files to the applicaiton with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> addJarsForApplication( @ApiParam(value = "Id of the application to add jar to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The jar files to add.", required = true) final Set<String> jars) throws GenieException { LOG.info("Called with id " + id + " and jars " + jars); return this.applicationConfigService.addJarsForApplication(id, jars); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get all the commands configured for a given cluster. * * @param id The id of the cluster to get the command files for. Not * NULL/empty/blank./*from w ww . j a va 2 s . com*/ * @param statuses The various statuses to return commands for. * @return The active set of commands for the cluster. * @throws GenieException For any error */ @GET @Path("/{id}/commands") @ApiOperation(value = "Get the commands for a cluster", notes = "Get the commands for the cluster with the supplied id.", response = Command.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Command> getCommandsForCluster( @ApiParam(value = "Id of the cluster to get commands for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses) throws GenieException { LOG.info("Called with id " + id + " status " + statuses); Set<CommandStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(CommandStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(CommandStatus.parse(status)); } } } return this.clusterConfigService.getCommandsForCluster(id, enumStatuses); }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Remove an tag from a given job.//from www .j a va2s. co m * * @param id The id of the job to delete the tag from. Not * null/empty/blank. * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the job. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a job", notes = "Remove the given tag from the job with given id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job for id does not exist."), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid id supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> removeTagForJob( @ApiParam(value = "Id of the job to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.jobService.removeTagForJob(id, tag); }