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:io.takari.maven.testing.executor.junit.MavenVersionResolver.java
private InputStream openStream(URL resource) throws IOException { URLConnection connection = resource.openConnection(); if (connection instanceof HttpURLConnection) { // for some reason, nexus version 2.11.1-01 returns partial maven-metadata.xml // unless request User-Agent header is set to non-default value connection.addRequestProperty("User-Agent", "takari-plugin-testing"); int responseCode = ((HttpURLConnection) connection).getResponseCode(); if (responseCode < 200 || responseCode > 299) { String message = String.format("HTTP/%d %s", responseCode, ((HttpURLConnection) connection).getResponseMessage()); throw responseCode == HttpURLConnection.HTTP_NOT_FOUND ? new FileNotFoundException(message) : new IOException(message); }/* w ww . j a va2 s .com*/ } return connection.getInputStream(); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get all the configuration files for a given command. * * @param id The id of the command to get the configuration files for. Not * NULL/empty/blank./* w ww. ja v a 2s . c o m*/ * @return The active set of configuration files. * @throws GenieException For any error */ @GET @Path("/{id}/configs") @ApiOperation(value = "Get the configuration files for a command", notes = "Get the configuration files 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> getConfigsForCommand( @ApiParam(value = "Id of the command to get configurations for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.commandConfigService.getConfigsForCommand(id); }
From source file:org.eclipse.hono.deviceregistry.FileBasedTenantService.java
/** * Updates a tenant.// w ww . j a v a2 s.c o m * * @param tenantId The identifier of the tenant. * @param tenantSpec The information to update the tenant with. * @return The outcome of the operation indicating success or failure. * @throws NullPointerException if any of the parameters are {@code null}. */ public TenantResult<JsonObject> update(final String tenantId, final JsonObject tenantSpec) { Objects.requireNonNull(tenantId); Objects.requireNonNull(tenantSpec); if (getConfig().isModificationEnabled()) { if (tenants.containsKey(tenantId)) { try { final TenantObject tenant = tenantSpec.mapTo(TenantObject.class); tenant.setTenantId(tenantId); final TenantObject conflictingTenant = getByCa(tenant.getTrustedCaSubjectDn()); if (conflictingTenant != null && !tenantId.equals(conflictingTenant.getTenantId())) { // we are trying to use the same CA as another tenant return TenantResult.from(HttpURLConnection.HTTP_CONFLICT); } else { tenants.put(tenantId, tenant); dirty = true; return TenantResult.from(HttpURLConnection.HTTP_NO_CONTENT); } } catch (IllegalArgumentException e) { return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST); } } else { return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } } else { return TenantResult.from(HttpURLConnection.HTTP_FORBIDDEN); } }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get all the configuration files for a given application. * * @param id The id of the application to get the configuration files for. * Not NULL/empty/blank./*from w w w. j a v a 2s. c om*/ * @return The active set of configuration files. * @throws GenieException For any error */ @GET @Path("/{id}/configs") @ApiOperation(value = "Get the configuration files for an application", notes = "Get the configuration files 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> getConfigsForApplication( @ApiParam(value = "Id of the application to get configurations for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.applicationConfigService.getConfigsForApplication(id); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get all the configuration files for a given cluster. * * @param id The id of the cluster to get the configuration files for. Not * NULL/empty/blank.//from w w w . j av a 2 s.c o m * @return The active set of configuration files. * @throws GenieException For any error */ @GET @Path("/{id}/configs") @ApiOperation(value = "Get the configuration files for a cluster", notes = "Get the configuration files for the cluster with the supplied id.", response = String.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 Set<String> getConfigsForCluster( @ApiParam(value = "Id of the cluster to get configurations for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.clusterConfigService.getConfigsForCluster(id); }
From source file:com.github.pascalgn.jiracli.web.HttpClient.java
private <T> T doExecute(HttpUriRequest request, boolean retry, Function<HttpEntity, T> function) { LOGGER.debug("Calling URL: {} [{}]", request.getURI(), request.getMethod()); // disable XSRF check: if (!request.containsHeader("X-Atlassian-Token")) { request.addHeader("X-Atlassian-Token", "nocheck"); }/*from ww w .j a va 2s. com*/ HttpResponse response; try { response = httpClient.execute(request, httpClientContext); } catch (IOException e) { if (Thread.interrupted()) { LOGGER.trace("Could not call URL: {}", request.getURI(), e); throw new InterruptedError(); } else { throw new IllegalStateException("Could not call URL: " + request.getURI(), e); } } LOGGER.debug("Response received ({})", response.getStatusLine().toString().trim()); HttpEntity entity = response.getEntity(); try { if (Thread.interrupted()) { throw new InterruptedError(); } int statusCode = response.getStatusLine().getStatusCode(); if (isSuccess(statusCode)) { T result; try { result = function.apply(entity, Hint.none()); } catch (NotAuthenticatedException e) { if (retry) { resetAuthentication(); setCredentials(); return doExecute(request, false, function); } else { throw e.getCause(); } } catch (RuntimeException e) { if (Thread.interrupted()) { LOGGER.trace("Could not call URL: {}", request.getURI(), e); throw new InterruptedError(); } else { throw e; } } if (Thread.interrupted()) { throw new InterruptedError(); } return result; } else { if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { resetAuthentication(); if (retry) { setCredentials(); return doExecute(request, false, function); } else { String error = readErrorResponse(request.getURI(), entity); LOGGER.debug("Unauthorized [401]: {}", error); throw new AccessControlException("Unauthorized [401]: " + request.getURI()); } } else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN) { resetAuthentication(); checkAccountLocked(response); if (retry) { setCredentials(); return doExecute(request, false, function); } else { throw new AccessControlException("Forbidden [403]: " + request.getURI()); } } else { String status = response.getStatusLine().toString().trim(); String message; if (entity == null) { message = status; } else { String error = readErrorResponse(request.getURI(), entity); message = status + (error.isEmpty() ? "" : ": " + error); } if (Thread.interrupted()) { throw new InterruptedError(); } if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new NoSuchElementException(message); } else { throw new IllegalStateException(message); } } } } finally { EntityUtils.consumeQuietly(entity); } }
From source file:org.eclipse.orion.server.tests.prefs.PreferenceTest.java
@Test public void testGetNode() throws IOException, JSONException { List<String> locations = getTestPreferenceNodes(); for (String location : locations) { //unknown node should return 404 WebRequest request = new GetMethodWebRequest(location); setAuthentication(request);/*www.j a v a 2 s .co m*/ WebResponse response = webConversation.getResource(request); assertEquals("1." + location, HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); //put a value request = createSetPreferenceRequest(location, "Name", "Frodo"); setAuthentication(request); response = webConversation.getResource(request); assertEquals("2." + location, HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode()); //now doing a get should succeed request = new GetMethodWebRequest(location); setAuthentication(request); response = webConversation.getResource(request); assertEquals("3." + location, HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject result = new JSONObject(response.getText()); assertEquals("4." + location, "Frodo", result.optString("Name")); } }
From source file:net.dahanne.gallery3.client.business.G3Client.java
private HttpEntity requestToResponseEntity(String appendToGalleryUrl, List<NameValuePair> nameValuePairs, String requestMethod, File file) throws UnsupportedEncodingException, IOException, ClientProtocolException, G3GalleryException { HttpClient defaultHttpClient = new DefaultHttpClient(); HttpRequestBase httpMethod;// ww w .ja v a 2 s . com //are we using rewritten urls ? if (this.isUsingRewrittenUrls && appendToGalleryUrl.contains(INDEX_PHP_REST)) { appendToGalleryUrl = StringUtils.remove(appendToGalleryUrl, "index.php"); } logger.debug("requestToResponseEntity , url requested : {}", galleryItemUrl + appendToGalleryUrl); if (POST.equals(requestMethod)) { httpMethod = new HttpPost(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); if (file != null) { MultipartEntity multipartEntity = new MultipartEntity(); String string = nameValuePairs.toString(); // dirty fix to remove the enclosing entity{} String substring = string.substring(string.indexOf("{"), string.lastIndexOf("}") + 1); StringBody contentBody = new StringBody(substring, Charset.forName("UTF-8")); multipartEntity.addPart("entity", contentBody); FileBody fileBody = new FileBody(file); multipartEntity.addPart("file", fileBody); ((HttpPost) httpMethod).setEntity(multipartEntity); } else { ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity(nameValuePairs)); } } else if (PUT.equals(requestMethod)) { httpMethod = new HttpPost(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity(nameValuePairs)); } else if (DELETE.equals(requestMethod)) { httpMethod = new HttpGet(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); //this is to avoid the HTTP 414 (length too long) error //it should only happen when getting items, index.php/rest/items?urls= // } else if(appendToGalleryUrl.length()>2000) { // String resource = appendToGalleryUrl.substring(0,appendToGalleryUrl.indexOf("?")); // String variable = appendToGalleryUrl.substring(appendToGalleryUrl.indexOf("?")+1,appendToGalleryUrl.indexOf("=")); // String value = appendToGalleryUrl.substring(appendToGalleryUrl.indexOf("=")+1); // httpMethod = new HttpPost(galleryItemUrl + resource); // httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); // nameValuePairs.add(new BasicNameValuePair(variable, value)); // ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity( // nameValuePairs)); } else { httpMethod = new HttpGet(galleryItemUrl + appendToGalleryUrl); } if (existingApiKey != null) { httpMethod.setHeader(X_GALLERY_REQUEST_KEY, existingApiKey); } //adding the userAgent to the request httpMethod.setHeader(USER_AGENT, userAgent); HttpResponse response = null; String[] patternsArray = new String[3]; patternsArray[0] = "EEE, dd MMM-yyyy-HH:mm:ss z"; patternsArray[1] = "EEE, dd MMM yyyy HH:mm:ss z"; patternsArray[2] = "EEE, dd-MMM-yyyy HH:mm:ss z"; try { // be extremely careful here, android httpclient needs it to be // an // array of string, not an arraylist defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsArray); response = defaultHttpClient.execute(httpMethod); } catch (ClassCastException e) { List<String> patternsList = Arrays.asList(patternsArray); defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsList); response = defaultHttpClient.execute(httpMethod); } int responseStatusCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = null; if (response.getEntity() != null) { responseEntity = response.getEntity(); } switch (responseStatusCode) { case HttpURLConnection.HTTP_CREATED: break; case HttpURLConnection.HTTP_OK: break; case HttpURLConnection.HTTP_MOVED_TEMP: //the gallery is using rewritten urls, let's remember it and re hit the server this.isUsingRewrittenUrls = true; responseEntity = requestToResponseEntity(appendToGalleryUrl, nameValuePairs, requestMethod, file); break; case HttpURLConnection.HTTP_BAD_REQUEST: throw new G3BadRequestException(); case HttpURLConnection.HTTP_FORBIDDEN: //for some reasons, the gallery may respond with 403 when trying to log in with the wrong url if (appendToGalleryUrl.contains(INDEX_PHP_REST)) { this.isUsingRewrittenUrls = true; responseEntity = requestToResponseEntity(appendToGalleryUrl, nameValuePairs, requestMethod, file); break; } throw new G3ForbiddenException(); case HttpURLConnection.HTTP_NOT_FOUND: throw new G3ItemNotFoundException(); default: throw new G3GalleryException("HTTP code " + responseStatusCode); } return responseEntity; }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Get all the tags for a given job.// w w w .j a v a 2 s . co m * * @param id The id of the job to get the tags for. Not * NULL/empty/blank. * @return The active set of tags. * @throws GenieException For any error */ @GET @Path("/{id}/tags") @ApiOperation(value = "Get the tags for a job", notes = "Get the tags for the job with the supplied 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> getTagsForJob( @ApiParam(value = "Id of the job to get tags for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.jobService.getTagsForJob(id); }
From source file:com.netflix.genie.server.services.impl.GenieExecutionServiceImpl.java
/** {@inheritDoc} */ @Override/*from ww w .j a v a2s . c o m*/ public JobInfoResponse getJobs(String jobID, String jobName, String userName, String jobType, String status, String clusterName, String clusterId, Integer limit, Integer page) { logger.info("called"); JobInfoResponse response; String table = JobInfoElement.class.getSimpleName(); ClauseBuilder criteria = null; try { criteria = new ClauseBuilder(ClauseBuilder.AND); if ((jobID != null) && (!jobID.isEmpty())) { String query = "jobID like '" + jobID + "'"; criteria.append(query); } if ((jobName != null) && (!jobName.isEmpty())) { String query = "jobName like '" + jobName + "'"; criteria.append(query); } if ((userName != null) && (!userName.isEmpty())) { String query = "userName='" + userName + "'"; criteria.append(query); } if ((jobType != null) && (!jobType.isEmpty())) { if (Types.JobType.parse(jobType) == null) { throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, "Job type: " + jobType + " can only be HADOOP, HIVE or PIG"); } String query = "jobType='" + jobType.toUpperCase() + "'"; criteria.append(query); } if ((status != null) && (!status.isEmpty())) { if (Types.JobStatus.parse(status) == null) { throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, "Unknown job status: " + status); } String query = "status='" + status.toUpperCase() + "'"; criteria.append(query); } if ((clusterName != null) && (!clusterName.isEmpty())) { String query = "clusterName='" + clusterName + "'"; criteria.append(query); } if ((clusterId != null) && (!clusterId.isEmpty())) { String query = "clusterId='" + clusterId + "'"; criteria.append(query); } } catch (CloudServiceException e) { logger.error(e.getMessage(), e); response = new JobInfoResponse(e); return response; } Object[] results; try { QueryBuilder builder = new QueryBuilder().table(table).clause(criteria.toString()).limit(limit) .page(page); results = pm.query(builder); } catch (Exception e) { logger.error("Failed to get job results from database: ", e); response = new JobInfoResponse( new CloudServiceException(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage())); return response; } if (results.length != 0) { JobInfoElement[] jobInfos = new JobInfoElement[results.length]; for (int i = 0; i < results.length; i++) { jobInfos[i] = (JobInfoElement) results[i]; } response = new JobInfoResponse(); response.setJobs(jobInfos); response.setMessage("Returning job information for specified criteria"); return response; } else { response = new JobInfoResponse(new CloudServiceException(HttpURLConnection.HTTP_NOT_FOUND, "No jobs found for specified criteria")); return response; } }