List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.
Click Source Link
From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java
@Override public void removeCurrency(String currencyCode) { String resource = String.format(baseUrl + CURRENCY, currencyCode); DeleteMethod method = createDeleteMethod(resource); try {//from w w w . j a va 2 s .c o m // Execute the method. int statusCode = getClient().executeMethod(method); if (statusCode == HttpStatus.SC_NOT_FOUND) { return; } assertResponseCodeOK(method, statusCode); } catch (Exception e) { throw new RuntimeException("Failed removing currency via url " + resource, e); } finally { method.releaseConnection(); } }
From source file:davmail.exchange.ews.EWSMethod.java
@Override public int getStatusCode() { if ("ErrorAccessDenied".equals(errorDetail)) { return HttpStatus.SC_FORBIDDEN; } else if ("ErrorItemNotFound".equals(errorDetail)) { return HttpStatus.SC_NOT_FOUND; } else {// w ww .j a v a 2 s . c o m return super.getStatusCode(); } }
From source file:edu.psu.iam.cpr.core.util.Utility.java
/** * This method is used to convert an CPR status code to an analogous HTTP status code. * * @param statusCode contains the CPR status code. * @return will return the HTTP status code. *//*from w w w . j a v a2 s .c om*/ public static int convertCprReturnToHttpStatus(final int statusCode) { final ReturnType returnType = ReturnType.get(statusCode); int httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; switch (returnType) { case SUCCESS: httpStatus = HttpStatus.SC_OK; break; case ADD_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case ALREADY_DELETED_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case RECORD_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case ARCHIVE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_SPECIFIED_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case TYPE_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case INVALID_PARAMETERS_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case YN_PARAMETERS_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case GENERAL_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case PARAMETER_LENGTH_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case MESSAGE_CREATION_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case MESSAGE_INITIALIZATION_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case MESSAGE_SEND_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_AUTHORIZED_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case PERSON_NOT_ACTIVE_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case PERSON_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case PSUID_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case SERVICE_AUTHENTICATION_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case SET_PRIMARY_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case UPDATE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case WEB_SERVICE_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case GI_FAILURE: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DB_CONNECTION_FAILURE: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case GENERAL_DATABASE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case UNARCHIVE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DATA_CHANGE_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case SECURITY_OPERATION_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case AFFILIATION_USE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case IAP_USE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case RECORD_ALREADY_EXISTS: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case EXACT_MATCH_EXCEPTION: httpStatus = HttpStatus.SC_MULTIPLE_CHOICES; break; case NEAR_MATCH_EXCEPTION: httpStatus = HttpStatus.SC_MULTIPLE_CHOICES; break; case MESSAGE_RECEIVE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DIRECTORY_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case JSON_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case JMS_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_IMPLEMENTED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; default: break; } return httpStatus; }
From source file:davmail.exchange.ews.EwsExchangeSession.java
/** * Get item content.//from w w w . j a v a 2 s.c om * * @param itemId EWS item id * @return item content as byte array * @throws IOException on error */ protected byte[] getContent(ItemId itemId) throws IOException { GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true); byte[] mimeContent = null; try { executeMethod(getItemMethod); mimeContent = getItemMethod.getMimeContent(); } catch (EWSException e) { LOGGER.warn("GetItem with MimeContent failed: " + e.getMessage()); } if (getItemMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new HttpNotFoundException("Item " + itemId + " not found"); } if (mimeContent == null) { LOGGER.warn("MimeContent not available, trying to rebuild from properties"); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, false); getItemMethod.addAdditionalProperty(Field.get("contentclass")); getItemMethod.addAdditionalProperty(Field.get("message-id")); getItemMethod.addAdditionalProperty(Field.get("from")); getItemMethod.addAdditionalProperty(Field.get("to")); getItemMethod.addAdditionalProperty(Field.get("cc")); getItemMethod.addAdditionalProperty(Field.get("subject")); getItemMethod.addAdditionalProperty(Field.get("date")); getItemMethod.addAdditionalProperty(Field.get("body")); executeMethod(getItemMethod); EWSMethod.Item item = getItemMethod.getResponseItem(); MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("Content-class", item.get(Field.get("contentclass").getResponseName())); mimeMessage.setSentDate(parseDateFromExchange(item.get(Field.get("date").getResponseName()))); mimeMessage.addHeader("From", item.get(Field.get("from").getResponseName())); mimeMessage.addHeader("To", item.get(Field.get("to").getResponseName())); mimeMessage.addHeader("Cc", item.get(Field.get("cc").getResponseName())); mimeMessage.setSubject(item.get(Field.get("subject").getResponseName())); String propertyValue = item.get(Field.get("body").getResponseName()); if (propertyValue == null) { propertyValue = ""; } mimeMessage.setContent(propertyValue, "text/html; charset=UTF-8"); mimeMessage.writeTo(baos); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Rebuilt message content: " + new String(baos.toByteArray())); } mimeContent = baos.toByteArray(); } catch (IOException e2) { LOGGER.warn(e2); } catch (MessagingException e2) { LOGGER.warn(e2); } if (mimeContent == null) { throw new IOException("GetItem returned null MimeContent"); } } return mimeContent; }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Execute Get method, do not follow redirects. * * @param httpClient Http client instance * @param method Http method/* w ww . j a v a 2s .c om*/ * @param followRedirects Follow redirects flag * @throws IOException on error */ public static void executeGetMethod(HttpClient httpClient, GetMethod method, boolean followRedirects) throws IOException { // do not follow redirects in expired sessions method.setFollowRedirects(followRedirects); int status = httpClient.executeMethod(method); if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) && acceptsNTLMOnly(method) && !hasNTLM(httpClient)) { resetMethod(method); LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM"); addNTLM(httpClient); status = httpClient.executeMethod(method); } if (status != HttpStatus.SC_OK && (followRedirects || !isRedirect(status))) { LOGGER.warn("GET failed with status " + status + " at " + method.getURI()); if (status != HttpStatus.SC_NOT_FOUND && status != HttpStatus.SC_FORBIDDEN) { LOGGER.warn(method.getResponseBodyAsString()); } throw DavGatewayHttpClientFacade.buildHttpException(method); } // check for expired session if (followRedirects) { String queryString = method.getQueryString(); checkExpiredSession(queryString); } }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Build Http Exception from methode status * * @param method Http Method// w w w .j a va2 s. co m * @return Http Exception */ public static HttpException buildHttpException(HttpMethod method) { int status = method.getStatusCode(); StringBuilder message = new StringBuilder(); message.append(status).append(' ').append(method.getStatusText()); try { message.append(" at ").append(method.getURI().getURI()); if (method instanceof CopyMethod || method instanceof MoveMethod) { message.append(" to ").append(method.getRequestHeader("Destination")); } } catch (URIException e) { message.append(method.getPath()); } // 440 means forbidden on Exchange if (status == 440) { return new LoginTimeoutException(message.toString()); } else if (status == HttpStatus.SC_FORBIDDEN) { return new HttpForbiddenException(message.toString()); } else if (status == HttpStatus.SC_NOT_FOUND) { return new HttpNotFoundException(message.toString()); } else if (status == HttpStatus.SC_PRECONDITION_FAILED) { return new HttpPreconditionFailedException(message.toString()); } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { return new HttpServerErrorException(message.toString()); } else { return new HttpException(message.toString()); } }
From source file:edu.ku.brc.util.WebStoreAttachmentMgr.java
/** * @param fileName/*from ww w. j ava 2s . com*/ * @param isThumb * @return */ private boolean deleteFileFromWeb(final String fileName, final boolean isThumb) { try { //String targetURL = String.format("http://localhost/cgi-bin/filedelete.php?filename=%s;disp=%s", targetName, discipline.getName()); //String targetURL = subAllExtraData(delURLStr, fileName, isThumb, null, null); fillValuesArray(); PostMethod postMethod = new PostMethod(delURLStr); postMethod.addParameter("filename", fileName); postMethod.addParameter("token", generateToken(fileName)); postMethod.addParameter("coll", values[0]); postMethod.addParameter("disp", values[1]); postMethod.addParameter("div", values[2]); postMethod.addParameter("inst", values[3]); //log.debug("Deleting " + fileName + " from " + targetURL ); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(postMethod); updateServerTimeDelta(postMethod); //log.debug(getMethod.getResponseBodyAsString()); return status == HttpStatus.SC_OK || status == HttpStatus.SC_NOT_FOUND; } catch (Exception ex) { //log.debug("Error: " + ex.getMessage()); ex.printStackTrace(); } return false; }
From source file:com.thoughtworks.go.server.service.ValueStreamMapServiceTest.java
@Test public void shouldPopulateErrorCorrectly_VSMForMaterial() throws Exception { /*// www .j av a 2s .c o m git --> p1 */ String groupName = "g1"; String pipelineName = "p1"; String userName = "looser"; GitMaterial gitMaterial = new GitMaterial("git"); MaterialConfig gitConfig = gitMaterial.config(); GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight"); PipelineConfigs groups = new BasicPipelineConfigs(groupName, new Authorization(), PipelineConfigMother.pipelineConfig(pipelineName, new MaterialConfigs(gitConfig))); CruiseConfig cruiseConfig = new BasicCruiseConfig(groups); when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig); when(goConfigService.groups()).thenReturn(new PipelineGroups(groups)); when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(false); // unknown material valueStreamMapService.getValueStreamMap("unknown-material", "r1", new Username(new CaseInsensitiveString(userName)), result); assertResult(HttpStatus.SC_NOT_FOUND, "MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND"); // unauthorized valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result); assertResult(HttpStatus.SC_UNAUTHORIZED, "MATERIAL_CANNOT_VIEW"); // material config exists but no material instance when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(true); when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(null); valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result); assertResult(HttpStatus.SC_NOT_FOUND, "MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND"); // modification (revision) doesn't exist when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(gitMaterialInstance); when(materialRepository.findModificationWithRevision(gitMaterial, "r1")).thenReturn(null); valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result); assertResult(HttpStatus.SC_NOT_FOUND, "MATERIAL_MODIFICATION_NOT_FOUND"); // internal error when(goConfigService.groups()).thenThrow(new RuntimeException("just for fun")); valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result); assertResult(HttpStatus.SC_INTERNAL_SERVER_ERROR, "VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL"); }
From source file:com.zimbra.qa.unittest.TestCalDav.java
/** Mostly checking that if attendees cease to exist (even via DLs) then modification and cancel iTip * messages still work to the remaining attendees. *///from w ww. ja v a2s. c o m @Test public void testCreateModifyDeleteAttendeeModifyAndCancel() throws ServiceException, IOException { Account dav1 = users[1].create(); Account dav2 = users[2].create(); Account dav3 = users[3].create(); Account dav4 = users[4].create(); DistributionList dl = TestUtil.createDistributionList(DL1); String[] members = { dav4.getName() }; prov.addMembers(dl, members); List<MailTarget> attendees = Lists.newArrayList(); attendees.add(dav1); attendees.add(dav2); attendees.add(dav3); attendees.add(dl); ZVCalendar vCal = simpleMeeting(dav1, attendees, "1", 8); ZProperty uidProp = vCal.getComponent(ICalTok.VEVENT).getProperty(ICalTok.UID); String uid = uidProp.getValue(); String davBaseName = uid + ".ics"; String url = String.format("%s%s", getFolderUrl(dav1, "Calendar"), davBaseName); doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED); String inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT); // attendee via DL inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav4, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav4, HttpStatus.SC_NO_CONTENT); vCal = simpleMeeting(dav1, attendees, uid, "2", 9); doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED); inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT); // attendee via DL inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav4, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav4, HttpStatus.SC_NO_CONTENT); // Test that iTip handling still happens when some of the attendees no longer exist. users[3].cleanup(); users[4].cleanup(); // attendee via DL vCal = simpleMeeting(dav1, attendees, uid, "3", 10); doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED); inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT); String dav2Url = String.format("%s%s", getFolderUrl(dav2, "Calendar"), davBaseName); doGetMethod(dav2Url, dav2, HttpStatus.SC_OK); // Cancel meeting by deleting it doDeleteMethod(url, dav1, HttpStatus.SC_NO_CONTENT); inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid); assertTrue("Found meeting request for newly created item", inboxhref.contains(uid)); doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT); // The associated calendar item should have been deleted as a result of the Cancel doGetMethod(dav2Url, dav2, HttpStatus.SC_NOT_FOUND); }
From source file:com.zimbra.cs.service.UserServlet.java
private static Pair<Header[], HttpMethod> doHttpOp(ZAuthToken authToken, HttpMethod method) throws ServiceException { // create an HTTP client with the same cookies String url = ""; String hostname = ""; try {//from w ww.j a v a2 s . c o m url = method.getURI().toString(); hostname = method.getURI().getHost(); } catch (IOException e) { log.warn("can't parse target URI", e); } HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); Map<String, String> cookieMap = authToken.cookieMap(false); if (cookieMap != null) { HttpState state = new HttpState(); for (Map.Entry<String, String> ck : cookieMap.entrySet()) { state.addCookie(new org.apache.commons.httpclient.Cookie(hostname, ck.getKey(), ck.getValue(), "/", null, false)); } client.setState(state); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); } if (method instanceof PutMethod) { long contentLength = ((PutMethod) method).getRequestEntity().getContentLength(); if (contentLength > 0) { int timeEstimate = Math.max(10000, (int) (contentLength / 100)); // 100kbps in millis // cannot set connection time using our ZimbrahttpConnectionManager, // see comments in ZimbrahttpConnectionManager. // actually, length of the content to Put should not be a factor for // establishing a connection, only read time out matter, which we set // client.getHttpConnectionManager().getParams().setConnectionTimeout(timeEstimate); method.getParams().setSoTimeout(timeEstimate); } } try { int statusCode = HttpClientUtil.executeMethod(client, method); if (statusCode == HttpStatus.SC_NOT_FOUND || statusCode == HttpStatus.SC_FORBIDDEN) throw MailServiceException.NO_SUCH_ITEM(-1); else if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_NO_CONTENT) throw ServiceException.RESOURCE_UNREACHABLE(method.getStatusText(), null, new ServiceException.InternalArgument(HTTP_URL, url, ServiceException.Argument.Type.STR), new ServiceException.InternalArgument(HTTP_STATUS_CODE, statusCode, ServiceException.Argument.Type.NUM)); List<Header> headers = new ArrayList<Header>(Arrays.asList(method.getResponseHeaders())); headers.add(new Header("X-Zimbra-Http-Status", "" + statusCode)); return new Pair<Header[], HttpMethod>(headers.toArray(new Header[0]), method); } catch (HttpException e) { throw ServiceException.RESOURCE_UNREACHABLE("HttpException while fetching " + url, e); } catch (IOException e) { throw ServiceException.RESOURCE_UNREACHABLE("IOException while fetching " + url, e); } }