Search in sources :

Example 21 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class AnnoPrincipalResource method getCalendarHomeSet.

@Override
public HrefList getCalendarHomeSet() {
    try {
        HrefList list = new HrefList();
        for (Resource r : getChildren()) {
            if (r instanceof AnnoCollectionResource) {
                AnnoCollectionResource col = (AnnoCollectionResource) r;
                if (annoFactory.calendarsAnnotationHandler.hasCalendars(col.getSource())) {
                    list.add(col.getHref());
                }
            }
        }
        if (list.isEmpty()) {
            ResourceList topDirs = getChildren().getDirs();
            if (topDirs.isEmpty()) {
                log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + ". In fact there are no child diretories at all!");
            } else {
                log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + " You should have a @" + Calendars.class + " annotation on one of the following methods");
                for (Resource r : topDirs) {
                    if (r instanceof AnnoCollectionResource) {
                        AnnoCollectionResource col = (AnnoCollectionResource) r;
                        List<ControllerMethod> candMethods = annoFactory.calendarsAnnotationHandler.getMethods(col.getSource().getClass());
                        if (candMethods.isEmpty()) {
                            log.info("	- inspecting: " + col.getName() + " for source: " + col.getSource().getClass() + " - has NO child methods");
                        } else {
                            log.info("	- inspecting: " + col.getName() + " for source: " + col.getSource().getClass());
                            for (ControllerMethod cm : candMethods) {
                                log.warn("	- candidate method: " + cm.controller.getClass() + "::" + cm.method.getName());
                            }
                        }
                    } else {
                        log.warn("	- found a directory which is not a AnnoCollectionResource: " + r.getClass() + " which cannot be inspected");
                    }
                }
            }
        }
        return list;
    } catch (NotAuthorizedException e) {
        throw new RuntimeException(e);
    } catch (BadRequestException e) {
        throw new RuntimeException(e);
    }
}
Also used : Resource(io.milton.resource.Resource) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) HrefList(io.milton.http.values.HrefList)

Example 22 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class MiltonFtpFile method isWritable.

/**
 * Check file write permission.
 */
@Override
public boolean isWritable() {
    try {
        log.debug("isWritable: " + getAbsolutePath());
        if (path.isRoot())
            return false;
        Auth auth = new Auth(user.getName(), user.getUser());
        FtpRequest request = new FtpRequest(Method.DELETE, auth, path.toString());
        if (r != null) {
            if (r instanceof ReplaceableResource) {
                return r.authorise(request, Method.PUT, auth);
            }
        }
        if (getParent() instanceof PutableResource) {
            return getParent().authorise(request, Method.PUT, auth);
        } else {
            return false;
        }
    } catch (NotAuthorizedException ex) {
        throw new RuntimeException(ex);
    } catch (BadRequestException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Auth(io.milton.http.Auth) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) ReplaceableResource(io.milton.resource.ReplaceableResource)

Example 23 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class MiltonFtpFile method createOutputStream.

@Override
public OutputStream createOutputStream(long offset) throws IOException {
    log.debug("createOutputStream: " + offset);
    final BufferingOutputStream out = new BufferingOutputStream(50000);
    if (r instanceof ReplaceableResource) {
        log.debug("resource is replaceable");
        final ReplaceableResource rr = (ReplaceableResource) r;
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    rr.replaceContent(out.getInputStream(), out.getSize());
                } catch (BadRequestException ex) {
                    throw new RuntimeException(ex);
                } catch (ConflictException ex) {
                    throw new RuntimeException(ex);
                } catch (NotAuthorizedException ex) {
                    throw new RuntimeException(ex);
                }
            }
        };
        out.setOnClose(runnable);
        return out;
    } else {
        CollectionResource col;
        try {
            col = getParent();
        } catch (NotAuthorizedException ex) {
            throw new RuntimeException(ex);
        } catch (BadRequestException ex) {
            throw new RuntimeException(ex);
        }
        if (col == null) {
            throw new IOException("parent not found");
        } else if (col instanceof PutableResource) {
            final PutableResource putableResource = (PutableResource) col;
            final String newName = path.getName();
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    try {
                        putableResource.createNew(newName, out.getInputStream(), out.getSize(), null);
                    } catch (BadRequestException ex) {
                        throw new RuntimeException(ex);
                    } catch (NotAuthorizedException ex) {
                        throw new RuntimeException(ex);
                    } catch (ConflictException ex) {
                        throw new RuntimeException(ex);
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
                }
            };
            out.setOnClose(runnable);
            return out;
        } else {
            throw new IOException("folder doesnt support PUT, and the resource is not replaceable");
        }
    }
}
Also used : ConflictException(io.milton.http.exceptions.ConflictException) BufferingOutputStream(io.milton.common.BufferingOutputStream) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) IOException(java.io.IOException) ReplaceableResource(io.milton.resource.ReplaceableResource)

Example 24 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class MiltonFtpFile method createInputStream.

@Override
public InputStream createInputStream(long offset) throws IOException {
    if (r instanceof GetableResource) {
        GetableResource gr = (GetableResource) r;
        String ct = gr.getContentType(null);
        BufferingOutputStream out = new BufferingOutputStream(50000);
        try {
            gr.sendContent(out, null, null, ct);
            out.close();
            return out.getInputStream();
        } catch (NotFoundException ex) {
            log.warn("Not found exception", ex);
            return null;
        } catch (BadRequestException ex) {
            log.warn("bad request", ex);
            return null;
        } catch (NotAuthorizedException ex) {
            log.warn("not authorising", ex);
            return null;
        }
    } else {
        return null;
    }
}
Also used : BufferingOutputStream(io.milton.common.BufferingOutputStream) NotFoundException(io.milton.http.exceptions.NotFoundException) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Example 25 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class MiltonFtpFile method listFiles.

@Override
public List<FtpFile> listFiles() {
    log.debug("listfiles");
    List<FtpFile> list = new ArrayList<FtpFile>();
    if (r instanceof CollectionResource) {
        try {
            CollectionResource cr = (CollectionResource) r;
            for (Resource child : cr.getChildren()) {
                list.add(ftpFactory.wrap(path.child(child.getName()), child));
            }
        } catch (NotAuthorizedException ex) {
            throw new RuntimeException(ex);
        } catch (BadRequestException ex) {
            throw new RuntimeException(ex);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ReplaceableResource(io.milton.resource.ReplaceableResource) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) FtpFile(org.apache.ftpserver.ftplet.FtpFile)

Aggregations

BadRequestException (io.milton.http.exceptions.BadRequestException)37 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)25 IOException (java.io.IOException)15 Resource (io.milton.resource.Resource)11 ConflictException (io.milton.http.exceptions.ConflictException)10 SQLException (java.sql.SQLException)10 Connection (java.sql.Connection)9 Path (io.milton.common.Path)6 NotFoundException (io.milton.http.exceptions.NotFoundException)6 Permissions (nl.uva.cs.lobcder.auth.Permissions)6 CollectionResource (io.milton.resource.CollectionResource)5 URISyntaxException (java.net.URISyntaxException)5 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)5 ReplaceableResource (io.milton.resource.ReplaceableResource)4 BufferingOutputStream (io.milton.common.BufferingOutputStream)3 Range (io.milton.http.Range)3 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)3 GetableResource (io.milton.resource.GetableResource)3 PostableResource (io.milton.resource.PostableResource)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3