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);
}
}
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);
}
}
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");
}
}
}
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;
}
}
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;
}
Aggregations