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.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testDeleteInProject() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); /* assume there are no projects in the workspace */ WebRequest request = getGetRequest(workspaceLocation.toString()); WebResponse response = webConversation.getResponse(request); JSONObject workspace = new JSONObject(response.getText()); JSONArray projects = workspace.getJSONArray(ProtocolConstants.KEY_CHILDREN); Assume.assumeTrue(projects.length() == 0); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); JSONObject clone = clone(workspaceId, project); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION); // make sure there's one project in the workspace request = getGetRequest(workspaceLocation.toString()); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); workspace = new JSONObject(response.getText()); projects = workspace.getJSONArray(ProtocolConstants.KEY_CHILDREN); assertEquals(1, projects.length());//from ww w . j a v a 2s. c o m // delete clone request = getDeleteCloneRequest(cloneLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // the clone is gone request = getGetRequest(cloneLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); // so it's the folder (top-level) request = getGetRequest(contentLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); // make sure the project doesn't exist request = getGetRequest(projectLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); }
From source file:i5.las2peer.services.gamificationAchievementService.GamificationAchievementService.java
/** * Delete an achievement data with specified ID * @param appId applicationId/*from w ww. j a v a 2 s.c om*/ * @param achievementId achievementId * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{achievementId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Achievement Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Achievements not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteAchievement", notes = "Delete an achievement") public HttpResponse deleteAchievement(@PathParam("appId") String appId, @PathParam("achievementId") String achievementId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/achievements/" + appId + "/" + achievementId); long randomLong = new Random().nextLong(); //To be able to match Connection conn = null; JSONObject objResponse = new JSONObject(); 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 (!achievementAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete achievement. 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 achievement. 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 (!achievementAccess.isAchievementIdExist(conn, appId, achievementId)) { objResponse.put("message", "Cannot delete achievement. Achievement not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } achievementAccess.deleteAchievement(conn, appId, achievementId); objResponse.put("message", "Cannot delete achievement. Achievement 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 achievement. Cannot delete Achievement. " + 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:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java
/** * Delete a quest data with specified ID * @param appId applicationId/* www. j a v a 2s . c o m*/ * @param questId questId * @return HttpResponse with the returnString */ @DELETE @Path("/{appId}/{questId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "quest Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "quest not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteQuest", notes = "delete a quest") public HttpResponse deleteQuest(@PathParam("appId") String appId, @PathParam("questId") String questId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE" + "gamification/quests/" + appId + "/" + questId); 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 (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete quest. 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 quest. 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 (!questAccess.isQuestIdExist(conn, appId, questId)) { objResponse.put("message", "Cannot delete quest. Failed to delete the quest. Quest ID is not exist!"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } questAccess.deleteQuest(conn, appId, questId); objResponse.put("message", "quest 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 quest. 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:ORG.oclc.os.SRW.SRWServlet.java
/** * probe for a JWS page and report 'no service' if one is not found there * @param request the request that didnt have an edpoint * @param response response we are generating *//*from w ww.jav a 2 s. c o m*/ protected void reportCantGetJWSService(HttpServletRequest request, HttpServletResponse response) throws IOException { //first look to see if there is a service String realpath = getServletConfig().getServletContext().getRealPath(request.getServletPath()); boolean foundJWSFile = (new File(realpath).exists()) && (realpath.endsWith(Constants.JWS_DEFAULT_FILE_EXTENSION)); response.setContentType("text/html"); PrintWriter writer = response.getWriter(); if (foundJWSFile) { response.setStatus(HttpURLConnection.HTTP_OK); writer.println(Messages.getMessage("foundJWS00") + "<p>"); String url = request.getRequestURI(); String urltext = Messages.getMessage("foundJWS01"); writer.println("<a href='" + url + "?wsdl'>" + urltext + "</a>"); } else { response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); writer.println(Messages.getMessage("noService06")); } writer.close(); }
From source file:org.eclipse.ecf.provider.filetransfer.httpclient.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 {/*from ww w .ja v a2 s. c om*/ initHttpClientConnectionManager(); setupAuthentication(urlString); CredentialsProvider credProvider = new ECFCredentialsProvider(); setupHostAndPort(credProvider, urlString); getMethod = new GzipGetMethod(hostConfigHelper.getTargetRelativePath()); getMethod.addRequestHeader("Connection", "Keep-Alive"); //$NON-NLS-1$ //$NON-NLS-2$ getMethod.setFollowRedirects(true); // 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. getMethod.getParams().setParameter(CredentialsProvider.PROVIDER, credProvider); 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 added to request header"); //$NON-NLS-1$ getMethod.setRequestHeader(GzipGetMethod.ACCEPT_ENCODING, GzipGetMethod.CONTENT_ENCODING_ACCEPTED); } 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(getMethod); 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 (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) { getResponseHeaderValues(); setInputStream(getMethod.getResponseBodyAsUnzippedStream()); fireReceiveStartEvent(); } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { getMethod.releaseConnection(); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { getMethod.releaseConnection(); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { getMethod.releaseConnection(); throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { getMethod.releaseConnection(); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code); } else { getMethod.releaseConnection(); 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:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testDeleteInFolder() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); IPath clonePath = getClonePath(workspaceId, project).append("clone").makeAbsolute(); JSONObject clone = clone(clonePath); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION); // delete clone WebRequest request = getDeleteCloneRequest(cloneLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // the clone is gone request = getGetRequest(cloneLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); // so is the folder request = getGetRequest(contentLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); // but the project is still there request = getGetRequest(projectLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testDeleteInWorkspace() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); JSONObject clone = clone(workspaceId, project); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); Repository repository = getRepositoryForContentLocation(contentLocation); assertNotNull(repository);/* w w w . j a va 2s . c o m*/ // delete folder with cloned repository in it WebRequest request = getDeleteFilesRequest(contentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // the clone is gone request = getGetRequest(cloneLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); assertFalse(repository.getDirectory().exists()); }
From source file:org.openrdf.http.client.HTTPClient.java
public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException { checkRepositoryURL();/*from w ww. j a v a 2 s. co m*/ HttpMethod method = new GetMethod(Protocol.getNamespacePrefixLocation(repositoryURL, prefix)); setDoAuthentication(method); try { int httpCode = httpClient.executeMethod(method); if (httpCode == HttpURLConnection.HTTP_OK) { return method.getResponseBodyAsString(); } else if (httpCode == HttpURLConnection.HTTP_NOT_FOUND) { return null; } else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new UnauthorizedException(); } else { ErrorInfo errInfo = getErrorInfo(method); throw new RepositoryException("Failed to get namespace: " + errInfo + " (" + httpCode + ")"); } } finally { releaseConnection(method); } }
From source file:net.myrrix.client.ClientRecommender.java
private List<RecommendedItem> anonymousOrSimilar(long[] itemIDs, float[] values, int howMany, String path, String[] rescorerParams, Long contextUserID) throws TasteException { Preconditions.checkArgument(values == null || values.length == itemIDs.length, "Number of values doesn't match number of items"); StringBuilder urlPath = new StringBuilder(); urlPath.append(path);//from w ww . ja v a 2 s. co m for (int i = 0; i < itemIDs.length; i++) { urlPath.append('/').append(itemIDs[i]); if (values != null) { urlPath.append('=').append(values[i]); } } appendCommonQueryParams(howMany, false, rescorerParams, urlPath); // Requests are typically partitioned by user, but this request does not directly depend on a user. // If a user ID is supplied anyway, use it for partitioning since it will follow routing for other // requests related to that user. Otherwise just partition on (first0 item ID, which is at least // deterministic. long idToPartitionOn = contextUserID == null ? itemIDs[0] : contextUserID; TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(idToPartitionOn)) { 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 NoSuchItemException(Arrays.toString(itemIDs)); 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:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testGetNonExistingClone() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = getWorkspaceId(workspaceLocation); JSONArray clonesArray = listClones(workspaceId, null); String dummyId = "dummyId"; ensureCloneIdDoesntExist(clonesArray, dummyId); String requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + "/workspace/" + dummyId; WebRequest request = getGetRequest(requestURI); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + "/file/" + dummyId; request = getGetRequest(requestURI); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); }