use of java.net.URISyntaxException in project blueocean-plugin by jenkinsci.
the class CredentialsUtils method generateDomainSpecifications.
public static List<DomainSpecification> generateDomainSpecifications(@Nullable String uriStr) {
if (StringUtils.isBlank(uriStr)) {
return Collections.emptyList();
}
List<DomainSpecification> domainSpecifications = new ArrayList<>();
try {
URI uri = new URI(uriStr);
// XXX: UriRequirementBuilder.fromUri() maps "" path to "/", so need to take care of it here
String path = uri.getRawPath() == null ? null : (uri.getRawPath().trim().isEmpty() ? "/" : uri.getRawPath());
domainSpecifications.add(new PathSpecification(path, "", false));
if (uri.getPort() != -1) {
domainSpecifications.add(new HostnamePortSpecification(uri.getHost() + ":" + uri.getPort(), null));
} else {
domainSpecifications.add(new HostnameSpecification(uri.getHost(), null));
}
domainSpecifications.add(new SchemeSpecification(uri.getScheme()));
} catch (URISyntaxException e) {
// for now, we are returning empty list to match with URIRequirementBuilder.fromUri()
return domainSpecifications;
}
return Collections.emptyList();
}
use of java.net.URISyntaxException in project jersey by jersey.
the class SimpleBeanWithJustOneAttributeAndValue method createTestInstance.
public static Object createTestInstance() {
SimpleBeanWithJustOneAttributeAndValue instance = new SimpleBeanWithJustOneAttributeAndValue();
try {
instance.uri = new URI("http://localhost:8080/jedna/bedna/");
instance.value = "characters";
} catch (URISyntaxException ex) {
Logger.getLogger(SimpleBeanWithJustOneAttributeAndValue.class.getName()).log(Level.SEVERE, null, ex);
}
return instance;
}
use of java.net.URISyntaxException in project k-9 by k9mail.
the class ImapStoreUriDecoder method decode.
/**
* Decodes an ImapStore URI.
*
* <p>Possible forms:</p>
* <pre>
* imap://auth:user:password@server:port ConnectionSecurity.NONE
* imap+tls+://auth:user:password@server:port ConnectionSecurity.STARTTLS_REQUIRED
* imap+ssl+://auth:user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED
* </pre>
*
* NOTE: this method expects the userinfo part of the uri to be encoded twice, due to a bug in
* {@link ImapStoreUriCreator#create(ServerSettings)}.
*
* @param uri the store uri.
*/
public static ImapStoreSettings decode(String uri) {
String host;
int port;
ConnectionSecurity connectionSecurity;
AuthType authenticationType = null;
String username = null;
String password = null;
String clientCertificateAlias = null;
String pathPrefix = null;
boolean autoDetectNamespace = true;
URI imapUri;
try {
imapUri = new URI(uri);
} catch (URISyntaxException use) {
throw new IllegalArgumentException("Invalid ImapStore URI", use);
}
String scheme = imapUri.getScheme();
/*
* Currently available schemes are:
* imap
* imap+tls+
* imap+ssl+
*
* The following are obsolete schemes that may be found in pre-existing
* settings from earlier versions or that may be found when imported. We
* continue to recognize them and re-map them appropriately:
* imap+tls
* imap+ssl
*/
if (scheme.equals("imap")) {
connectionSecurity = ConnectionSecurity.NONE;
port = Type.IMAP.defaultPort;
} else if (scheme.startsWith("imap+tls")) {
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
port = Type.IMAP.defaultPort;
} else if (scheme.startsWith("imap+ssl")) {
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
port = Type.IMAP.defaultTlsPort;
} else {
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
}
host = imapUri.getHost();
if (imapUri.getPort() != -1) {
port = imapUri.getPort();
}
if (imapUri.getUserInfo() != null) {
String userinfo = imapUri.getUserInfo();
String[] userInfoParts = userinfo.split(":");
if (userinfo.endsWith(":")) {
// Or XOAUTH2 where it's a valid config - XOAUTH:username:
if (userInfoParts.length > 1) {
authenticationType = AuthType.valueOf(userInfoParts[0]);
username = decodeUtf8(userInfoParts[1]);
} else {
authenticationType = AuthType.PLAIN;
username = decodeUtf8(userInfoParts[0]);
}
} else if (userInfoParts.length == 2) {
// Old/standard style of encoding - PLAIN auth only:
// username:password
authenticationType = AuthType.PLAIN;
username = decodeUtf8(userInfoParts[0]);
password = decodeUtf8(userInfoParts[1]);
} else if (userInfoParts.length == 3) {
// Standard encoding
// PLAIN:username:password
// EXTERNAL:username:certAlias
authenticationType = AuthType.valueOf(userInfoParts[0]);
username = decodeUtf8(userInfoParts[1]);
if (AuthType.EXTERNAL == authenticationType) {
clientCertificateAlias = decodeUtf8(userInfoParts[2]);
} else {
password = decodeUtf8(userInfoParts[2]);
}
}
}
String path = imapUri.getPath();
if (path != null && path.length() > 1) {
// Strip off the leading "/"
String cleanPath = path.substring(1);
if (cleanPath.length() >= 2 && cleanPath.charAt(1) == '|') {
autoDetectNamespace = cleanPath.charAt(0) == '1';
if (!autoDetectNamespace) {
pathPrefix = cleanPath.substring(2);
}
} else {
if (cleanPath.length() > 0) {
pathPrefix = cleanPath;
autoDetectNamespace = false;
}
}
}
return new ImapStoreSettings(host, port, connectionSecurity, authenticationType, username, password, clientCertificateAlias, autoDetectNamespace, pathPrefix);
}
use of java.net.URISyntaxException in project k-9 by k9mail.
the class WebDavStoreUriDecoder method decode.
/**
* Decodes a WebDavStore URI.
* <p/>
* <p>Possible forms:</p>
* <pre>
* webdav://user:password@server:port ConnectionSecurity.NONE
* webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED
* </pre>
*/
public static WebDavStoreSettings decode(String uri) {
String host;
int port;
ConnectionSecurity connectionSecurity;
String username = null;
String password = null;
String alias = null;
String path = null;
String authPath = null;
String mailboxPath = null;
URI webDavUri;
try {
webDavUri = new URI(uri);
} catch (URISyntaxException use) {
throw new IllegalArgumentException("Invalid WebDavStore URI", use);
}
String scheme = webDavUri.getScheme();
/*
* Currently available schemes are:
* webdav
* webdav+ssl+
*
* The following are obsolete schemes that may be found in pre-existing
* settings from earlier versions or that may be found when imported. We
* continue to recognize them and re-map them appropriately:
* webdav+tls
* webdav+tls+
* webdav+ssl
*/
if (scheme.equals("webdav")) {
connectionSecurity = ConnectionSecurity.NONE;
} else if (scheme.startsWith("webdav+")) {
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
} else {
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
}
host = webDavUri.getHost();
if (host.startsWith("http")) {
String[] hostParts = host.split("://", 2);
if (hostParts.length > 1) {
host = hostParts[1];
}
}
port = webDavUri.getPort();
String userInfo = webDavUri.getUserInfo();
if (userInfo != null) {
String[] userInfoParts = userInfo.split(":");
username = decodeUtf8(userInfoParts[0]);
String[] userParts = username.split("\\\\", 2);
if (userParts.length > 1) {
alias = userParts[1];
} else {
alias = username;
}
if (userInfoParts.length > 1) {
password = decodeUtf8(userInfoParts[1]);
}
}
String[] pathParts = webDavUri.getPath().split("\\|");
for (int i = 0, count = pathParts.length; i < count; i++) {
if (i == 0) {
if (pathParts[0] != null && pathParts[0].length() > 1) {
path = pathParts[0];
}
} else if (i == 1) {
if (pathParts[1] != null && pathParts[1].length() > 1) {
authPath = pathParts[1];
}
} else if (i == 2) {
if (pathParts[2] != null && pathParts[2].length() > 1) {
mailboxPath = pathParts[2];
}
}
}
return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, null, alias, path, authPath, mailboxPath);
}
use of java.net.URISyntaxException in project jna by java-native-access.
the class Native method extractFromResourcePath.
/** Attempt to extract a native library from the resource path using the
* given class loader.
* @param name Base name of native library to extract. May also be an
* absolute resource path (i.e. starts with "/"), in which case the
* no transformations of the library name are performed. If only the base
* name is given, the resource path is attempted both with and without
* {@link Platform#RESOURCE_PREFIX}, after mapping the library name via
* {@link NativeLibrary#mapSharedLibraryName(String)}.
* @param loader Class loader to use to load resources
* @return File indicating extracted resource on disk
* @throws IOException if resource not found
*/
public static File extractFromResourcePath(String name, ClassLoader loader) throws IOException {
final boolean DEBUG = DEBUG_LOAD || (DEBUG_JNA_LOAD && name.indexOf("jnidispatch") != -1);
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader();
// Context class loader is not guaranteed to be set
if (loader == null) {
loader = Native.class.getClassLoader();
}
}
if (DEBUG) {
System.out.println("Looking in classpath from " + loader + " for " + name);
}
String libname = name.startsWith("/") ? name : NativeLibrary.mapSharedLibraryName(name);
String resourcePath = name.startsWith("/") ? name : Platform.RESOURCE_PREFIX + "/" + libname;
if (resourcePath.startsWith("/")) {
resourcePath = resourcePath.substring(1);
}
URL url = loader.getResource(resourcePath);
if (url == null && resourcePath.startsWith(Platform.RESOURCE_PREFIX)) {
// If not found with the standard resource prefix, try without it
url = loader.getResource(libname);
}
if (url == null) {
String path = System.getProperty("java.class.path");
if (loader instanceof URLClassLoader) {
path = Arrays.asList(((URLClassLoader) loader).getURLs()).toString();
}
throw new IOException("Native library (" + resourcePath + ") not found in resource path (" + path + ")");
}
if (DEBUG) {
System.out.println("Found library resource at " + url);
}
File lib = null;
if (url.getProtocol().toLowerCase().equals("file")) {
try {
lib = new File(new URI(url.toString()));
} catch (URISyntaxException e) {
lib = new File(url.getPath());
}
if (DEBUG) {
System.out.println("Looking in " + lib.getAbsolutePath());
}
if (!lib.exists()) {
throw new IOException("File URL " + url + " could not be properly decoded");
}
} else if (!Boolean.getBoolean("jna.nounpack")) {
InputStream is = loader.getResourceAsStream(resourcePath);
if (is == null) {
throw new IOException("Can't obtain InputStream for " + resourcePath);
}
FileOutputStream fos = null;
try {
// Suffix is required on windows, or library fails to load
// Let Java pick the suffix, except on windows, to avoid
// problems with Web Start.
File dir = getTempDir();
lib = File.createTempFile(JNA_TMPLIB_PREFIX, Platform.isWindows() ? ".dll" : null, dir);
if (!Boolean.getBoolean("jnidispatch.preserve")) {
lib.deleteOnExit();
}
fos = new FileOutputStream(lib);
int count;
byte[] buf = new byte[1024];
while ((count = is.read(buf, 0, buf.length)) > 0) {
fos.write(buf, 0, count);
}
} catch (IOException e) {
throw new IOException("Failed to create temporary file for " + name + " library: " + e.getMessage());
} finally {
try {
is.close();
} catch (IOException e) {
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
return lib;
}
Aggregations