public StorageItem dereferenceLinkItem( StorageLinkItem item ) throws NoSuchResourceStoreException, ItemNotFoundException, AccessDeniedException, IllegalOperationException, StorageException { return getRootRouter().dereferenceLink( item ); }
@Override protected String getHttpMethodAction(ServletRequest request) { String method = ((HttpServletRequest) request).getMethod().toLowerCase(); if ("put".equals(method)) { // heavy handed thing // doing a LOCAL ONLY request to check is this exists? try { rootRouter.retrieveItem(getResourceStoreRequest(request, true)); } catch (ItemNotFoundException e) { // the path does not exists, it is a CREATE method = "post"; } catch (AccessDeniedException e) { // no access for read, so chances are post or put doesnt matter method = "post"; } catch (Exception e) { // huh? throw new IllegalStateException("Got exception during target mapping!", e); } // the path exists, this is UPDATE return super.getHttpMethodAction(method); } else { return super.getHttpMethodAction(request); } }
@Override protected void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final ResourceStoreRequest rsr = getResourceStoreRequest(request); try { repositoryRouter.deleteItem(rsr); response.setStatus(HttpServletResponse.SC_NO_CONTENT); ((Stopwatch) rsr.getRequestContext().get(STOPWATCH_KEY)).stop(); } catch (Exception e) { ((Stopwatch) rsr.getRequestContext().get(STOPWATCH_KEY)).stop(); handleException(request, response, rsr, e); } }
route = repositoryRouter.getRequestRouteForRequest(request); repositoryRouter.dereferenceLink((StorageLinkItem) item, request.isRequestLocalOnly(), request.isRequestRemoteOnly());
@Override public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException { // let check the mappedValues 1st boolean result = false; if (mappedValue != null) { result = super.isAccessAllowed(request, response, mappedValue); // if we are not allowed at start, forbid it if (!result) { return false; } } String actionVerb = getHttpMethodAction(request); Action action = Action.valueOf(actionVerb); if (null == action) { return false; } return rootRouter.authorizePath(getResourceStoreRequest(request, false), action); } }
@Override protected void doPut(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final ResourceStoreRequest rsr = getResourceStoreRequest(request); try { final Map<String, String> userAttributes = getUserAttributesFromRequest(request); repositoryRouter.storeItem(rsr, request.getInputStream(), userAttributes); ((Stopwatch) rsr.getRequestContext().get(STOPWATCH_KEY)).stop(); response.setStatus(HttpServletResponse.SC_CREATED); } catch (Exception e) { ((Stopwatch) rsr.getRequestContext().get(STOPWATCH_KEY)).stop(); handleException(request, response, rsr, e); } }
route = repositoryRouter.getRequestRouteForRequest( request ); repositoryRouter.dereferenceLink( (StorageLinkItem) item, request.isRequestLocalOnly(), request.isRequestRemoteOnly() );
@Override public boolean isAccessAllowed( ServletRequest request, ServletResponse response, Object mappedValue ) throws IOException { // let check the mappedValues 1st boolean result = false; if ( mappedValue != null ) { result = super.isAccessAllowed( request, response, mappedValue ); // if we are not allowed at start, forbid it if ( !result ) { return false; } } String actionVerb = getHttpMethodAction( request ); Action action = Action.valueOf( actionVerb ); if ( null == action ) { return false; } return rootRouter.authorizePath( getResourceStoreRequest( request, false ), action ); } }
@VisibleForTesting Object renderStorageLinkItem(final Context context, final Request req, final Response res, final Variant variant, final ResourceStore store, final StorageLinkItem item) throws ResourceException { // we have a link, dereference it // TODO: we should be able to do HTTP redirects too! (parametrize the dereferencing?) try { return renderItem(context, req, res, variant, store, getRepositoryRouter().dereferenceLink(item)); } catch (Exception e) { handleException(req, res, e); return null; } }
rootRouter.retrieveItem( getResourceStoreRequest( request, true ) );
/** * Dereferences the passed in link completely (following link-to-links too) as long as non-link item is found as * target. This method will detect cycles, and will fail if such link constellation is found. If any target during * dereference is not found, the usual {@link ItemNotFoundException} will be thrown (by the method used to * dereference). */ protected StorageItem dereferenceLink(final StorageLinkItem link) throws Exception { final List<String> hops = Lists.newArrayList(); StorageLinkItem currentLink = link; while (true) { final String hop = currentLink.getRepositoryItemUid().getKey(); if (!hops.contains(hop)) { hops.add(hop); final StorageItem item = repositoryRouter.dereferenceLink(currentLink); if (!(item instanceof StorageLinkItem)) { return item; } else { currentLink = (StorageLinkItem) item; } } else { // cycle detected, current link already processed throw new ItemNotFoundException(ItemNotFoundException.reasonFor(link.getResourceStoreRequest(), link .getRepositoryItemUid().getRepository(), "Link item %s introduced a cycle while referencing it, cycle is %s", link.getRepositoryItemUid(), hops)); } } }
try { try { StorageItem item = repositoryRouter.retrieveItem(rsr); if (item instanceof StorageLinkItem) { final StorageLinkItem link = (StorageLinkItem) item;