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.JpaCommandServiceImplIntegrationTests.java
/** * Test the create method when no id is entered. * * @throws GenieException For any problem *///from w w w . j a v a 2 s . c om @Test public void testCreateCommandNoId() throws GenieException { final int memory = 512; final Command command = new Command.Builder(COMMAND_1_NAME, COMMAND_1_USER, COMMAND_1_VERSION, CommandStatus.ACTIVE, COMMAND_1_EXECUTABLE, COMMAND_1_CHECK_DELAY).withMemory(memory).build(); final String id = this.service.createCommand(command); final Command created = this.service.getCommand(id); Assert.assertNotNull(this.service.getCommand(created.getId().orElseThrow(IllegalArgumentException::new))); Assert.assertEquals(COMMAND_1_NAME, created.getName()); Assert.assertEquals(COMMAND_1_USER, created.getUser()); Assert.assertEquals(CommandStatus.ACTIVE, created.getStatus()); Assert.assertEquals(COMMAND_1_EXECUTABLE, created.getExecutable()); Assert.assertThat(COMMAND_1_CHECK_DELAY, Matchers.is(created.getCheckDelay())); Assert.assertThat(created.getMemory().orElse(memory + 1), Matchers.is(memory)); this.service.deleteCommand(created.getId().orElseThrow(IllegalArgumentException::new)); try { this.service.getCommand(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.server.resources.CommandConfigResource.java
/** * Get all the tags for a given command. * * @param id The id of the command to get the tags for. Not * NULL/empty/blank./*from w w w. ja v a 2 s. co m*/ * @return The active set of tags. * @throws GenieException For any error */ @GET @Path("/{id}/tags") @ApiOperation(value = "Get the tags for a command", notes = "Get the tags for 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> getTagsForCommand( @ApiParam(value = "Id of the command to get tags for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.commandConfigService.getTagsForCommand(id); }
From source file:com.datos.vfs.provider.webdav.WebdavFileObject.java
/** * Execute a 'Workspace' operation.//from www . j a va 2s .c o m * * @param method The DavMethod to invoke. * @throws FileSystemException If an error occurs. */ private void execute(final DavMethod method) throws FileSystemException { try { final int status = fileSystem.getClient().executeMethod(method); if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { throw new FileNotFoundException(method.getURI()); } method.checkSuccess(); } catch (final FileSystemException fse) { throw fse; } catch (final IOException e) { throw new FileSystemException(e); } catch (final DavException e) { throw ExceptionConverter.generate(e); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:org.elasticsearch.metrics.ElasticsearchReporter.java
/** * This index template is automatically applied to all indices which start with the index name * The index template simply configures the name not to be analyzed *///www . java 2 s . co m private void checkForIndexTemplate() { try { HttpURLConnection connection = openConnection("/_template/metrics_template", "HEAD"); if (connection == null) { LOGGER.error("Could not connect to any configured elasticsearch instances: {}", Arrays.asList(hosts)); return; } connection.disconnect(); boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND; // nothing there, lets create it if (isTemplateMissing) { LOGGER.debug("No metrics template found in elasticsearch. Adding..."); HttpURLConnection putTemplateConnection = openConnection("/_template/metrics_template", "PUT"); if (putTemplateConnection == null) { LOGGER.error("Error adding metrics template to elasticsearch"); return; } JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream()); json.writeStartObject(); json.writeStringField("template", index + "*"); json.writeObjectFieldStart("mappings"); json.writeObjectFieldStart("_default_"); json.writeObjectFieldStart("_all"); json.writeBooleanField("enabled", false); json.writeEndObject(); json.writeObjectFieldStart("properties"); json.writeObjectFieldStart("name"); json.writeObjectField("type", "string"); json.writeObjectField("index", "not_analyzed"); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.flush(); putTemplateConnection.disconnect(); if (putTemplateConnection.getResponseCode() != 200) { LOGGER.error( "Error adding metrics template to elasticsearch: {}/{}" + putTemplateConnection.getResponseCode(), putTemplateConnection.getResponseMessage()); } } checkedForIndexTemplate = true; } catch (IOException e) { LOGGER.error("Error when checking/adding metrics template to elasticsearch", e); } }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get all the jar files for a given application. * * @param id The id of the application to get the jar files for. Not * NULL/empty/blank./*ww w .ja va2s. co m*/ * @return The set of jar files. * @throws GenieException For any error */ @GET @Path("/{id}/jars") @ApiOperation(value = "Get the jars for an application", notes = "Get the jars for the application 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> getJarsForApplication( @ApiParam(value = "Id of the application to get the jars for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.applicationConfigService.getJarsForApplication(id); }
From source file:org.apache.axis.transport.http.AxisServlet.java
/** * generate the error response to indicate that there is apparently no endpoint there * @param request the request that didnt have an edpoint * @param response response we are generating * @param writer open writer for the request *//*from w w w . j a v a 2 s . co m*/ protected void reportCantGetAxisService(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) { // no such service.... response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); response.setContentType("text/html; charset=utf-8"); writer.println("<h2>" + Messages.getMessage("error00") + "</h2>"); writer.println("<p>" + Messages.getMessage("noService06") + "</p>"); }
From source file:org.eclipse.hono.deviceregistry.FileBasedCredentialsService.java
@Override public void remove(final String tenantId, final String type, final String authId, final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(type); Objects.requireNonNull(authId); Objects.requireNonNull(resultHandler); if (getConfig().isModificationEnabled()) { final Map<String, JsonArray> credentialsForTenant = credentials.get(tenantId); if (credentialsForTenant == null) { resultHandler// w w w . j av a 2 s . c o m .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 if (removeCredentialsFromCredentialsArray(null, type, credentialsForAuthId)) { if (credentialsForAuthId.isEmpty()) { credentialsForTenant.remove(authId); // do not leave empty array as value } 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.oneops.metrics.es.ElasticsearchReporter.java
/** * This index template is automatically applied to all indices which start with the index name * The index template simply configures the name not to be analyzed *//*from w ww . j a v a 2s . c o m*/ private void checkForIndexTemplate() { try { HttpURLConnection connection = openConnection("/_template/metrics_template", "HEAD"); if (connection == null) { LOGGER.error("Could not connect to any configured elasticsearch instances: {}", Arrays.asList(hosts)); return; } connection.disconnect(); boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND; // nothing there, lets create it if (isTemplateMissing) { LOGGER.debug("No metrics template found in elasticsearch. Adding..."); HttpURLConnection putTemplateConnection = openConnection("/_template/metrics_template", "PUT"); JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream()); json.writeStartObject(); json.writeStringField("template", index + "*"); json.writeObjectFieldStart("mappings"); json.writeObjectFieldStart("_default_"); json.writeObjectFieldStart("_all"); json.writeBooleanField("enabled", false); json.writeEndObject(); json.writeObjectFieldStart("properties"); json.writeObjectFieldStart("name"); json.writeObjectField("type", "string"); json.writeObjectField("index", "not_analyzed"); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.writeEndObject(); json.flush(); putTemplateConnection.disconnect(); if (putTemplateConnection.getResponseCode() != 200) { LOGGER.error( "Error adding metrics template to elasticsearch: {}/{}" + putTemplateConnection.getResponseCode(), putTemplateConnection.getResponseMessage()); } } checkedForIndexTemplate = true; } catch (IOException e) { LOGGER.error("Error when checking/adding metrics template to elasticsearch", e); } }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Update the commands for a given cluster. * * @param id The id of the cluster to update the configuration files for. * Not null/empty/blank. * @param commands The commands to replace existing applications with. Not * null/empty/blank.// w w w . j a va2 s . c o m * @return The new set of commands for the cluster. * @throws GenieException For any error */ @PUT @Path("/{id}/commands") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update the commands for an cluster", notes = "Replace the existing commands for cluster with given 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> updateCommandsForCluster( @ApiParam(value = "Id of the cluster to update commands for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The commands to replace existing with. Should already be created", required = true) final List<Command> commands) throws GenieException { LOG.info("Called with id " + id + " and commands " + commands); return this.clusterConfigService.updateCommandsForCluster(id, commands); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Update the tags for a given command./*from ww w . ja va 2 s .c o m*/ * * @param id The id of the command to update the tags for. * Not null/empty/blank. * @param tags The tags to replace existing configuration * files with. Not null/empty/blank. * @return The new set of command tags. * @throws GenieException For any error */ @PUT @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update tags for a command", notes = "Replace the existing tags for command with given 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> updateTagsForCommand( @ApiParam(value = "Id of the command to update tags for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to replace existing with.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.commandConfigService.updateTagsForCommand(id, tags); }