Refine search
/** * Checks whether directory used in ftp/ftps/sftp endpoint URI is relative. * Absolute path will be converted to relative path and a WARN will be printed. * @see <a href="http://camel.apache.org/ftp2.html">FTP/SFTP/FTPS Component</a> * @param ftpComponent * @param configuration */ public static void ensureRelativeFtpDirectory(Component ftpComponent, RemoteFileConfiguration configuration) { if (FileUtil.hasLeadingSeparator(configuration.getDirectoryName())) { String relativePath = FileUtil.stripLeadingSeparator(configuration.getDirectoryName()); LOG.warn(String.format("%s doesn't support absolute paths, \"%s\" will be converted to \"%s\". " + "After Camel 2.16, absolute paths will be invalid.", ftpComponent.getClass().getSimpleName(), configuration.getDirectoryName(), relativePath)); configuration.setDirectory(relativePath); configuration.setDirectoryName(relativePath); } }
private boolean buildDirectoryChunks(String dirName) throws IOException { final StringBuilder sb = new StringBuilder(dirName.length()); final String[] dirs = dirName.split("/|\\\\"); boolean success = false; for (String dir : dirs) { sb.append(dir).append('/'); // must normalize the directory name String directory = endpoint.getConfiguration().normalizePath(sb.toString()); // do not try to build root folder (/ or \) if (!(directory.equals("/") || directory.equals("\\"))) { log.trace("Trying to build remote directory by chunk: {}", directory); // while creating directory string if directory results in // trailing slash, remove it not necessary directory = FileUtil.stripTrailingSeparator(directory); success = client.makeDirectory(directory); } } return success; }
@Override public Enumeration<URL> loadAllResourcesAsURL(String uri) { ObjectHelper.notEmpty(uri, "uri"); Vector<URL> answer = new Vector<>(); try { String resolvedName = resolveUriPath(uri); Enumeration<URL> e = bundleContext.getBundle().getResources(resolvedName); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } String path = FileUtil.onlyPath(uri); String name = FileUtil.stripPath(uri); if (path != null && name != null) { for (Bundle bundle : bundleContext.getBundles()) { LOG.trace("Finding all entries in path: {} with pattern: {}", path, name); e = bundle.findEntries(path, name, false); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } } } } catch (IOException e) { throw new RuntimeException("Cannot load resource: " + uri, e); } return answer.elements(); }
private Map<String, List<CamelNodeDetails>> groupAnonymousRoutesByClassName(List<CamelNodeDetails> anonymousRouteTrees) { Map<String, List<CamelNodeDetails>> answer = new LinkedHashMap<>(); for (CamelNodeDetails t : anonymousRouteTrees) { String fileName = asRelativeFile(t.getFileName()); String className = FileUtil.stripExt(FileUtil.stripPath(fileName)); List<CamelNodeDetails> list = answer.computeIfAbsent(className, k -> new ArrayList<>()); list.add(t); } return answer; }
InputStream is = null; ByteArrayOutputStream baos = null; Object obj = exchange.getIn().getMandatoryBody(); PutObjectRequest putObjectRequest = null; is = new FileInputStream(filePayload); } else { is = exchange.getIn().getMandatoryBody(InputStream.class); baos = determineLengthInputStream(is); objectMetadata.setContentLength(baos.size()); String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class); if (cannedAcl != null) { CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl); if (ObjectHelper.isNotEmpty(getConfiguration().getAwsKMSKeyId())) { keyManagementParams = new SSEAwsKeyManagementParams(getConfiguration().getAwsKMSKeyId()); } else { FileUtil.deleteFile(filePayload);
File local = new File(endpoint.getLocalWorkDirectory()); OutputStream os; GenericFile<ChannelSftp.LsEntry> file = (GenericFile<ChannelSftp.LsEntry>)exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE); ObjectHelper.notNull(file, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set"); try { if (!FileUtil.deleteFile(temp)) { throw new GenericFileOperationFailedException("Cannot delete existing local work file: " + temp); if (!FileUtil.deleteFile(local)) { throw new GenericFileOperationFailedException("Cannot delete existing local work file: " + local); exchange.getIn().setHeader(Exchange.FILE_LOCAL_WORK_PATH, local.getPath()); } catch (Exception e) { throw new GenericFileOperationFailedException("Cannot create new local work file: " + local); String path = FileUtil.onlyPath(name); if (path != null) { changeCurrentDirectory(path); remoteName = FileUtil.stripPath(name); boolean deleted = FileUtil.deleteFile(temp); if (!deleted) { LOG.warn("Error occurred during retrieving file: " + name + " to local directory. Cannot delete local work file: " + temp); if (!FileUtil.renameFile(temp, local, false)) { throw new GenericFileOperationFailedException("Cannot rename local work file from: " + temp + " to: " + local);
boolean result; try { GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE); ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set"); String path = FileUtil.onlyPath(name); if (path != null) { changeCurrentDirectory(path); remoteName = FileUtil.stripPath(name); InputStream is = client.retrieveFileStream(remoteName); target.setBody(is); exchange.getIn().setHeader(RemoteFileComponent.REMOTE_FILE_INPUT_STREAM, is); result = true; } else { exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE, client.getReplyCode()); exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING, client.getReplyString());
String onlyName = FileUtil.stripPath(fileName); dummy.getIn().setHeader(Exchange.FILE_NAME, fileName); dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName); dummy.getIn().setHeader(Exchange.FILE_PARENT, parent); to = FileUtil.stripLeadingSeparator(to); if (ObjectHelper.isEmpty(to)) { throw new GenericFileOperationFailedException("moveExisting evaluated as empty String, cannot move existing file: " + fileName); String dir = FileUtil.onlyPath(to); if (dir != null) {
path = FileUtil.stripLeadingSeparator(path); if (ObjectHelper.isNotEmpty(contextPath)) { contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) { path = contextPath + "/" + path; if (ObjectHelper.isEmpty(host)) { if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) { host = "0.0.0.0";
tarFile = FileUtil.createTempFile(this.filePrefix, this.fileSuffix, parentDir); LOG.trace("Created temporary file: {}", tarFile); } catch (IOException e) { answer.addOnCompletion(new DeleteTarFileOnCompletion(tarFile)); } else { tarFile = oldExchange.getIn().getBody(File.class); Object body = newExchange.getIn().getBody(); if (body instanceof WrappedFile) { body = ((WrappedFile) body).getFile();
dirName = FileUtil.stripTrailingSeparator(dirName); try { if (isStepwise()) { dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath; operations.changeCurrentDirectory(dir); } else {
basePath = FileUtil.stripLeadingSeparator(basePath); uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate); if (!ObjectHelper.isEmpty(basePath)) { url += "/" + basePath; if (!ObjectHelper.isEmpty(uriTemplate)) { url += "/" + uriTemplate;
public synchronized void changeCurrentDirectory(String path) throws GenericFileOperationFailedException { LOG.trace("changeCurrentDirectory({})", path); if (ObjectHelper.isEmpty(path)) { return; path = FileUtil.compactPath(path, separatorChar); if (LOG.isTraceEnabled()) { LOG.trace("Compacted path: {} -> {} using separator: {}", before, path, separatorChar); if (FileUtil.hasLeadingSeparator(path)) {
private RemoteFile<SftpRemoteFile> asRemoteFile(String absolutePath, SftpRemoteFile file, String charset) { RemoteFile<SftpRemoteFile> answer = new RemoteFile<>(); answer.setCharset(charset); answer.setEndpointPath(endpointPath); answer.setFile(file); answer.setFileNameOnly(file.getFilename()); answer.setFileLength(file.getFileLength()); answer.setLastModified(file.getLastModified()); answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost()); answer.setDirectory(file.isDirectory()); // absolute or relative path boolean absolute = FileUtil.hasLeadingSeparator(absolutePath); answer.setAbsolute(absolute); // create a pseudo absolute name String dir = FileUtil.stripTrailingSeparator(absolutePath); String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename()); // if absolute start with a leading separator otherwise let it be relative if (absolute) { absoluteFileName = "/" + absoluteFileName; } answer.setAbsoluteFilePath(absoluteFileName); // the relative filename, skip the leading endpoint configured path String relativePath = ObjectHelper.after(absoluteFileName, endpointPath); // skip trailing / relativePath = FileUtil.stripLeadingSeparator(relativePath); answer.setRelativeFilePath(relativePath); // the file name should be the relative path answer.setFileName(answer.getRelativeFilePath()); return answer; }
String directory = FileUtil.onlyPath(name); if (directory == null) { String onlyName = FileUtil.stripPath(name); String existing = entry.getFilename(); LOG.trace("Existing file: {}, target file: {}", existing, name); existing = FileUtil.stripPath(existing); if (existing != null && existing.equals(onlyName)) { return true;
public static String extractDirNameFromAbsolutePath(String path) { // default is unix so try with '/' // otherwise force File.separator if (path.endsWith("/") || path.endsWith("\\")) { path = path.substring(0, path.length() - 1); } return FileUtil.stripPath(path); }
@Override public void onComplete(Exchange exchange) { FileUtil.deleteFile(this.fileToDelete); } }
/** * Helper operation used to remove relative path notation from * resources. Most critical for resources on the Classpath * as resource loaders will not resolve the relative paths correctly. * * @param name the name of the resource to load * @return the modified or unmodified string if there were no changes */ private static String resolveUriPath(String name) { // compact the path and use / as separator as that's used for loading resources on the classpath return FileUtil.compactPath(name, '/'); }
path = FileUtil.stripLeadingSeparator(path);
protected void populateAttachments(HttpServletRequest request, HttpMessage message) { // check if there is multipart files, if so will put it into DataHandler Enumeration<?> names = request.getAttributeNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Object object = request.getAttribute(name); LOG.trace("HTTP attachment {} = {}", name, object); if (object instanceof File) { String fileName = request.getParameter(name); // is the file name accepted boolean accepted = true; if (fileNameExtWhitelist != null) { String ext = FileUtil.onlyExt(fileName); if (ext != null) { ext = ext.toLowerCase(Locale.US); fileNameExtWhitelist = fileNameExtWhitelist.toLowerCase(Locale.US); if (!fileNameExtWhitelist.equals("*") && !fileNameExtWhitelist.contains(ext)) { accepted = false; } } } if (accepted) { message.addAttachment(fileName, new DataHandler(new CamelFileDataSource((File) object, fileName))); } else { LOG.debug("Cannot add file as attachment: {} because the file is not accepted according to fileNameExtWhitelist: {}", fileName, fileNameExtWhitelist); } } } }