List of usage examples for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS
int SC_MULTI_STATUS
To view the source code for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS.
Click Source Link
From source file:davmail.caldav.TestCaldav.java
public void testPropfindCalendar() throws IOException { Settings.setLoggingLevel("httpclient.wire", Level.DEBUG); PropFindMethod method = new PropFindMethod("/users/" + session.getEmail() + "/calendar/", null, 1); httpClient.executeMethod(method);//w w w . j a v a 2 s . c om assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); }
From source file:com.owncloud.android.lib.resources.files.MoveRemoteFileOperation.java
/** * Analyzes a multistatus response from the OC server to generate an appropriate result. * * In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some * children are moved, some other aren't. * * According to the WebDAV specification, a multistatus response SHOULD NOT include partial * successes (201, 204) nor for descendants of already failed children (424) in the response * entity. But SHOULD NOT != MUST NOT, so take carefully. * * @param move Move operation just finished with a multistatus response * @return A result for the {@link MoveRemoteFileOperation} caller * * @throws IOException If the response body could not be parsed * @throws DavException If the status code is other than MultiStatus or if obtaining * the response XML document fails *//*from www. j a v a 2 s . c o m*/ private RemoteOperationResult processPartialError(MoveMethod move) throws IOException, DavException { // Adding a list of failed descendants to the result could be interesting; or maybe not. // For the moment, let's take the easy way. /// check that some error really occurred MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); Status[] status = null; boolean failFound = false; for (int i = 0; i < responses.length && !failFound; i++) { status = responses[i].getStatus(); failFound = (status != null && status.length > 0 && status[0].getStatusCode() > 299); } RemoteOperationResult result; if (failFound) { result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); } else { result = new RemoteOperationResult(true, HttpStatus.SC_MULTI_STATUS, move.getResponseHeaders()); } return result; }
From source file:com.cerema.cloud2.lib.resources.files.MoveRemoteFileOperation.java
/** * Analyzes a multistatus response from the OC server to generate an appropriate result. * /*from ww w. j ava 2 s .co m*/ * In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some * children are moved, some other aren't. * * According to the WebDAV specification, a multistatus response SHOULD NOT include partial * successes (201, 204) nor for descendants of already failed children (424) in the response * entity. But SHOULD NOT != MUST NOT, so take carefully. * * @param move Move operation just finished with a multistatus response * @return A result for the {@link MoveRemoteFileOperation} caller * * @throws IOException If the response body could not be parsed * @throws DavException If the status code is other than MultiStatus or if obtaining * the response XML document fails */ private RemoteOperationResult processPartialError(MoveMethod move) throws IOException, DavException { // Adding a list of failed descendants to the result could be interesting; or maybe not. // For the moment, let's take the easy way. /// check that some error really occurred MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); Status[] status = null; boolean failFound = false; for (int i = 0; i < responses.length && !failFound; i++) { status = responses[i].getStatus(); failFound = (status != null && status.length > 0 && status[0].getStatusCode() > 299); } RemoteOperationResult result; if (failFound) { result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); } else { result = new RemoteOperationResult(true, HttpStatus.SC_MULTI_STATUS, move.getResponseHeaders()); } return result; }
From source file:com.cerema.cloud2.lib.resources.files.CopyRemoteFileOperation.java
/** * Analyzes a multistatus response from the OC server to generate an appropriate result. * <p/>/*from w w w .ja v a2s.c o m*/ * In WebDAV, a COPY request on collections (folders) can be PARTIALLY successful: some * children are copied, some other aren't. * <p/> * According to the WebDAV specification, a multistatus response SHOULD NOT include partial * successes (201, 204) nor for descendants of already failed children (424) in the response * entity. But SHOULD NOT != MUST NOT, so take carefully. * * @param copyMethod Copy operation just finished with a multistatus response * @return A result for the {@link com.cerema.cloud2.lib.resources.files.CopyRemoteFileOperation} caller * @throws java.io.IOException If the response body could not be parsed * @throws org.apache.jackrabbit.webdav.DavException If the status code is other than MultiStatus or if obtaining * the response XML document fails */ private RemoteOperationResult processPartialError(CopyMethod copyMethod) throws IOException, DavException { // Adding a list of failed descendants to the result could be interesting; or maybe not. // For the moment, let's take the easy way. /// check that some error really occurred MultiStatusResponse[] responses = copyMethod.getResponseBodyAsMultiStatus().getResponses(); Status[] status; boolean failFound = false; for (int i = 0; i < responses.length && !failFound; i++) { status = responses[i].getStatus(); failFound = (status != null && status.length > 0 && status[0].getStatusCode() > 299); } RemoteOperationResult result; if (failFound) { result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); } else { result = new RemoteOperationResult(true, HttpStatus.SC_MULTI_STATUS, copyMethod.getResponseHeaders()); } return result; }
From source file:davmail.caldav.TestCaldav.java
public void testReportCalendar() throws IOException, DavException { SimpleDateFormat formatter = ExchangeSession.getZuluDateFormat(); Calendar cal = Calendar.getInstance(); Date end = cal.getTime();/* ww w . j a v a 2 s . c om*/ cal.add(Calendar.MONTH, -1); Date start = cal.getTime(); StringBuilder buffer = new StringBuilder(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">"); buffer.append("<D:prop>"); buffer.append("<C:calendar-data/>"); buffer.append("</D:prop>"); buffer.append("<C:comp-filter name=\"VCALENDAR\">"); buffer.append("<C:comp-filter name=\"VEVENT\">"); buffer.append("<C:time-range start=\"").append(formatter.format(start)).append("\" end=\"") .append(formatter.format(end)).append("\"/>"); //buffer.append("<C:time-range start=\"").append(formatter.format(start)).append("\"/>"); buffer.append("</C:comp-filter>"); buffer.append("</C:comp-filter>"); buffer.append("<C:filter>"); buffer.append("</C:filter>"); buffer.append("</C:calendar-query>"); SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString()); httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); ExchangeSession.Condition dateCondition = session.and( session.gt("dtstart", session.formatSearchDate(start)), session.lt("dtend", session.formatSearchDate(end))); List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/", session.or(session.isEqualTo("instancetype", 1), session.and(session.isEqualTo("instancetype", 0), dateCondition)) ); assertEquals(events.size(), responses.length); }
From source file:davmail.caldav.TestCaldav.java
public void testReportInbox() throws IOException, DavException { StringBuilder buffer = new StringBuilder(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">"); buffer.append("<D:prop>"); buffer.append("<C:calendar-data/>"); buffer.append("</D:prop>"); buffer.append("<C:filter>"); buffer.append("</C:filter>"); buffer.append("</C:calendar-query>"); SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/inbox/", buffer.toString());/*from w w w.ja va2 s. co m*/ httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); /*List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/", session.or(session.isEqualTo("instancetype", 1), session.and(session.isEqualTo("instancetype", 0), dateCondition)) );*/ //assertEquals(events.size(), responses.length); }
From source file:davmail.caldav.TestCaldav.java
public void testReportTasks() throws IOException, DavException { StringBuilder buffer = new StringBuilder(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">"); buffer.append("<D:prop>"); buffer.append("<C:calendar-data/>"); buffer.append("</D:prop>"); buffer.append("<C:comp-filter name=\"VCALENDAR\">"); buffer.append("<C:comp-filter name=\"VTODO\"/>"); buffer.append("</C:comp-filter>"); buffer.append("<C:filter>"); buffer.append("</C:filter>"); buffer.append("</C:calendar-query>"); SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString());/*from w w w . ja v a2 s . co m*/ httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); }
From source file:com.buzzdavidson.spork.client.OWAClient.java
/** * Retrieve list of messages via OWA/WebDAV * * @param filter type of list to retrieve (new or all messages) * @return list of mime messages (never null) *//*ww w . j a va 2 s .co m*/ public List<MimeMessage> fetchMail(OWAMessageFilter filter) { List<MimeMessage> retval = new ArrayList<MimeMessage>(); try { WebDavMethod search = new WebDavMethod(inboxAddress, OWA_METHOD_SEARCH, OWA_HEADERS_BRIEF); String msg = ""; if (OWAMessageFilter.ALL_MESSAGES.equals(filter)) { msg = OWA_QUERY_GET_LIST_MAIL_MSG_ALL; } else { msg = OWA_QUERY_GET_LIST_MAIL_MSG; } logger.info(String.format("Requesting %s mail messages", OWAMessageFilter.ALL_MESSAGES.equals(filter) ? "all" : "new")); search.setRequestEntity(new StringRequestEntity(msg, null, null)); int status = client.executeMethod(search); if (logger.isDebugEnabled()) { logger.info("Message request returned status code [" + status + "]"); } if (status == HttpStatus.SC_MULTI_STATUS) { Document doc = XmlUtils.readResponseDocument(search); Node email = XmlUtils.getChild(doc, OWA_FILTER_FIRST_MESSAGE_PATH); int msgCount; for (msgCount = 0; email != null; email = email.getNextSibling()) { msgCount++; if (msgCount > itemFetchLimit) { break; } else { String nodeName = email.getNodeName(); if (nodeName.endsWith(OWA_MSG_RESPONSE_SUFFIX)) { MimeMessage newMessage = OWAUtils.toMimeMessage(email); if (newMessage != null) { String messageUrl = OWAUtils.getMessageURL(email); populateMessage(newMessage, messageUrl); if (markReadAfterFetch) { markMessageRead(messageUrl); } retval.add(newMessage); } } } } } return retval; } catch (HttpException ex) { logger.error("Received HttpException fetching mail", ex); } catch (UnsupportedEncodingException ex) { logger.error("Received UnsupportedEncodingException fetching mail", ex); } catch (IOException ex) { logger.error("Received IOException fetching mail", ex); } return retval; }
From source file:davmail.caldav.TestCaldav.java
public void testReportEventsOnly() throws IOException, DavException { StringBuilder buffer = new StringBuilder(); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">"); buffer.append("<D:prop>"); buffer.append("<C:calendar-data/>"); buffer.append("</D:prop>"); buffer.append("<C:comp-filter name=\"VCALENDAR\">"); buffer.append("<C:comp-filter name=\"VEVENT\"/>"); buffer.append("</C:comp-filter>"); buffer.append("<C:filter>"); buffer.append("</C:filter>"); buffer.append("</C:calendar-query>"); SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString());/* w w w. j a v a 2s . c o m*/ httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testGetWebdavUri() { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); Uri webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers", webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); assertTrue("WebDAV URI is not a subpath of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) && webdavUri.getPath().startsWith(mServerUri.getPath())); client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUsername, mPassword)); webdavUri = client.getWebdavUri();//from ww w .ja v a2 s. c o m assertTrue("WebDAV URI does not point to the right entry point", webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); PropFindMethod propfind = null; try { propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0); int status = client.executeMethod(propfind); assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status); } catch (IOException e) { Log.e(TAG, "Exception in PROPFIND method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { propfind.releaseConnection(); } }