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.JobResource.java
/** * Get job information for given job id. * * @param id id for job to look up/* w w w .ja v a 2s . c om*/ * @return the Job * @throws GenieException For any error */ @GET @Path("/{id}") @ApiOperation(value = "Find a job by id", notes = "Get the job by id if it exists", response = Job.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job 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 Job getJob(@ApiParam(value = "Id of the job to get.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("called for job with id: " + id); return this.jobService.getJob(id); }
From source file:org.eclipse.orion.server.tests.servlets.files.CoreFilesTest.java
@Test public void testCopyFileOverwrite() throws Exception { String directoryPath = "testCopyFile/directory/path" + System.currentTimeMillis(); String sourcePath = directoryPath + "/source.txt"; String destName = "destination.txt"; String destPath = directoryPath + "/" + destName; createDirectory(directoryPath);//from w w w . j ava 2s . c o m createFile(sourcePath, "This is the contents"); createFile(destPath, "Original file"); //with no-overwrite, copy should fail JSONObject requestObject = new JSONObject(); addSourceLocation(requestObject, sourcePath); WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt"); request.setHeaderField("X-Create-Options", "copy,no-overwrite"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode()); //now omit no-overwrite and copy should succeed and return 200 instead of 201 request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt"); request.setHeaderField("X-Create-Options", "copy"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject responseObject = new JSONObject(response.getText()); checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null, null); assertTrue(checkFileExists(sourcePath)); assertTrue(checkFileExists(destPath)); }
From source file:net.reichholf.dreamdroid.helpers.SimpleHttpClient.java
/** * @param uri/*w ww . ja v a2 s.c o m*/ * @param parameters * @return */ public boolean fetchPageContent(String uri, List<NameValuePair> parameters) { // Set login, ssl, port, host etc; applyConfig(); mErrorText = ""; mErrorTextId = -1; mError = false; mBytes = new byte[0]; if (!uri.startsWith("/")) { uri = "/".concat(uri); } HttpURLConnection conn = null; try { if (mProfile.getSessionId() != null) parameters.add(new BasicNameValuePair("sessionid", mProfile.getSessionId())); URL url = new URL(buildUrl(uri, parameters)); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(mConnectionTimeoutMillis); if (DreamDroid.featurePostRequest()) conn.setRequestMethod("POST"); setAuth(conn); if (conn.getResponseCode() != 200) { if (conn.getResponseCode() == HttpURLConnection.HTTP_BAD_METHOD && mRememberedReturnCode != HttpURLConnection.HTTP_BAD_METHOD) { // Method not allowed, the target device either can't handle // POST or GET requests (old device or Anti-Hijack enabled) DreamDroid.setFeaturePostRequest(!DreamDroid.featurePostRequest()); conn.disconnect(); mRememberedReturnCode = HttpURLConnection.HTTP_BAD_METHOD; return fetchPageContent(uri, parameters); } if (conn.getResponseCode() == HttpURLConnection.HTTP_PRECON_FAILED && mRememberedReturnCode != HttpURLConnection.HTTP_PRECON_FAILED) { createSession(); conn.disconnect(); mRememberedReturnCode = HttpURLConnection.HTTP_PRECON_FAILED; return fetchPageContent(uri, parameters); } mRememberedReturnCode = 0; Log.e(LOG_TAG, Integer.toString(conn.getResponseCode())); switch (conn.getResponseCode()) { case HttpURLConnection.HTTP_UNAUTHORIZED: mErrorTextId = R.string.auth_error; break; default: mErrorTextId = -1; } mErrorText = conn.getResponseMessage(); mError = true; return false; } BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); ByteArrayBuffer baf = new ByteArrayBuffer(50); int read = 0; int bufSize = 512; byte[] buffer = new byte[bufSize]; while ((read = bis.read(buffer)) != -1) { baf.append(buffer, 0, read); } mBytes = baf.toByteArray(); if (DreamDroid.dumpXml()) dumpToFile(url); return true; } catch (MalformedURLException e) { mError = true; mErrorTextId = R.string.illegal_host; } catch (UnknownHostException e) { mError = true; mErrorText = null; mErrorTextId = R.string.host_not_found; } catch (ProtocolException e) { mError = true; mErrorText = e.getLocalizedMessage(); } catch (ConnectException e) { mError = true; mErrorTextId = R.string.host_unreach; } catch (IOException e) { e.printStackTrace(); mError = true; mErrorText = e.getLocalizedMessage(); } finally { if (conn != null) conn.disconnect(); if (mError) if (mErrorText == null) mErrorText = "Error text is null"; Log.e(LOG_TAG, mErrorText); } return false; }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get Command configuration based on user parameters. * * @param name Name for command (optional) * @param userName The user who created the configuration (optional) * @param statuses The statuses of the commands to get (optional) * @param tags The set of tags you want the command for. * @param page The page to start one (optional) * @param limit The max number of results to return per page (optional) * @param descending Whether results returned in descending or ascending order (optional) * @param orderBys The fields to order the results by (optional) * @return All the Commands matching the criteria or all if no criteria * @throws GenieException For any error/*from w ww . j a v a 2 s . com*/ */ @GET @ApiOperation(value = "Find commands", notes = "Find commands by the submitted criteria.", response = Command.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "One of the statuses was invalid"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Command> getCommands( @ApiParam(value = "Name of the command.") @QueryParam("name") final String name, @ApiParam(value = "User who created the command.") @QueryParam("userName") final String userName, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info("Called [name | userName | status | tags | page | limit | descending | orderBys]"); LOG.info(name + " | " + userName + " | " + statuses + " | " + tags + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); 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.commandConfigService.getCommands(name, userName, enumStatuses, tags, page, limit, descending, orderBys); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get cluster config based on user params. If empty strings are passed for * they are treated as nulls (not false). * * @param name cluster name (can be a pattern) * @param statuses valid types - Types.ClusterStatus * @param tags tags for the cluster * @param minUpdateTime min time when cluster configuration was updated * @param maxUpdateTime max time when cluster configuration was updated * @param limit number of entries to return * @param page page number/* w w w . j a v a2s .c om*/ * @param descending Whether results returned in descending or ascending order * @param orderBys The fields to order the results by * @return the Clusters found matching the criteria * @throws GenieException For any error */ @GET @ApiOperation(value = "Find clusters", notes = "Find clusters by the submitted criteria.", response = Cluster.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "If one of status is invalid"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Cluster> getClusters( @ApiParam(value = "Name of the cluster.") @QueryParam("name") final String name, @ApiParam(value = "Status of the cluster.", allowableValues = "UP, OUT_OF_SERVICE, TERMINATED") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "Minimum time threshold for cluster update") @QueryParam("minUpdateTime") final Long minUpdateTime, @ApiParam(value = "Maximum time threshold for cluster update") @QueryParam("maxUpdateTime") final Long maxUpdateTime, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info( "Called [name | statuses | tags | minUpdateTime | maxUpdateTime | page | limit | descending | orderBys]"); LOG.info(name + " | " + statuses + " | " + tags + " | " + minUpdateTime + " | " + maxUpdateTime + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); //Create this conversion internal in case someone uses lower case by accident? Set<ClusterStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(ClusterStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(ClusterStatus.parse(status)); } } } return this.clusterConfigService.getClusters(name, enumStatuses, tags, minUpdateTime, maxUpdateTime, page, limit, descending, orderBys); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get Applications based on user parameters. * * @param name name for configuration (optional) * @param userName The user who created the application (optional) * @param statuses The statuses of the applications (optional) * @param tags The set of tags you want the command for. * @param page The page to start one (optional) * @param limit the max number of results to return per page (optional) * @param descending Whether results returned in descending or ascending order (optional) * @param orderBys The fields to order the results by (optional) * @return All applications matching the criteria * @throws GenieException For any error/*from w w w.j a va2s .c o m*/ */ @GET @ApiOperation(value = "Find applications", notes = "Find applications by the submitted criteria.", response = Application.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "If status is invalid."), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Application> getApplications( @ApiParam(value = "Name of the application.") @QueryParam("name") final String name, @ApiParam(value = "User who created the application.") @QueryParam("userName") final String userName, @ApiParam(value = "The status of the applications to get.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info("Called [name | userName | status | tags | page | limit | descending | orderBys]"); LOG.info(name + " | " + userName + " | " + statuses + " | " + tags + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); Set<ApplicationStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(ApplicationStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(ApplicationStatus.parse(status)); } } } return this.applicationConfigService.getApplications(name, userName, enumStatuses, tags, page, limit, descending, orderBys); }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Get job status for give job id./*from w ww. ja va 2s.c o m*/ * * @param id id for job to look up * @return The status of the job * @throws GenieException For any error */ @GET @Path("/{id}/status") @ApiOperation(value = "Get the status of the job ", notes = "Get the status of job whose id is sent", response = String.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job 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 ObjectNode getJobStatus( @ApiParam(value = "Id of the job.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called for job id:" + id); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); node.put("status", this.jobService.getJobStatus(id).toString()); return node; }
From source file:org.hyperic.hq.plugin.netservices.HTTPCollector.java
private double getAvail(int code) { // There are too many options to list everything that is // successful. So, instead we are going to call out the // things that should be considered failure, everything else // is OK.//from www . ja v a 2s . co m switch (code) { case HttpURLConnection.HTTP_BAD_REQUEST: case HttpURLConnection.HTTP_FORBIDDEN: case HttpURLConnection.HTTP_NOT_FOUND: case HttpURLConnection.HTTP_BAD_METHOD: case HttpURLConnection.HTTP_CLIENT_TIMEOUT: case HttpURLConnection.HTTP_CONFLICT: case HttpURLConnection.HTTP_PRECON_FAILED: case HttpURLConnection.HTTP_ENTITY_TOO_LARGE: case HttpURLConnection.HTTP_REQ_TOO_LONG: case HttpURLConnection.HTTP_INTERNAL_ERROR: case HttpURLConnection.HTTP_NOT_IMPLEMENTED: case HttpURLConnection.HTTP_UNAVAILABLE: case HttpURLConnection.HTTP_VERSION: case HttpURLConnection.HTTP_BAD_GATEWAY: case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: return Metric.AVAIL_DOWN; default: } if (hasCredentials()) { if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { return Metric.AVAIL_DOWN; } } return Metric.AVAIL_UP; }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Get jobs for given filter criteria.//from w ww .ja v a 2s .com * * @param id id for job * @param name name of job (can be a SQL-style pattern such as HIVE%) * @param userName user who submitted job * @param statuses statuses of jobs to find * @param tags tags for the job * @param clusterName the name of the cluster * @param clusterId the id of the cluster * @param commandName the name of the command run by the job * @param commandId the id of the command run by the job * @param page page number for job * @param limit max number of jobs to return * @param descending Whether the order of the results should be descending or ascending * @param orderBys Fields to order the results by * @return successful response, or one with HTTP error code * @throws GenieException For any error */ @GET @ApiOperation(value = "Find jobs", notes = "Find jobs by the submitted criteria.", response = Job.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job 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 List<Job> getJobs(@ApiParam(value = "Id of the job.") @QueryParam("id") final String id, @ApiParam(value = "Name of the job.") @QueryParam("name") final String name, @ApiParam(value = "Name of the user who submitted the job.") @QueryParam("userName") final String userName, @ApiParam(value = "Statuses of the jobs to fetch.", allowableValues = "INIT, RUNNING, SUCCEEDED, KILLED, FAILED") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the job.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "Name of the cluster on which the job ran.") @QueryParam("executionClusterName") final String clusterName, @ApiParam(value = "Id of the cluster on which the job ran.") @QueryParam("executionClusterId") final String clusterId, @ApiParam(value = "The page to start on.") @QueryParam("commandName") final String commandName, @ApiParam(value = "Id of the cluster on which the job ran.") @QueryParam("commandId") final String commandId, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info("Called with [id | jobName | userName | statuses | executionClusterName " + "| executionClusterId | page | limit | descending | orderBys]"); LOG.info(id + " | " + name + " | " + userName + " | " + statuses + " | " + tags + " | " + clusterName + " | " + clusterId + " | " + commandName + " | " + commandId + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); Set<JobStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(JobStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(JobStatus.parse(status)); } } } return this.jobService.getJobs(id, name, userName, enumStatuses, tags, clusterName, clusterId, commandName, commandId, page, limit, descending, orderBys); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Update command configuration.// w w w. j a v a2 s . co m * * @param id unique id for the configuration to update. * @param updateCommand the information to update the command with * @return The updated command * @throws GenieException For any error */ @PUT @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update a command", notes = "Update a command from the supplied information.", response = Command.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command to update 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 updateCommand( @ApiParam(value = "Id of the command to update.", required = true) @PathParam("id") final String id, @ApiParam(value = "The command information to update.", required = true) final Command updateCommand) throws GenieException { LOG.info("Called to create/update comamnd config"); return this.commandConfigService.updateCommand(id, updateCommand); }