@Override public void replaceContent(InputStream in, Long length) throws BadRequestException, ConflictException, NotAuthorizedException { try { contentService.setFileContent(file, in); } catch (IOException ex) { throw new BadRequestException("Couldnt write to: " + file.getAbsolutePath(), ex); } } }
switch (result) { case 400: throw new BadRequestException(href); case 401: throw new NotAuthorizedException(href, null); case 403: throw new NotAuthorizedException(href, null); case 404: throw new NotFoundException(href); case 405: throw new MethodNotAllowedException(result, href); case 409: throw new ConflictException(href); default: throw new GenericHttpException(result, href);
@Override public synchronized void unlock( String tokenId, LockableResource r ) throws NotAuthorizedException { FsResource resource = (FsResource) r; LockToken lockToken = currentLock( resource ); if( lockToken == null ) { log.debug( "not locked" ); return; } if( lockToken.tokenId.equals( tokenId ) ) { removeLock( lockToken ); } else { throw new NotAuthorizedException( resource ); } }
void process() throws ConflictException, NotAuthorizedException, BadRequestException { String relFolder = sFolder.substring( 1 ); Path p = Path.path( relFolder ); Resource r = find( wrappedResource, p ); if( r instanceof CollectionResource ) { target = (CollectionResource) r; } else { log.warn("not found or not CollectionResource: " + r); } if( target == null ) { log.warn( "No PutableResource with that path: " + sFolder ); throw new BadRequestException( "Path not found: " + sFolder ); } try { if( command.equals( "GetFolders" ) ) { processGetFoldersCommand( false ); } else if( command.equals( "GetFoldersAndFiles" ) ) { processGetFoldersCommand( true ); } else if( command.equals( "CreateFolder" ) ) { processCreateFolderCommand(); } else if( command.equals( "FileUpload" ) ) { processUploadFolderCommand(); } else { log.warn( "Unknown command: " + command ); throw new ConflictException( target ); } } finally { writer.flush(); } }
String dest = parameters.get( "destination"); if( dest == null ) { throw new BadRequestException(this, "The destination parameter is null"); } else if (dest.trim().length() == 0 ) { throw new BadRequestException(this, "The destination parameter is empty"); throw new BadRequestException(this, "Couldnt parse the destination header, returned null from: " + dest); if( rDestParent == null ) throw new BadRequestException( wrapped, "The destination parent does not exist"); if(rDestParent instanceof CollectionResource ) { CollectionResource colDestParent = (CollectionResource) rDestParent; } catch( ConflictException ex ) { log.warn( "Exception copying to: " + pDest.getName(), ex); throw new BadRequestException( rDestParent, "conflict: " + ex.getMessage()); throw new BadRequestException( rDestParent, "File already exists"); throw new BadRequestException( wrapped, "The destination parent is not a collection resource");
log.warn("BadRequestException: " + ex.getReason(), ex); manager.getResponseHandler().respondBadRequest(ex.getResource(), response, request); } catch (ConflictException ex) { log.warn("conflictException: ", ex); manager.getResponseHandler().respondConflict(ex.getResource(), response, request, INTERNAL_SERVER_ERROR_HTML); } catch (NotAuthorizedException ex) { log.warn("NotAuthorizedException", ex); manager.getResponseHandler().respondUnauthorised(ex.getResource(), response, request); } catch (NotFoundException ex) { log.warn("NotFoundException", ex);
if( cause instanceof NotAuthorizedException ) { NotAuthorizedException nae = (NotAuthorizedException)cause; if( nae.getResource() == null ) { throw new NotAuthorizedException(sourceRes, nae); // need exception with resource so we can generate challenge
} catch (BadRequestException e) { log.warn("BadRequestException", e); errorMessage = "Bad Request: " + e.getReason(); } catch (NotAuthorizedException e) { log.warn("NotAuthorizedException", e); errorMessage = "Not authorised: " + e.getMessage(); } catch (ConflictException e) { log.warn("ConflictException", e); errorMessage = "Conflict: " + e.getMessage();
private String findAcceptableName(String baseName, String ext, int i) throws ConflictException, NotAuthorizedException, BadRequestException { String candidateName = baseName + "_" + i; if (ext != null && ext.length() > 0) { candidateName += "." + ext; } if (wrapped.child(candidateName) == null) { return candidateName; } else { if (i < 100) { return findAcceptableName(baseName, ext, i + 1); } else { log.warn("Too many files with similar names: " + candidateName); throw new ConflictException(this); } } }
@Override public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotFoundException { InputStream in = null; try { in = contentService.getFileContent(file); if (range != null) { log.debug("sendContent: ranged content: " + file.getAbsolutePath()); RangeUtils.writeRange(in, range, out); } else { log.debug("sendContent: send whole file " + file.getAbsolutePath()); IOUtils.copy(in, out); } out.flush(); } catch (FileNotFoundException e) { throw new NotFoundException("Couldnt locate content"); } catch (ReadingException e) { throw new IOException(e); } catch (WritingException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(in); } }
@Override public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException { if (r == null) { throw new BadRequestException(this, "No existing resource was found to map the zsync operation to"); } if (ranges != null) { log.info("sendContent: sending range data"); sendRangeData(out); } else { log.info("sendContent: sending meta data"); sendMetaData(params, contentType, out); } }
public String processForm( Map<String, String> parameters, Map<String, FileItem> files ) throws BadRequestException, NotAuthorizedException { String destHeader = parameters.get( "destination"); String dest = Utils.decodePath(destHeader); Path pDest = Path.path( dest ); Resource rDestParent = resourceFactory.getResource( host, pDest.getParent().toString()); if( rDestParent == null ) throw new BadRequestException( wrapped, "The destination parent does not exist"); if(rDestParent instanceof CollectionResource ) { CollectionResource colDestParent = (CollectionResource) rDestParent; if( colDestParent.child( pDest.getName()) == null ) { try { wrapped.copyTo( colDestParent, pDest.getName() ); } catch( ConflictException ex ) { log.warn( "Exception copying to: " + pDest.getName(), ex); throw new BadRequestException( rDestParent, "conflict: " + ex.getMessage()); } return null; } else { log.warn( "destination already exists: " + pDest.getName()); throw new BadRequestException( rDestParent, "File already exists"); } } else { throw new BadRequestException( wrapped, "The destination parent is not a collection resource"); } }
@Override public synchronized void unlock(String tokenId, LockableResource r) throws NotAuthorizedException { LockToken lockToken = currentLock(r.getUniqueId()); if (lockToken == null) { log.debug("not locked"); return; } if (lockToken.tokenId.equals(tokenId)) { removeLock(lockToken); } else { throw new NotAuthorizedException("Non-matching tokens: " + tokenId + " != " + lockToken.tokenId, r); } }
if (!autoname) { log.warn("Conflict: Can't create resource with name " + initialName + " because it already exists. To rename automatically use request parameter: " + PARAM_AUTONAME + ", or to overwrite use " + PARAM_OVERWRITE); throw new ConflictException(this); } else { log.trace("file exists and autoname is set, so will find acceptable name");
@Override public void process(HttpManager manager, Request request, Response response) throws NotAuthorizedException, ConflictException, BadRequestException { String url = request.getAbsoluteUrl(); if (url.contains("#")) { // See http://www.ettrema.com:8080/browse/MIL-88 // Litmus test thinks this is unsafe throw new BadRequestException(null, "Can't delete a resource with a # in the url"); } resourceHandlerHelper.process(manager, request, response, this); }
if (authStatus == null) { log.trace("Authentication not attempted"); throw new NotAuthorizedException(res); } else { if (authStatus.loginFailed) { log.warn("Early authentication failed"); throw new NotAuthorizedException(res); } else { log.trace("Early authentication succeeded");
public void moveTo(io.milton.httpclient.Resource remoteResource, String destName, Folder destRemoteFolder) throws NotAuthorizedException, ConflictException, BadRequestException { try { if (destName.equals(remoteResource.name)) { // this is the normal case, move with no rename remoteResource.moveTo(destRemoteFolder); } else { // its possible to request a copy with a new name remoteResource.moveTo(destRemoteFolder, destName); } } catch (IOException ex) { throw new RuntimeException(ex); } catch (HttpException ex) { throw new RuntimeException(ex); } catch (NotFoundException ex) { throw new BadRequestException("Remote resource does not exist", ex); } } }
public void copyTo(io.milton.httpclient.Resource remoteResource, String destName, Folder destRemoteFolder) throws RuntimeException, ConflictException, BadRequestException, NotAuthorizedException { try { if (destName.equals(remoteResource.name)) { // this is the normal case, copy with no rename remoteResource.copyTo(destRemoteFolder); } else { // its possible to request a copy with a new name remoteResource.copyTo(destRemoteFolder, destName); } } catch (IOException ex) { throw new RuntimeException(ex); } catch (HttpException ex) { throw new RuntimeException(ex); } catch (NotFoundException ex) { throw new BadRequestException("Remote resource does not exist", ex); } }
public Long getContentLength( Request request ) throws BadRequestException { Long l = request.getContentLengthHeader(); if( l == null ) { String s = request.getRequestHeader( Request.Header.X_EXPECTED_ENTITY_LENGTH ); if( s != null && s.length() > 0 ) { log.debug( "no content-length given, but founhd non-standard length header: " + s ); try { l = Long.parseLong( s ); } catch( NumberFormatException e ) { throw new BadRequestException( null, "invalid length for header: " + Request.Header.X_EXPECTED_ENTITY_LENGTH.code + ". value is: " + s ); } } } return l; }
public String processForm( Map<String, String> parameters, Map<String, FileItem> files ) throws BadRequestException, NotAuthorizedException { try { CollectionResource col = wrapped.createCollection( parameters.get( "name" ) ); if( eventManager != null ) { eventManager.fireEvent( new NewFolderEvent( col ) ); } return null; } catch( ConflictException ex ) { throw new BadRequestException( wrapped, "A conflict occured. The folder might already exist" ); } }