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:org.eclipse.orion.server.tests.servlets.files.AdvancedFilesTest.java
@Test public void testETagDeletedFile() throws JSONException, IOException, SAXException, CoreException { String fileName = "testfile.txt"; //setup: create a file WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //obtain file metadata and ensure data is correct request = getGetFilesRequest(fileName + "?parts=meta"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG); assertNotNull(etag);/*from w ww . jav a2s .co m*/ //delete the file on disk IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName)); fileStore.delete(EFS.NONE, null); //now a PUT should fail request = getPutFileRequest(fileName, "something"); request.setHeaderField(ProtocolConstants.HEADER_IF_MATCH, etag); try { response = webConversation.getResponse(request); } catch (IOException e) { //inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0); } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Create a Command configuration./* ww w. j av a 2 s. co m*/ * * @param command The command configuration to create * @return The command created * @throws GenieException For any error */ @POST @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Create a command", notes = "Create a command from the supplied information.", response = Command.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Created", response = Command.class), @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = "A command with the supplied id already exists"), @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 Response createCommand( @ApiParam(value = "The command to create.", required = true) final Command command) throws GenieException { LOG.info("called to create new command configuration " + command.toString()); final Command createdCommand = this.commandConfigService.createCommand(command); return Response.created(this.uriInfo.getAbsolutePathBuilder().path(createdCommand.getId()).build()) .entity(createdCommand).build(); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Create cluster configuration./*from ww w .j a v a 2s .c o m*/ * * @param cluster contains the cluster information to create * @return The created cluster * @throws GenieException For any error */ @POST @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Create a cluster", notes = "Create a cluster from the supplied information.", response = Cluster.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Created", response = Cluster.class), @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = "A cluster with the supplied id already exists"), @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 Response createCluster( @ApiParam(value = "The cluster to create.", required = true) final Cluster cluster) throws GenieException { LOG.info("Called to create new cluster " + cluster); final Cluster createdCluster = this.clusterConfigService.createCluster(cluster); return Response.created(this.uriInfo.getAbsolutePathBuilder().path(createdCluster.getId()).build()) .entity(createdCluster).build(); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Create an Application.//from w w w. j a v a 2 s . c om * * @param app The application to create * @return The created application configuration * @throws GenieException For any error */ @POST @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Create an application", notes = "Create an application from the supplied information.", response = Application.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Application created successfully.", response = Application.class), @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = "An application with the supplied id already exists"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "A precondition failed"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Response createApplication( @ApiParam(value = "The application to create.", required = true) final Application app) throws GenieException { LOG.info("Called to create new application"); final Application createdApp = this.applicationConfigService.createApplication(app); return Response.created(this.uriInfo.getAbsolutePathBuilder().path(createdApp.getId()).build()) .entity(createdApp).build(); }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Submit a new job.// w w w .jav a 2s. com * * @param job request object containing job info element for new job * @return The submitted job * @throws GenieException For any error */ @POST @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Submit a job", notes = "Submit a new job to run to genie", response = Job.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Created", response = Job.class), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = "Job with ID already exists."), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Precondition Failed"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Response submitJob(@ApiParam(value = "Job object to run.", required = true) final Job job) throws GenieException { if (job == null) { throw new GenieException(HttpURLConnection.HTTP_PRECON_FAILED, "No job entered. Unable to submit."); } LOG.info("Called to submit job: " + job); // get client's host from the context String clientHost = this.httpServletRequest.getHeader(FORWARDED_FOR_HEADER); if (clientHost != null) { clientHost = clientHost.split(",")[0]; } else { clientHost = this.httpServletRequest.getRemoteAddr(); } // set the clientHost, if it is not overridden already if (StringUtils.isNotBlank(clientHost)) { LOG.debug("called from: " + clientHost); job.setClientHost(clientHost); } final Job createdJob = this.executionService.submitJob(job); return Response.created(this.uriInfo.getAbsolutePathBuilder().path(createdJob.getId()).build()) .entity(createdJob).build(); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get cluster configuration from unique id. * * @param id id for the cluster// w w w.j ava 2 s .com * @return the cluster * @throws GenieException For any error */ @GET @Path("/{id}") @ApiOperation(value = "Find a cluster by id", notes = "Get the cluster by id if it exists", response = Cluster.class) @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 Cluster getCluster( @ApiParam(value = "Id of the cluster to get.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id: " + id); return this.clusterConfigService.getCluster(id); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get Command configuration for given id. * * @param id unique id for command configuration * @return The command configuration/* w w w. ja v a2 s.co m*/ * @throws GenieException For any error */ @GET @Path("/{id}") @ApiOperation(value = "Find a command by id", notes = "Get the command by id if it exists", response = Command.class) @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 Command getCommand( @ApiParam(value = "Id of the command to get.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called to get command with id " + id); return this.commandConfigService.getCommand(id); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get Application for given id.// w ww .ja v a 2 s. c om * * @param id unique id for application configuration * @return The application configuration * @throws GenieException For any error */ @GET @Path("/{id}") @ApiOperation(value = "Find an application by id", notes = "Get the application by id if it exists", response = Application.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "OK", response = Application.class), @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 Application getApplication( @ApiParam(value = "Id of the application to get.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called to get Application for id " + id); return this.applicationConfigService.getApplication(id); }
From source file:org.eclipse.orion.server.tests.servlets.files.AdvancedFilesTest.java
@Test public void testETagPutNotMatch() throws JSONException, IOException, SAXException, CoreException { String fileName = "testfile.txt"; //setup: create a file WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //obtain file metadata and ensure data is correct request = getGetFilesRequest(fileName + "?parts=meta"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG); assertNotNull(etag);//from w w w . j a v a 2 s . co m //change the file on disk IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName)); OutputStream out = fileStore.openOutputStream(EFS.NONE, null); out.write("New Contents".getBytes()); out.close(); //now a PUT should fail request = getPutFileRequest(fileName, "something"); request.setHeaderField("If-Match", etag); try { response = webConversation.getResponse(request); } catch (IOException e) { //inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0); } }