org.apache.jackrabbit.webdav.DavException Java Examples
The following examples show how to use
org.apache.jackrabbit.webdav.DavException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public ActiveLock refreshLock( LockInfo lockInfo, String lockToken ) throws DavException { if ( !exists() ) { throw new DavException( DavServletResponse.SC_NOT_FOUND ); } ActiveLock lock = getLock( lockInfo.getType(), lockInfo.getScope() ); if ( lock == null ) { throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given type/scope present on resource " + getResourcePath() ); } lock = lockManager.refreshLock( lockInfo, lockToken, this ); return lock; }
Example #2
Source File: ArchivaDavResourceFactory.java From archiva with Apache License 2.0 | 6 votes |
private ArchivaDavResourceLocator checkLocatorIsInstanceOfRepositoryLocator( DavResourceLocator locator ) throws DavException { if ( !( locator instanceof ArchivaDavResourceLocator ) ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Locator does not implement RepositoryLocator" ); } // Hidden paths if ( locator.getResourcePath().startsWith( ArchivaDavResource.HIDDEN_PATH_PREFIX ) ) { throw new DavException( HttpServletResponse.SC_NOT_FOUND ); } ArchivaDavResourceLocator archivaLocator = (ArchivaDavResourceLocator) locator; // MRM-419 - Windows Webdav support. Should not 404 if there is no content. if ( StringUtils.isEmpty( archivaLocator.getRepositoryId() ) ) { throw new DavException( HttpServletResponse.SC_NO_CONTENT ); } return archivaLocator; }
Example #3
Source File: CtagHandler.java From openmeetings with Apache License 2.0 | 6 votes |
@Override BaseDavRequest internalSyncItems() throws IOException, DavException { //Calendar already inited. DavPropertyNameSet properties = new DavPropertyNameSet(); properties.add(DNAME_GETCTAG); HttpPropFindMethod method = new HttpPropFindMethod(path, properties, CalDAVConstants.DEPTH_0); HttpResponse httpResponse = client.execute(method, context); if (method.succeeded(httpResponse)) { for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus(httpResponse).getResponses()) { DavPropertySet set = response.getProperties(SC_OK); String ctag = AppointmentManager.getTokenFromProperty(set.get(DNAME_GETCTAG)); if (ctag != null && !ctag.equals(calendar.getToken())) { EtagsHandler etagsHandler = new EtagsHandler(path, calendar, client, context, appointmentDao, utils); etagsHandler.syncItems(); calendar.setToken(ctag); } } } else { log.error("Error executing PROPFIND Method, with status Code: {}", httpResponse.getStatusLine().getStatusCode()); } return method; }
Example #4
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public DavResourceIterator getMembers() { List<DavResource> list; if ( exists() && isCollection() ) { list = asset.list().stream().filter( m -> !m.getName().startsWith( HIDDEN_PATH_PREFIX ) ) .map(m -> { String path = locator.getResourcePath( ) + '/' + m.getName(); DavResourceLocator resourceLocator = locator.getFactory( ).createResourceLocator( locator.getPrefix( ), path ); try { return factory.createResource( resourceLocator, session ); } catch ( DavException e ) { return null; } }).filter( Objects::nonNull ).collect( Collectors.toList()); } else { list = Collections.emptyList( ); } return new DavResourceIteratorImpl( list ); }
Example #5
Source File: DeltaVResourceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public Report getReport(ReportInfo reportInfo) throws DavException { if (reportInfo == null) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "A REPORT request must provide a valid XML request body."); } if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND); } if (supportedReports.isSupportedReport(reportInfo)) { Report report = ReportType.getType(reportInfo).createReport(this, reportInfo); return report; } else { throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Unkown report " + reportInfo.getReportName() + "requested."); } }
Example #6
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public void unlock( String lockToken ) throws DavException { ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE ); if ( lock == null ) { throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED ); } else if ( lock.isLockedByToken( lockToken ) ) { lockManager.releaseLock( lockToken, this ); } else { throw new DavException( DavServletResponse.SC_LOCKED ); } }
Example #7
Source File: TestCaldavHttpClient4.java From davmail with GNU General Public License v2.0 | 6 votes |
public void testInvalidDavRequest() { BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) { @Override public String getMethod() { return DavMethods.METHOD_REPORT; } }; method.setEntity(new StringEntity("invalid", ContentType.create("text/xml", "UTF-8"))); try { httpClient.executeDavRequest(method); fail("Should fail"); } catch (IOException e) { assertNotNull(e.getMessage()); assertEquals(503, ((DavException)e.getCause()).getErrorCode()); } }
Example #8
Source File: DavResourceFactoryImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException { try { DavResource resource = getFromCache(session, locator.getResourcePath()); if (resource != null) return resource; Resource res = resourceService.getResource(locator.getResourcePath(), session); resource = createResource(locator, session, res); putInCache(session, resource); return resource; } catch (Throwable e) { log.error(e.getMessage(), e); throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e); } }
Example #9
Source File: DavResourceTest.java From archiva with Apache License 2.0 | 6 votes |
@Test public void testRefreshLockThrowsExceptionIfNoLockIsPresent() throws Exception { LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false ); assertEquals( 0, resource.getLocks().length ); try { lockManager.refreshLock( info, "notoken", resource ); fail( "Did not throw dav exception" ); } catch ( DavException e ) { assertEquals( DavServletResponse.SC_PRECONDITION_FAILED, e.getErrorCode() ); } assertEquals( 0, resource.getLocks().length ); }
Example #10
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The OPTION method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource */ protected void doOptions(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doOptions"); response.addHeader(DavConstants.HEADER_DAV, resource.getComplianceClass()); response.addHeader("Allow", resource.getSupportedMethods()); response.addHeader("MS-Author-Via", DavConstants.HEADER_DAV); if (resource instanceof SearchResource) { String[] langs = ((SearchResource) resource).getQueryGrammerSet().getQueryLanguages(); for (int i = 0; i < langs.length; i++) { response.addHeader(SearchConstants.HEADER_DASL, "<" + langs[i] + ">"); } } // with DeltaV the OPTIONS request may contain a Xml body. OptionsResponse oR = null; OptionsInfo oInfo = request.getOptionsInfo(); if (oInfo != null && resource instanceof DeltaVResource) { oR = ((DeltaVResource) resource).getOptionResponse(oInfo); } if (oR == null) { response.setStatus(DavServletResponse.SC_OK); } else { response.sendXmlResponse(oR, DavServletResponse.SC_OK); } }
Example #11
Source File: DavResourceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * Adds a new member to this resource. * * @see DavResource#addMember(DavResource, * org.apache.jackrabbit.webdav.io.InputContext) */ public void addMember(DavResource member, InputContext inputContext) throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_CONFLICT); } if (isLocked(this) || isLocked(member)) { throw new DavException(DavServletResponse.SC_LOCKED); } try { String memberName = Text.getName(member.getLocator().getResourcePath()); ImportContext ctx = getImportContext(inputContext, memberName); if (!config.getIOManager().importContent(ctx, member)) { // any changes should have been reverted in the importer throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); } } catch (Exception e) { log.error(e.getMessage(), e); } }
Example #12
Source File: SyncMethod.java From openmeetings with Apache License 2.0 | 6 votes |
/** * Adapted from DavMethodBase to handle MultiStatus responses. * * @param response {@link HttpResponse} to be converted to {@link MultiStatus} * @return MultiStatus response * @throws DavException if the response body could not be parsed */ @Override public MultiStatus getResponseBodyAsMultiStatus(HttpResponse response) throws DavException { if (!processedResponse) { processResponseBody(response); } if (multiStatus != null) { return multiStatus; } else { DavException dx = getResponseException(response); if (dx != null) { throw dx; } else { throw new DavException(response.getStatusLine().getStatusCode(), getMethod() + " resulted with unexpected status: " + response.getStatusLine()); } } }
Example #13
Source File: VersionControlledResourceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * Modify the labels present with the versions of this resource. * * @param labelInfo details of the label * * @throws org.apache.jackrabbit.webdav.DavException error in the DAV communication * @see VersionControlledResource#label(LabelInfo) * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String, * boolean) * @see javax.jcr.version.VersionHistory#removeVersionLabel(String) */ public void label(LabelInfo labelInfo) throws DavException { if (labelInfo == null) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required."); } if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND); } try { if (!isVersionControlled()) { throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "A LABEL request may only be applied to a version-controlled, checked-in resource."); } DavResource[] resArr = this.getReferenceResources(CHECKED_IN); if (resArr.length == 1 && resArr[0] instanceof VersionResource) { ((VersionResource) resArr[0]).label(labelInfo); } else { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:checked-in property on '" + getHref() + "' did not point to a single VersionResource."); } } catch (Exception e) { } }
Example #14
Source File: ArchivaVirtualDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public DavResource getCollection() { DavResource parent = null; if ( getResourcePath() != null && !getResourcePath().equals( "/" ) ) { String parentPath = Text.getRelativeParent( getResourcePath(), 1 ); if ( parentPath.equals( "" ) ) { parentPath = "/"; } DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath ); try { // go back to ArchivaDavResourceFactory! parent = factory.createResource( parentloc, null ); } catch ( DavException e ) { // should not occur } } return parent; }
Example #15
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public DavResource getCollection() { DavResource parent = null; if ( getResourcePath() != null && !getResourcePath().equals( "/" ) ) { String parentPath = Text.getRelativeParent( getResourcePath(), 1 ); if ( parentPath.equals( "" ) ) { parentPath = "/"; } DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath ); try { parent = factory.createResource( parentloc, session ); } catch ( DavException e ) { // should not occur } } return parent; }
Example #16
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The PROPPATCH method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error */ @SuppressWarnings("rawtypes") protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doPropPatch"); List changeList = request.getPropPatchChangeList(); if (changeList.isEmpty()) { response.sendError(DavServletResponse.SC_BAD_REQUEST); return; } MultiStatus ms = new MultiStatus(); MultiStatusResponse msr = resource.alterProperties(changeList); ms.addResponse(msr); response.sendMultiStatus(ms); }
Example #17
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * Validate the given destination resource and return the proper status * code: Any return value greater/equal than * {@link DavServletResponse#SC_NO_CONTENT} indicates an error. * * @param destResource destination resource to be validated. * @param request the HTTP request * * @return status code indicating whether the destination is valid. */ private int validateDestination(DavResource destResource, WebdavRequest request) throws DavException { String destHeader = request.getHeader(HEADER_DESTINATION); if (destHeader == null || "".equals(destHeader)) { return DavServletResponse.SC_BAD_REQUEST; } if (destResource.getLocator().equals(request.getRequestLocator())) { return DavServletResponse.SC_FORBIDDEN; } int status; if (destResource.exists()) { if (request.isOverwrite()) { // matching if-header required for existing resources if (!request.matchesIfHeader(destResource)) { return DavServletResponse.SC_PRECONDITION_FAILED; } else { // overwrite existing resource destResource.getCollection().removeMember(destResource); status = DavServletResponse.SC_NO_CONTENT; } } else { // cannot copy/move to an existing item, if overwrite is not // forced return DavServletResponse.SC_PRECONDITION_FAILED; } } else { // destination does not exist >> copy/move can be performed status = DavServletResponse.SC_CREATED; } return status; }
Example #18
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeMember( DavResource member ) throws DavException { StorageAsset resource = checkDavResourceIsArchivaDavResource( member ).getAsset( ); if ( resource.exists() ) { try { if ( resource.isContainer() ) { repositoryStorage.removeAsset( resource ); triggerAuditEvent( member, AuditEvent.REMOVE_DIR ); } else { repositoryStorage.removeAsset( resource ); triggerAuditEvent( member, AuditEvent.REMOVE_FILE ); } log.debug( "{}{}' removed (current user '{}')", ( resource.isContainer() ? "Directory '" : "File '" ), member.getDisplayName(), this.principal ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); } } else { throw new DavException( HttpServletResponse.SC_NOT_FOUND ); } }
Example #19
Source File: DavResourceTest.java From archiva with Apache License 2.0 | 5 votes |
@Override public DavResource createResource( DavResourceLocator locator, DavSession session ) throws DavException { try { return new ArchivaDavResource( new FilesystemAsset(repository, "/" , baseDir.toAbsolutePath()), "/", repository, session, resourceLocator, resourceFactory, mimeTypes, Collections.<AuditListener> emptyList(), null ); } catch ( LayoutException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e ); } }
Example #20
Source File: TestCaldav.java From davmail with GNU General Public License v2.0 | 5 votes |
public void testPropfindRoot() throws IOException, DavException { DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet(); davPropertyNameSet.add(DavPropertyName.create("current-user-principal", Namespace.getNamespace("DAV:"))); davPropertyNameSet.add(DavPropertyName.create("principal-URL", Namespace.getNamespace("DAV:"))); davPropertyNameSet.add(DavPropertyName.create("resourcetype", Namespace.getNamespace("DAV:"))); PropFindMethod method = new PropFindMethod("/", davPropertyNameSet, 0); httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode()); method.getResponseBodyAsMultiStatus(); }
Example #21
Source File: ArchivaVirtualDavResource.java From archiva with Apache License 2.0 | 5 votes |
@SuppressWarnings( "unchecked" ) @Override public MultiStatusResponse alterProperties( List arg0 ) throws DavException { return null; }
Example #22
Source File: ResourceServiceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public Resource move(Resource source, Resource destination, DavSession session) throws DavException { String sid = (String) session.getObject("sid"); if (source.isWorkspace()) { throw new DavException(DavServletResponse.SC_FORBIDDEN, "Cannot move a workspace"); } else if (source.isFolder()) { return folderRenameOrMove(source, destination, session, sid); } else { return fileRenameOrMove(source, destination, session, sid); } }
Example #23
Source File: TestCaldav.java From davmail with GNU General Public License v2.0 | 5 votes |
public void testWellKnown() throws IOException, DavException { DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet(); davPropertyNameSet.add(DavPropertyName.create("current-user-principal", Namespace.getNamespace("DAV:"))); davPropertyNameSet.add(DavPropertyName.create("principal-URL", Namespace.getNamespace("DAV:"))); davPropertyNameSet.add(DavPropertyName.create("resourcetype", Namespace.getNamespace("DAV:"))); PropFindMethod method = new PropFindMethod("/.well-known/caldav", davPropertyNameSet, 0); httpClient.executeMethod(method); assertEquals(HttpStatus.SC_MOVED_PERMANENTLY, method.getStatusCode()); }
Example #24
Source File: ExceptionConverter.java From commons-vfs with Apache License 2.0 | 5 votes |
public static FileSystemException generate(final DavException davExc) throws FileSystemException { String msg = davExc.getMessage(); if (davExc.hasErrorCondition()) { try { final Element error = davExc.toXml(DomUtil.createDocument()); if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) { if (DomUtil.hasChildElement(error, "exception", null)) { final Element exc = DomUtil.getChildElement(error, "exception", null); if (DomUtil.hasChildElement(exc, "message", null)) { msg = DomUtil.getChildText(exc, "message", null); } if (DomUtil.hasChildElement(exc, "class", null)) { final Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null)); final Constructor<?> excConstr = cl.getConstructor(new Class[] { String.class }); if (excConstr != null) { final Object o = excConstr.newInstance(new Object[] { msg }); if (o instanceof FileSystemException) { return (FileSystemException) o; } else if (o instanceof Exception) { return new FileSystemException(msg, (Exception) o); } } } } } } catch (final Exception e) { throw new FileSystemException(e); } } return new FileSystemException(msg); }
Example #25
Source File: DavResourceFactoryImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavSession session) throws DavException { try { String resourcePath = locator.getResourcePath(); Matcher matcher = versionRequestPattern.matcher(locator.getResourcePath()); String version = null; if (matcher.matches() == true) { version = matcher.group(1); resourcePath = resourcePath.replaceFirst("/vstore/" + version, ""); } DavResource resource; Resource repositoryResource = resourceService.getResource(resourcePath, session); if (repositoryResource == null) { boolean isCollection = DavMethods.isCreateCollectionRequest(request); resource = createNullResource(locator, session, isCollection); } else { repositoryResource.setVersionLabel(version); repositoryResource.setRequestedPerson(Long.parseLong(session.getObject("id").toString())); resource = new VersionControlledResourceImpl(locator, this, session, resourceConfig, repositoryResource); } putInCache(session, resource); return resource; } catch (Exception e) { log.error(e.getMessage(), e); throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e); } }
Example #26
Source File: DavResourceFactoryImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public DavResource createResource(DavResourceLocator locator, DavSession session, Resource resource) throws DavException { DavResource res = getFromCache(session, locator.getResourcePath()); if (res != null) return res; res = new VersionControlledResourceImpl(locator, this, session, resourceConfig, resource); putInCache(session, res); return res; }
Example #27
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 5 votes |
private void triggerAuditEvent( DavResource member, String action ) throws DavException { String path = logicalResource + "/" + member.getDisplayName(); ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member ); AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, action ); auditEvent.setRemoteIP( resource.remoteAddr ); for ( AuditListener listener : auditListeners ) { listener.auditEvent( auditEvent ); } }
Example #28
Source File: HttpClientAdapter.java From davmail with GNU General Public License v2.0 | 5 votes |
/** * Execute WebDav request * * @param request WebDav request * @return multistatus response * @throws IOException on error */ public MultiStatus executeDavRequest(BaseDavRequest request) throws IOException { handleURI(request); MultiStatus multiStatus = null; try (CloseableHttpResponse response = execute(request)) { request.checkSuccess(response); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_MULTI_STATUS) { multiStatus = request.getResponseBodyAsMultiStatus(response); } } catch (DavException e) { LOGGER.error(e.getMessage(), e); throw new IOException(e.getErrorCode() + " " + e.getStatusPhrase(), e); } return multiStatus; }
Example #29
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 5 votes |
private ArchivaDavResource checkDavResourceIsArchivaDavResource( DavResource resource ) throws DavException { if ( !( resource instanceof ArchivaDavResource ) ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "DavResource is not instance of ArchivaDavResource" ); } return (ArchivaDavResource) resource; }
Example #30
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 5 votes |
@Override public void move( DavResource destination ) throws DavException { if ( !exists() ) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." ); } try { ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( destination ); if ( isCollection() ) { this.asset = repositoryStorage.moveAsset( asset, destination.getResourcePath() ); triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_DIRECTORY ); } else { this.asset = repositoryStorage.moveAsset( asset, destination.getResourcePath() ); triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_FILE ); } log.debug( "{}{}' moved to '{}' (current user '{}')", ( isCollection() ? "Directory '" : "File '" ), asset.getPath(), destination, this.principal ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e ); } }