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:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testNotFoundTruncate() throws IOException { try {/*from www .j a va 2 s . co m*/ streamClient.truncate(TestUtils.NOT_FOUND_STREAM_NAME); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getStatusCode()); } }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Add new configuration files to a given cluster. * * @param id The id of the cluster to add the configuration file to. Not * null/empty/blank./*from w ww . jav a 2 s .co m*/ * @param configs The configuration files to add. Not null/empty/blank. * @return The active configurations for this cluster. * @throws GenieException For any error */ @POST @Path("/{id}/configs") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new configuration files to a cluster", notes = "Add the supplied configuration files to 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> addConfigsForCluster( @ApiParam(value = "Id of the cluster to add configuration to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The configuration files to add.", required = true) final Set<String> configs) throws GenieException { LOG.info("Called with id " + id + " and config " + configs); return this.clusterConfigService.addConfigsForCluster(id, configs); }
From source file:com.mobile.natal.natalchart.NetworkUtilities.java
/** * Get a default message for an HTTP code. * * @param context the context to use. * @param responseCode the http code. * @param defaultOkMessage an optional message for the ok code. * @return the message.//from w ww . j av a 2 s. c o m */ public static String getMessageForCode(Context context, int responseCode, String defaultOkMessage) { Resources resources = context.getResources(); switch (responseCode) { case HttpURLConnection.HTTP_OK: if (defaultOkMessage != null) { return defaultOkMessage; } else { return resources.getString(R.string.http_ok_msg); } case HttpURLConnection.HTTP_FORBIDDEN: return resources.getString(R.string.http_forbidden_msg); case HttpURLConnection.HTTP_UNAUTHORIZED: return resources.getString(R.string.http_forbidden_msg); case HttpURLConnection.HTTP_NOT_FOUND: return resources.getString(R.string.http_not_found_msg); default: return resources.getString(R.string.http_not_implemented_code_msg) + " " + responseCode; } }
From source file:mobi.jenkinsci.alm.assembla.client.AssemblaClient.java
private String getData(final String dataSuffix, final boolean autoLogin) throws IOException { loginWhenNecessary(autoLogin);/*w ww .j a v a2 s.c o m*/ final HttpGet get = new HttpGet(getTargetUrl(dataSuffix)); setRequestHeaders(get, autoLogin); try { final HttpResponse response = httpClient.execute(get, httpContext); switch (response.getStatusLine().getStatusCode()) { case HttpURLConnection.HTTP_OK: final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final InputStream in = response.getEntity().getContent(); IOUtils.copy(in, bout); return new String(bout.toByteArray()); case HttpURLConnection.HTTP_NO_CONTENT: return null; case HttpURLConnection.HTTP_NOT_FOUND: LOG.warn("Resource at " + dataSuffix + " was not found: returning NULL"); return null; case HttpURLConnection.HTTP_UNAUTHORIZED: if (autoLogin) { loginRefresh(); return getData(dataSuffix, false); } default: throw new IOException("Cannot GET " + dataSuffix + " from Assembla: " + response.getStatusLine()); } } finally { get.releaseConnection(); } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TopicResource.java
private Response saveTopic(Topic topic, String httpMethod, String requestContent, boolean entityIsNew) { try {//from ww w . j a va 2s . c o m topic = astroboaClient.getTopicService().save(topic); return ContentApiUtils.createResponseForPutOrPostOfACmsEntity(topic, httpMethod, requestContent, entityIsNew); } catch (CmsUnauthorizedAccessException e) { throw new WebApplicationException(HttpURLConnection.HTTP_UNAUTHORIZED); } catch (Exception e) { logger.error("", e); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Add new tags to a given job./*w w w . j a va 2 s . c om*/ * * @param id The id of the job 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 job. * @throws GenieException For any error */ @POST @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new tags to a job", notes = "Add the supplied tags to 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> addTagsForJob( @ApiParam(value = "Id of the job 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.jobService.addTagsForJob(id, tags); }
From source file:org.eclipse.hono.service.registration.BaseRegistrationService.java
/** * {@inheritDoc}//from w w w . j a v a 2 s. c o m * <p> * Subclasses may override this method in order to implement a more sophisticated approach for asserting registration status, e.g. * using cached information etc. */ @Override public void assertRegistration(final String tenantId, final String deviceId, final Handler<AsyncResult<RegistrationResult>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(deviceId); Objects.requireNonNull(resultHandler); final Future<RegistrationResult> getResultTracker = Future.future(); getDevice(tenantId, deviceId, getResultTracker.completer()); getResultTracker.map(result -> { if (isDeviceEnabled(result)) { return RegistrationResult.from(HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA)), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime())); } else { return RegistrationResult.from(HttpURLConnection.HTTP_NOT_FOUND); } }).setHandler(resultHandler); }
From source file:com.googlecode.onevre.utils.ServerClassLoader.java
private URL getResourceURL(String name) throws IOException { URL url = cachedFiles.get(name); // If the cached jar is not found, find the class in a remote jar file if (url == null) { return getRemoteResource(name); }/* ww w . j a va 2 s. c o m*/ // If the cached jar is found, check if it is updated remotely File jar = cachedJars.get(url); if (System.currentTimeMillis() - jar.lastModified() > CACHE_TIMEOUT) { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); addSslConnection(connection); connection.setRequestMethod("HEAD"); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { long time = connection.getHeaderFieldDate("Last-Modified", System.currentTimeMillis()); // If the remote jar has been updated, // redownload the jar and load it if (jar.lastModified() < time) { downloadJar(url); } else { jar.setLastModified(System.currentTimeMillis()); } } else if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return getRemoteResource(name); } else { throw new IOException("Connection Error: " + connection.getResponseCode() + " " + connection.getResponseMessage()); } } return url; }
From source file:com.scvngr.levelup.core.net.LevelUpResponse.java
/** * Maps an {@link LevelUpStatus} to an HTTP status code from the response. * * @param statusCode the HTTP status code from the response. * @param serverHeader the value of the Server HTTP header; this is used to validate whether the * response is coming from the LevelUp Platform server or a backup/reverse-proxy. * @return {@link LevelUpStatus} describing the status code. *///ww w . ja v a 2s .c o m @NonNull @VisibleForTesting(visibility = Visibility.PRIVATE) /* package */static LevelUpStatus mapStatus(final int statusCode, @Nullable final String serverHeader) { final boolean fromLevelUpPlatform = HTTP_HEADER_VALUE_SERVER.equals(serverHeader); final LevelUpStatus status; if (statusCode >= AbstractResponse.STATUS_CODE_SUCCESS_MIN_INCLUSIVE && statusCode < AbstractResponse.STATUS_CODE_SUCCESS_MAX_EXCLUSIVE) { // A 2xx status code is OK. status = LevelUpStatus.OK; } else if (HttpURLConnection.HTTP_NOT_IMPLEMENTED == statusCode && fromLevelUpPlatform) { /* * The API treats a 501 response as a requirement for the client to be upgraded. * However, in failover etc. this response should be ignored since it may have a * different meaning coming from other servers. */ status = LevelUpStatus.UPGRADE; } else if (HttpURLConnection.HTTP_UNAUTHORIZED == statusCode && fromLevelUpPlatform) { /* * The API treats a 401 response as a notice that the user needs a new access token, and * should be logged out. However, if a reverse-proxy or backup server is sending the * response, this should be ignored since it may have a different meaning coming from * other servers. */ status = LevelUpStatus.LOGIN_REQUIRED; } else if (HttpURLConnection.HTTP_NOT_FOUND == statusCode && fromLevelUpPlatform) { /* * Some endpoints (like PaymentToken) have special meanings for 404s, but in failover * they may just indicate a partially-functioning service and should be treated as * generic network errors. */ status = LevelUpStatus.ERROR_NOT_FOUND; } else if (HttpURLConnection.HTTP_UNAVAILABLE == statusCode) { // LevelUp is down for maintenance (applicable even if the Server header differs). status = LevelUpStatus.ERROR_MAINTENANCE; } else { // All other response codes are server errors. status = LevelUpStatus.ERROR_SERVER; } return status; }
From source file:org.apache.maven.wagon.providers.http.LightweightHttpWagon.java
public boolean resourceExists(String resourceName) throws TransferFailedException, AuthorizationException { HttpURLConnection headConnection; try {/*w w w . j a va2s . c o m*/ URL url = new URL(buildUrl(new Resource(resourceName).getName())); headConnection = (HttpURLConnection) url.openConnection(this.proxy); addHeaders(headConnection); headConnection.setRequestMethod("HEAD"); headConnection.setDoOutput(true); int statusCode = headConnection.getResponseCode(); switch (statusCode) { case HttpURLConnection.HTTP_OK: return true; case HttpURLConnection.HTTP_FORBIDDEN: throw new AuthorizationException("Access denied to: " + url); case HttpURLConnection.HTTP_NOT_FOUND: return false; case HttpURLConnection.HTTP_UNAUTHORIZED: throw new AuthorizationException("Access denied to: " + url); default: throw new TransferFailedException( "Failed to look for file: " + buildUrl(resourceName) + ". Return code is: " + statusCode); } } catch (IOException e) { throw new TransferFailedException("Error transferring file: " + e.getMessage(), e); } }