List of usage examples for org.apache.commons.vfs.provider URLFileName getHostName
public String getHostName()
From source file:org.docx4all.util.AuthenticationUtil.java
public final static int getAuthorisationStatus(WebdavFileObject fo) throws FileSystemException { int status = 401; //unauthorised and retry. org.apache.webdav.lib.methods.OptionsMethod optionsMethod = null; try {/* w w w. j a v a 2 s. c om*/ String urlCharset = WebdavFileSystemConfigBuilder.getInstance() .getUrlCharset(fo.getFileSystem().getFileSystemOptions()); URLFileName urlFileName = (URLFileName) fo.getName(); optionsMethod = new org.apache.webdav.lib.methods.OptionsMethod( urlFileName.getPathQueryEncoded(urlCharset)); optionsMethod.setMethodRetryHandler(WebdavMethodRetryHandler.getInstance()); optionsMethod.setFollowRedirects(true); char[] username = null; if (urlFileName.getUserName() != null) { username = urlFileName.getUserName().toCharArray(); } char[] password = null; if (urlFileName.getPassword() != null) { password = urlFileName.getPassword().toCharArray(); } WebdavClientFactory factory = new WebdavClientFactory(); HttpClient client = factory.createConnection(urlFileName.getHostName(), urlFileName.getPort(), username, password, fo.getFileSystem().getFileSystemOptions()); status = client.executeMethod(optionsMethod); } catch (Exception exc) { throw new FileSystemException("Cannot get authorisation status", exc); } finally { if (optionsMethod != null) { optionsMethod.releaseConnection(); } } return status; }
From source file:org.pentaho.di.core.vfs.configuration.KettleSftpFileSystemConfigBuilder.java
/** * Publicly expose a generic way to set parameters *//* w ww .jav a 2 s .c om*/ @Override public void setParameter(FileSystemOptions opts, String name, String value, String fullParameterName, String vfsUrl) throws IOException { if (!fullParameterName.startsWith("vfs.sftp")) { // This is not an SFTP parameter. Delegate to the generic handler super.setParameter(opts, name, value, fullParameterName, vfsUrl); } else { // Check for the presence of a host in the full variable name try { // Parse server name from vfsFilename FileNameParser sftpFilenameParser = SftpFileNameParser.getInstance(); URLFileName file = (URLFileName) sftpFilenameParser.parseUri(null, null, vfsUrl); if (!parameterContainsHost(fullParameterName) || fullParameterName.endsWith(file.getHostName())) { // Match special cases for parameter names if (name.equalsIgnoreCase("AuthKeyPassphrase")) { setParam(opts, UserInfo.class.getName(), new PentahoUserInfo(value)); } else if (name.equals("identity")) { File[] identities = (File[]) this.getParam(opts, "identities"); if (identities == null) { identities = new File[] { new File(value) }; } else { // Copy, in a Java 5 friendly manner, identities into a larger array File[] temp = new File[identities.length + 1]; System.arraycopy(identities, 0, temp, 0, identities.length); identities = temp; identities[identities.length - 1] = new File(value); } setParam(opts, "identities", identities); } else { setParam(opts, name, value); } } else { // No host match found log.logDebug("No host match found for: " + fullParameterName); } } catch (IOException e) { log.logError("Failed to set VFS parameter: [" + fullParameterName + "] " + value, e); } } }
From source file:org.pentaho.s3.vfs.S3FileNameParser.java
@Override public FileName parseUri(VfsComponentContext vfsComponentContext, FileName fileName, String s) throws FileSystemException { if (fileName == null) { s = encodeAccessKeys(s);/*from w w w.j a v a 2s.com*/ } URLFileName name = (URLFileName) super.parseUri(vfsComponentContext, fileName, s); FileType type = name.getType(); /* There is a problem with parsing bucket uri which has not char "/" at the end. * In this case UrlParser parse URI and return filename with type file. * As S3 does not allow to store files without buckets - so bucket is always a folder */ if (FileType.FILE.equals(type) && name.getPath().split("/").length == 2) { type = FileType.FOLDER; } String user = name.getUserName(); String password = name.getPassword(); return new S3FileName(name.getScheme(), name.getHostName(), name.getPort(), getDefaultPort(), user, password, name.getPath(), type, name.getQueryString()); }