List of usage examples for java.net HttpURLConnection HTTP_NOT_IMPLEMENTED
int HTTP_NOT_IMPLEMENTED
To view the source code for java.net HttpURLConnection HTTP_NOT_IMPLEMENTED.
Click Source Link
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. *//*from www . 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.eclipse.hono.service.registration.BaseRegistrationService.java
/** * Handles an unimplemented operation by failing the given handler * with a {@link ClientErrorException} having a <em>501 Not Implemented</em> status code. * /*from w w w. j a v a 2 s. c o m*/ * @param resultHandler The handler. */ protected void handleUnimplementedOperation(final Handler<AsyncResult<RegistrationResult>> resultHandler) { resultHandler .handle(Future.succeededFuture(RegistrationResult.from(HttpURLConnection.HTTP_NOT_IMPLEMENTED))); }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java
private Response retrieveTaxonomies(String cmsQuery, Integer offset, Integer limit, String orderBy, Output output, String callback, boolean prettyPrint, FetchLevel fetchLevel) { try {/*w w w.j a va 2s .co m*/ if (output == null) { output = Output.XML; } if (fetchLevel == null) { fetchLevel = FetchLevel.ENTITY; } StringBuilder resourceRepresentation = new StringBuilder(); //List<Taxonomy> taxonomies = new ArrayList<Taxonomy>(); if (!StringUtils.isBlank(cmsQuery)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_IMPLEMENTED); } switch (output) { case XML: { String resourceCollectionAsXML = astroboaClient.getTaxonomyService() .getAllTaxonomies(ResourceRepresentationType.XML, fetchLevel, prettyPrint); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(resourceCollectionAsXML); } else { ContentApiUtils.generateXMLP(resourceRepresentation, resourceCollectionAsXML, callback); } break; } case JSON: String resourceCollectionAsJSON = astroboaClient.getTaxonomyService() .getAllTaxonomies(ResourceRepresentationType.JSON, fetchLevel, prettyPrint); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(resourceCollectionAsJSON); } else { ContentApiUtils.generateJSONP(resourceRepresentation, resourceCollectionAsJSON, callback); } break; } return ContentApiUtils.createResponse(resourceRepresentation, output, callback, null); } catch (Exception e) { logger.error("Cms query " + cmsQuery, e); throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:net.myrrix.client.ClientRecommender.java
private int getNumClusters(boolean user) throws TasteException { String urlPath = '/' + (user ? "user" : "item") + "/clusters/count"; TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(0L)) { HttpURLConnection connection = null; try {// w w w . j a v a2 s. co m connection = buildConnectionToReplica(replica, urlPath, "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: BufferedReader reader = IOUtils.bufferStream(connection.getInputStream()); try { return Integer.parseInt(reader.readLine()); } finally { reader.close(); } case HttpURLConnection.HTTP_NOT_IMPLEMENTED: throw new UnsupportedOperationException(); case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
From source file:net.myrrix.client.ClientRecommender.java
private FastIDSet getCluster(int n, boolean user) throws TasteException { String urlPath = '/' + (user ? "user" : "item") + "/clusters/" + n; TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(0L)) { HttpURLConnection connection = null; try {/* w w w . java2 s . c om*/ connection = buildConnectionToReplica(replica, urlPath, "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: FastIDSet members = new FastIDSet(); consumeIDs(connection, members); return members; case HttpURLConnection.HTTP_NOT_IMPLEMENTED: throw new UnsupportedOperationException(); case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }