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:org.apache.maven.wagon.providers.http.LightweightHttpWagon.java
protected void finishPutTransfer(Resource resource, InputStream input, OutputStream output) throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException { try {/* ww w. j av a 2s .c o m*/ int statusCode = putConnection.getResponseCode(); switch (statusCode) { // Success Codes case HttpURLConnection.HTTP_OK: // 200 case HttpURLConnection.HTTP_CREATED: // 201 case HttpURLConnection.HTTP_ACCEPTED: // 202 case HttpURLConnection.HTTP_NO_CONTENT: // 204 break; case HttpURLConnection.HTTP_FORBIDDEN: throw new AuthorizationException("Access denied to: " + buildUrl(resource.getName())); case HttpURLConnection.HTTP_NOT_FOUND: throw new ResourceDoesNotExistException( "File: " + buildUrl(resource.getName()) + " does not exist"); // add more entries here default: throw new TransferFailedException("Failed to transfer file: " + buildUrl(resource.getName()) + ". Return code is: " + statusCode); } } catch (IOException e) { fireTransferError(resource, e, TransferEvent.REQUEST_PUT); throw new TransferFailedException("Error transferring file: " + e.getMessage(), e); } }
From source file:org.eclipse.hono.deviceregistry.FileBasedTenantService.java
private TenantResult<JsonObject> getForCertificateAuthority(final X500Principal subjectDn) { if (subjectDn == null) { return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST); } else {/*from w w w . j a v a 2 s . com*/ final TenantObject tenant = getByCa(subjectDn); if (tenant == null) { return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } } }
From source file:org.eclipse.ecf.tests.filetransfer.URLRetrieveTest.java
License:asdf
public void testFailedReceive() throws Exception { try {// w w w . j a va2s . c o m testReceiveFails(HTTP_404_FAIL_RETRIEVE); assertDoneExceptionAfterServerResponse(HttpURLConnection.HTTP_NOT_FOUND); } catch (final Exception e) { e.printStackTrace(); fail(e.toString()); } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Update command configuration./*from ww w. ja va 2 s .c om*/ * * @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); }
From source file:org.eclipse.orion.server.tests.servlets.site.SiteTest.java
@Test /**/* w w w . j a v a 2 s. c o m*/ * Create a site, then delete it and make sure it's gone. */ public void testDeleteSite() throws SAXException, JSONException, IOException, URISyntaxException, CoreException { // Create site final String name = "A site to delete"; final String workspaceId = workspaceObject.getString(ProtocolConstants.KEY_ID); WebResponse createResp = createSite(name, workspaceId, null, null, null); JSONObject site = new JSONObject(createResp.getText()); final String siteId = site.getString(ProtocolConstants.KEY_ID); String location = site.getString(ProtocolConstants.HEADER_LOCATION); UserInfo user = OrionConfiguration.getMetaStore().readUser(testUserId); SiteInfo siteInfo = SiteInfo.getSite(user, siteId); Assert.assertNotNull(siteInfo); // Delete site WebRequest deleteReq = getDeleteSiteRequest(location); WebResponse deleteResp = webConversation.getResponse(deleteReq); assertEquals(HttpURLConnection.HTTP_OK, deleteResp.getResponseCode()); // GET should fail now WebRequest getReq = getRetrieveSiteRequest(location, null); WebResponse getResp = webConversation.getResponse(getReq); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, getResp.getResponseCode()); user = OrionConfiguration.getMetaStore().readUser(testUserId); siteInfo = SiteInfo.getSite(user, siteId); Assert.assertNull(siteInfo); // GET all sites should not include the deleted site WebRequest getAllReq = getRetrieveAllSitesRequest(null); WebResponse getAllResp = webConversation.getResponse(getAllReq); JSONObject allSitesJson = new JSONObject(getAllResp.getText()); JSONArray allSites = allSitesJson.getJSONArray(SiteConfigurationConstants.KEY_SITE_CONFIGURATIONS); for (int i = 0; i < allSites.length(); i++) { assertEquals(false, allSites.getJSONObject(i).getString(ProtocolConstants.KEY_ID).equals(siteId)); } }
From source file:org.wso2.developerstudio.eclipse.registry.base.remote.RemoteRegistry.java
public Resource get(String path) throws RegistryException { AbderaClient abderaClient = new AbderaClient(abdera); AbderaClient.registerTrustManager(new TrustEverythingTrustManager()); ClientResponse clientResponse;//from w w w . j av a2 s .c o m String encodedPath; // If the request is to fetch all comments for a given path, then encode ":" as well to // avoid confusion with versioned paths. if (path.endsWith(RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_COMMENTS)) { encodedPath = encodeURL(path); if (encodedPath.contains(RegistryConstants.VERSION_SEPARATOR)) { int index = encodedPath.lastIndexOf(RegistryConstants.VERSION_SEPARATOR); encodedPath = encodedPath.substring(0, index).replace(":", "%3A") + encodedPath.substring(index); } else { encodedPath = encodedPath.replace(":", "%3A"); } } else { encodedPath = encodeURL(path); } if (!cache.isResourceCached(path)) { clientResponse = abderaClient.get(baseURI + "/atom" + encodedPath, getAuthorization()); } else { clientResponse = abderaClient.get(baseURI + "/atom" + encodedPath, getAuthorizationForCaching(path)); } if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR || clientResponse.getType() == Response.ResponseType.SERVER_ERROR) { if (clientResponse.getStatus() == HttpURLConnection.HTTP_NOT_FOUND) { abderaClient.teardown(); throw new ResourceNotFoundException(path); } abderaClient.teardown(); throw new RegistryException(clientResponse.getStatusText()); } if (clientResponse.getStatus() == HttpURLConnection.HTTP_NOT_MODIFIED) { abderaClient.teardown(); /*do caching here */ log.debug("Cached resource returned since no modification has been done on the resource"); return cache.getCachedResource(path); } String eTag = clientResponse.getHeader("ETag"); Element introspection = clientResponse.getDocument().getRoot(); ResourceImpl resource; if (introspection instanceof Feed) { // This is a collection Feed feed = (Feed) introspection; String state = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, APPConstants.NAMESPACE_STATE)); if (state != null && state.equals("Deleted")) { abderaClient.teardown(); throw new ResourceNotFoundException(path); } resource = createResourceFromFeed(feed); } else { Entry entry = (Entry) introspection; resource = createResourceFromEntry(entry); } /* if the resource is not Get before add it to cache before adding it check the max cache or if the resource is modified then new resource is replacing the current resource in the cache * size configured in registry.xml */ if (!cache.cacheResource(path, resource, eTag, RegistryConstants.MAX_REG_CLIENT_CACHE_SIZE)) { log.debug("Max Cache size exceeded the configured Cache size"); } abderaClient.teardown(); // resource.setPath(path); return resource; }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Update application./*from w w w . j ava 2 s.c o m*/ * * @param id unique id for configuration to update * @param updateApp contains the application information to update * @return successful response, or one with an HTTP error code * @throws GenieException For any error */ @PUT @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update an application", notes = "Update an application from the supplied information.", response = Application.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application to update 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 updateApplication( @ApiParam(value = "Id of the application to update.", required = true) @PathParam("id") final String id, @ApiParam(value = "The application information to update.", required = true) final Application updateApp) throws GenieException { LOG.info("called to update application config with info " + updateApp.toString()); return this.applicationConfigService.updateApplication(id, updateApp); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Update a cluster configuration./*from w w w . j a v a2s.co m*/ * * @param id unique if for cluster to update * @param updateCluster contains the cluster information to update * @return the updated cluster * @throws GenieException For any error */ @PUT @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update a cluster", notes = "Update a cluster from the supplied information.", response = Cluster.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster 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 Cluster updateCluster( @ApiParam(value = "Id of the cluster to update.", required = true) @PathParam("id") final String id, @ApiParam(value = "The cluster information to update with.", required = true) final Cluster updateCluster) throws GenieException { LOG.info("Called to update cluster with id " + id + " update fields " + updateCluster); return this.clusterConfigService.updateCluster(id, updateCluster); }
From source file:com.microsoft.azure.storage.table.QueryTableOperation.java
private StorageRequest<CloudTableClient, QueryTableOperation, TableResult> retrieveImpl( final CloudTableClient client, final String tableName, final TableRequestOptions options) { final boolean isTableEntry = TableConstants.TABLES_SERVICE_TABLES_NAME.equals(tableName); if (this.getClazzType() != null) { Utility.checkNullaryCtor(this.getClazzType()); } else {/* ww w . ja v a 2 s . c o m*/ Utility.assertNotNull(SR.QUERY_REQUIRES_VALID_CLASSTYPE_OR_RESOLVER, this.getResolver()); } final StorageRequest<CloudTableClient, QueryTableOperation, TableResult> getRequest = new StorageRequest<CloudTableClient, QueryTableOperation, TableResult>( options, client.getStorageUri()) { @Override public void setRequestLocationMode() { this.setRequestLocationMode(isPrimaryOnlyRetrieve() ? RequestLocationMode.PRIMARY_ONLY : RequestLocationMode.PRIMARY_OR_SECONDARY); } @Override public HttpURLConnection buildRequest(CloudTableClient client, QueryTableOperation operation, OperationContext context) throws Exception { return TableRequest.query(client.getTransformedEndPoint(context).getUri(this.getCurrentLocation()), options, null/* Query Builder */, context, tableName, generateRequestIdentity(isTableEntry, operation.getPartitionKey()), null/* Continuation Token */); } @Override public void signRequest(HttpURLConnection connection, CloudTableClient client, OperationContext context) throws Exception { StorageRequest.signTableRequest(connection, client, -1L, context); } @Override public TableResult preProcessResponse(QueryTableOperation operation, CloudTableClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK && this.getResult().getStatusCode() != HttpURLConnection.HTTP_NOT_FOUND) { this.setNonExceptionedRetryableFailure(true); } return null; } @Override public TableResult postProcessResponse(HttpURLConnection connection, QueryTableOperation operation, CloudTableClient client, OperationContext context, TableResult storageObject) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { // Empty result return new TableResult(this.getResult().getStatusCode()); } // Parse response for updates InputStream inStream = connection.getInputStream(); TableResult res = parseResponse(inStream, this.getResult().getStatusCode(), this.getConnection().getHeaderField(TableConstants.HeaderConstants.ETAG), context, options); return res; } @Override public StorageExtendedErrorInformation parseErrorDetails() { return TableStorageErrorDeserializer.parseErrorDetails(this); } }; return getRequest; }
From source file:me.philio.ghost.ui.LoginFragment.java
@Override public void failure(RetrofitError error) { Log.d(TAG, "Authentication failed"); // Parse error JSON ErrorResponse errorResponse = (ErrorResponse) error.getBodyAs(ErrorResponse.class); // Extract the first error message (at time of writing there is only ever one) String errorMsg = null;// w ww . j a v a2 s. c o m if (errorResponse != null && errorResponse.errors != null && errorResponse.errors.size() > 0) { String rawMsg = errorResponse.errors.get(0).message; errorMsg = Html.fromHtml(rawMsg).toString(); } // Show user an error int status = 0; if (error.getResponse() != null) { status = error.getResponse().getStatus(); } switch (status) { case HttpURLConnection.HTTP_NOT_FOUND: mEditEmail.setError(errorMsg != null ? errorMsg : getString(R.string.error_incorrect_email)); break; case HttpURLConnection.HTTP_FORBIDDEN: mEditEmail.setError(errorMsg != null ? errorMsg : getString(R.string.error_incorrect_email)); break; case HttpURLConnection.HTTP_UNAUTHORIZED: mEditPassword.setError(errorMsg != null ? errorMsg : getString(R.string.error_invalid_password)); break; } // Enable button and hide progress bar mBtnLogin.setEnabled(true); ((LoginActivity) getActivity()).setToolbarProgressBarVisibility(false); }