List of usage examples for java.net HttpURLConnection HTTP_PRECON_FAILED
int HTTP_PRECON_FAILED
To view the source code for java.net HttpURLConnection HTTP_PRECON_FAILED.
Click Source Link
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Delete the all configuration files from a given command. * * @param id The id of the command to delete the configuration files from. * Not null/empty/blank.// w ww .j a va 2 s . c o m * @return Empty set if successful * @throws GenieException For any error */ @DELETE @Path("/{id}/configs") @ApiOperation(value = "Remove all configuration files from an command", notes = "Remove all the configuration files from the 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> removeAllConfigsForCommand( @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.commandConfigService.removeAllConfigsForCommand(id); }
From source file:org.eclipse.orion.server.tests.servlets.files.CoreFilesTest.java
@Test public void testCreateFileOverwrite() throws CoreException, IOException, SAXException, JSONException { String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath);/*from ww w.j ava 2 s. com*/ String fileName = "testfile.txt"; WebRequest request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //creating again at the same location should succeed but return OK rather than CREATED request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); //creating with no-overwrite should fail if it already exists request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName); request.setHeaderField("X-Create-Options", "no-overwrite"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode()); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Delete the all configuration files from a given application. * * @param id The id of the application to delete the configuration files * from. Not null/empty/blank. * @return Empty set if successful//from w ww . ja v a 2 s .co m * @throws GenieException For any error */ @DELETE @Path("/{id}/configs") @ApiOperation(value = "Remove all configuration files from an application", notes = "Remove all the configuration files from the application with given 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> removeAllConfigsForApplication( @ApiParam(value = "Id of the application to delete from.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.applicationConfigService.removeAllConfigsForApplication(id); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Add new commands to the given cluster. * * @param id The id of the cluster to add the commands to. Not * null/empty/blank./*from w w w . j av a2 s .com*/ * @param commands The commands to add. Not null. * @return The active commands for this cluster. * @throws GenieException For any error */ @POST @Path("/{id}/commands") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new commands to a cluster", notes = "Add the supplied commands to the cluster with the supplied id." + " commands should already have been created.", 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> addCommandsForCluster( @ApiParam(value = "Id of the cluster to add commands to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The commands to add.", required = true) final List<Command> commands) throws GenieException { LOG.info("Called with id " + id + " and commands " + commands); return this.clusterConfigService.addCommandsForCluster(id, commands); }
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.// www . j ava 2s . c o 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//from w ww .j av a 2s . 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 ww . j a va 2 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: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 w w.ja va2 s . c om*/ * @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 w w . j a va 2 s . c o m*/ * @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 w ww . j a v a 2s . c o 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); }