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:net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilterTest.java
/** * When the servlet container generates a 404 page not found, we want to pass * it through without caching and without adding anything to it. * <p/>//from w w w . j av a 2s . c o m * Manual Test: wget -d --server-response --header='Accept-Encoding: gzip' http://localhost:9090/non_ok/PageNotFound.jsp */ @Test public void testNotFound() throws Exception { String url = buildUrl("/non_ok/PageNotFound.jsp"); HttpClient httpClient = new HttpClient(); HttpMethod httpMethod = new GetMethod(url); httpMethod.addRequestHeader("If-modified-Since", "Fri, 13 May 3006 23:54:18 GMT"); httpMethod.addRequestHeader("Accept-Encoding", "gzip"); int responseCode = httpClient.executeMethod(httpMethod); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, responseCode); String responseBody = httpMethod.getResponseBodyAsString(); assertNotNull(responseBody); assertNull(httpMethod.getResponseHeader("Content-Encoding")); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get all the commands this application is associated with. * * @param id The id of the application to get the commands for. Not * NULL/empty/blank.//from ww w . java 2 s . c o m * @param statuses The various statuses of the commands to retrieve * @return The set of commands. * @throws GenieException For any error */ @GET @Path("/{id}/commands") @ApiOperation(value = "Get the commands this application is associated with", notes = "Get the commands which this application supports.", response = Command.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 List<Command> getCommandsForApplication( @ApiParam(value = "Id of the application to get the commands for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses) throws GenieException { LOG.info("Called with id " + id); 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.applicationConfigService.getCommandsForApplication(id, enumStatuses); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Remove an tag from a given command./*from w w w. j a va 2s . co m*/ * * @param id The id of the command to delete the tag from. Not * null/empty/blank. * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the command. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a command", notes = "Remove the given tag from the command with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForCommand( @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.commandConfigService.removeTagForCommand(id, tag); }
From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java
/** * Delete an action data with specified ID * @param appId applicationId// ww w .j a v a2 s . c om * @param actionId actionId * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{actionId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Action is deleted"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Action not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "", notes = "delete an action") public HttpResponse deleteAction(@PathParam("appId") String appId, @PathParam("actionId") String actionId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/actions/" + appId + "/" + actionId); long randomLong = new Random().nextLong(); //To be able to match JSONObject objResponse = new JSONObject(); Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } try { conn = dbm.getConnection(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!actionAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete action. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot delete action. Cannot check whether application ID exist or not. Database error. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } if (!actionAccess.isActionIdExist(conn, appId, actionId)) { objResponse.put("message", "Cannot delete action. Failed to delete the action. Action ID is not exist!"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } actionAccess.deleteAction(conn, appId, actionId); objResponse.put("message", "Action deleted"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_21, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_31, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot delete action. Database error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:net.myrrix.client.ClientRecommender.java
/** * @param userIDs users for which recommendations are to be computed * @param howMany desired number of recommendations * @param considerKnownItems if true, items that the user is already associated to are candidates * for recommendation. Normally this is {@code false}. * @param rescorerParams optional parameters to send to the server's {@code RescorerProvider} * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to least * @throws NoSuchUserException if <em>none</em> of {@code userIDs} are known in the model. Otherwise unknown * user IDs are ignored./* w w w .j av a2 s.co m*/ * @throws NotReadyException if the recommender has no model available yet * @throws TasteException if another error occurs * @throws UnsupportedOperationException if rescorer is not null */ public List<RecommendedItem> recommendToMany(long[] userIDs, int howMany, boolean considerKnownItems, String[] rescorerParams) throws TasteException { StringBuilder urlPath = new StringBuilder(32); urlPath.append("/recommendToMany"); for (long userID : userIDs) { urlPath.append('/').append(userID); } appendCommonQueryParams(howMany, considerKnownItems, rescorerParams, urlPath); // Note that this assumes that all user IDs are on the same partition. It will fail at request // time if not since the partition of the first user doesn't contain the others. TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(userIDs[0])) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath.toString(), "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: return consumeItems(connection); case HttpURLConnection.HTTP_NOT_FOUND: throw new NoSuchUserException(Arrays.toString(userIDs)); 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:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Remove an tag from a given cluster.//w w w . j a v a2 s. c om * * @param id The id of the cluster to delete the tag from. Not * null/empty/blank. * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the cluster. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a cluster", notes = "Remove the given tag from the cluster with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForCluster( @ApiParam(value = "Id of the cluster to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.clusterConfigService.removeTagForCluster(id, tag); }
From source file:i5.las2peer.services.gamificationLevelService.GamificationLevelService.java
/** * Delete a level data with specified ID * @param appId applicationId/*w ww . j a va 2 s . c o m*/ * @param levelNum levelNum * @return HttpResponse with the returnString */ @DELETE @Path("/{appId}/{levelNum}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Level Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Level not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteLevel", notes = "delete a level") public HttpResponse deleteLevel( @ApiParam(value = "Application ID to delete a level", required = true) @PathParam("appId") String appId, @ApiParam(value = "Level number that will be deleted", required = true) @PathParam("levelNum") int levelNum) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/levels/" + appId + "/" + levelNum); long randomLong = new Random().nextLong(); //To be able to match JSONObject objResponse = new JSONObject(); Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } try { conn = dbm.getConnection(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete level. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot delete level. Cannot check whether application ID exist or not. Database error. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } if (!levelAccess.isLevelNumExist(conn, appId, levelNum)) { objResponse.put("message", "Cannot delete level. Level not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } levelAccess.deleteLevel(conn, appId, levelNum); objResponse.put("message", "Level Deleted"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_21, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_31, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot delete level. Cannot delete level. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientRetrieveFileTransfer.java
protected void openStreams() throws IncomingFileTransferException { Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "openStreams"); //$NON-NLS-1$ final String urlString = getRemoteFileURL().toString(); this.doneFired = false; int code = -1; try {/* ww w .j a va2 s .co m*/ httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getSocketReadTimeout()); int connectTimeout = getConnectTimeout(); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); setupAuthentication(urlString); getMethod = new HttpGet(urlString); // Define a CredentialsProvider - found that possibility while debugging in org.apache.commons.httpclient.HttpMethodDirector.processProxyAuthChallenge(HttpMethod) // Seems to be another way to select the credentials. setRequestHeaderValues(); Trace.trace(Activator.PLUGIN_ID, "retrieve=" + urlString); //$NON-NLS-1$ // Set request header for possible gzip encoding, but only if // 1) The file range specification is null (we want the whole file) // 2) The target remote file does *not* end in .gz (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280205) if (getFileRangeSpecification() == null && !targetHasGzSuffix(super.getRemoteFileName())) { Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding: gzip,deflate added to request header"); //$NON-NLS-1$ // Add the interceptors to provide the gzip httpClient.addRequestInterceptor(new RequestAcceptEncoding()); httpClient.addResponseInterceptor(new ResponseContentEncoding()); } else { Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding NOT added to header"); //$NON-NLS-1$ } fireConnectStartEvent(); if (checkAndHandleDone()) { return; } connectingSockets.clear(); // Actually execute get and get response code (since redirect is set to true, then // redirect response code handled internally if (connectJob == null) { performConnect(new NullProgressMonitor()); } else { connectJob.schedule(); connectJob.join(); connectJob = null; } if (checkAndHandleDone()) { return; } code = responseCode; responseHeaders = getResponseHeaders(); Trace.trace(Activator.PLUGIN_ID, "retrieve resp=" + code); //$NON-NLS-1$ // Check for NTLM proxy in response headers // This check is to deal with bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=252002 boolean ntlmProxyFound = NTLMProxyDetector.detectNTLMProxy(httpContext); if (ntlmProxyFound && !hasForceNTLMProxyOption()) throw new IncomingFileTransferException( "HttpClient Provider is not configured to support NTLM proxy authentication.", //$NON-NLS-1$ HttpClientOptions.NTLM_PROXY_RESPONSE_CODE); if (NTLMProxyDetector.detectSPNEGOProxy(httpContext)) throw new BrowseFileTransferException( "HttpClient Provider does not support the use of SPNEGO proxy authentication."); //$NON-NLS-1$ if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) { getResponseHeaderValues(); setInputStream(httpResponse.getEntity().getContent()); fireReceiveStartEvent(); } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code); } else { Trace.trace(Activator.PLUGIN_ID, EntityUtils.toString(httpResponse.getEntity())); // EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code); } } catch (final Exception e) { Trace.throwing(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_THROWING, this.getClass(), "openStreams", //$NON-NLS-1$ e); if (code == -1) { if (!isDone()) { setDoneException(e); } fireTransferReceiveDoneEvent(); } else { IncomingFileTransferException ex = (IncomingFileTransferException) ((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code)); throw ex; } } Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreams"); //$NON-NLS-1$ }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Remove an tag from a given application. * * @param id The id of the application to delete the tag from. Not * null/empty/blank./*from www .j a v a2s .c o m*/ * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the application. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a application", notes = "Remove the given tag from the application with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForApplication( @ApiParam(value = "Id of the application to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.applicationConfigService.removeTagForApplication(id, tag); }
From source file:ORG.oclc.os.SRW.SRWServlet.java
/** * generate the error response to indicate that there is apparently no endpoint there * @param request the request that didnt have an edpoint * @param response response we are generating *//*w w w . j a v a 2s . com*/ protected void reportCantGetAxisService(HttpServletRequest request, HttpServletResponse response) throws IOException { // no such service.... response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println("<h2>" + Messages.getMessage("error00") + "</h2>"); writer.println("<p>" + Messages.getMessage("noService06") + "</p>"); writer.close(); }