use of java.net.URISyntaxException in project elasticsearch by elastic.
the class SyncResponseListenerTests method testExceptionIsWrapped.
public void testExceptionIsWrapped() throws Exception {
RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
//we just need any checked exception
URISyntaxException exception = new URISyntaxException("test", "test");
syncResponseListener.onFailure(exception);
try {
syncResponseListener.get();
fail("get should have failed");
} catch (RuntimeException e) {
assertEquals("error while performing request", e.getMessage());
assertSame(exception, e.getCause());
}
}
use of java.net.URISyntaxException in project che by eclipse.
the class JavadocContentAccess2 method handleLink.
private void handleLink(List<? extends ASTNode> fragments) {
//TODO: Javadoc shortens type names to minimal length according to context
int fs = fragments.size();
if (fs > 0) {
Object first = fragments.get(0);
String refTypeName = null;
String refMemberName = null;
String[] refMethodParamTypes = null;
String[] refMethodParamNames = null;
if (first instanceof Name) {
Name name = (Name) first;
refTypeName = name.getFullyQualifiedName();
} else if (first instanceof MemberRef) {
MemberRef memberRef = (MemberRef) first;
Name qualifier = memberRef.getQualifier();
//$NON-NLS-1$
refTypeName = qualifier == null ? "" : qualifier.getFullyQualifiedName();
refMemberName = memberRef.getName().getIdentifier();
} else if (first instanceof MethodRef) {
MethodRef methodRef = (MethodRef) first;
Name qualifier = methodRef.getQualifier();
//$NON-NLS-1$
refTypeName = qualifier == null ? "" : qualifier.getFullyQualifiedName();
refMemberName = methodRef.getName().getIdentifier();
List<MethodRefParameter> params = methodRef.parameters();
int ps = params.size();
refMethodParamTypes = new String[ps];
refMethodParamNames = new String[ps];
for (int i = 0; i < ps; i++) {
MethodRefParameter param = params.get(i);
refMethodParamTypes[i] = ASTNodes.asString(param.getType());
SimpleName paramName = param.getName();
if (paramName != null)
refMethodParamNames[i] = paramName.getIdentifier();
}
}
if (refTypeName != null) {
//$NON-NLS-1$
fBuf.append("<a href='");
try {
String scheme = urlPrefix;
String uri = JavaElementLinks.createURI(scheme, fElement, refTypeName, refMemberName, refMethodParamTypes);
fBuf.append(uri);
} catch (URISyntaxException e) {
LOG.error(e.getMessage(), e);
}
//$NON-NLS-1$
fBuf.append("'>");
if (fs > 1 && !(fs == 2 && isWhitespaceTextElement(fragments.get(1)))) {
handleContentElements(fragments.subList(1, fs), true);
} else {
fBuf.append(refTypeName);
if (refMemberName != null) {
if (refTypeName.length() > 0) {
fBuf.append('.');
}
fBuf.append(refMemberName);
if (refMethodParamTypes != null) {
fBuf.append('(');
for (int i = 0; i < refMethodParamTypes.length; i++) {
String pType = refMethodParamTypes[i];
fBuf.append(pType);
String pName = refMethodParamNames[i];
if (pName != null) {
fBuf.append(' ').append(pName);
}
if (i < refMethodParamTypes.length - 1) {
//$NON-NLS-1$
fBuf.append(", ");
}
}
fBuf.append(')');
}
}
}
//$NON-NLS-1$
fBuf.append("</a>");
} else {
handleContentElements(fragments);
}
}
}
use of java.net.URISyntaxException in project zeppelin by apache.
the class ZeppelinHubRealm method isZeppelinHubUrlValid.
/**
* Perform a Simple URL check by using <code>URI(url).toURL()</code>.
* If the url is not valid, the try-catch condition will catch the exceptions and return false,
* otherwise true will be returned.
*
* @param url
* @return
*/
protected boolean isZeppelinHubUrlValid(String url) {
boolean valid;
try {
new URI(url).toURL();
valid = true;
} catch (URISyntaxException | MalformedURLException e) {
LOG.error("Zeppelinhub url is not valid, default ZeppelinHub url will be used.", e);
valid = false;
}
return valid;
}
use of java.net.URISyntaxException in project checkstyle by checkstyle.
the class CommonUtilsTest method testLoadSuppressionsUriSyntaxException.
@Test
@PrepareForTest({ CommonUtils.class, CommonUtilsTest.class })
@SuppressWarnings("unchecked")
public void testLoadSuppressionsUriSyntaxException() throws Exception {
final URL configUrl = mock(URL.class);
when(configUrl.toURI()).thenThrow(URISyntaxException.class);
mockStatic(CommonUtils.class, Mockito.CALLS_REAL_METHODS);
final String fileName = "suppressions_none.xml";
when(CommonUtils.class.getResource(fileName)).thenReturn(configUrl);
try {
CommonUtils.getUriByFilename(fileName);
fail("Exception is expected");
} catch (CheckstyleException ex) {
assertTrue(ex.getCause() instanceof URISyntaxException);
assertEquals("Unable to find: " + fileName, ex.getMessage());
}
}
use of java.net.URISyntaxException in project buck by facebook.
the class MavenUrlDecoder method toHttpUrl.
public static URI toHttpUrl(Optional<String> mavenRepo, URI uri) {
Preconditions.checkArgument("mvn".equals(uri.getScheme()), "URI must start with mvn: " + uri);
Preconditions.checkArgument(mavenRepo.isPresent(), "You must specify the maven repo in the \"download->maven_repo\" section of your " + ".buckconfig");
String repo = mavenRepo.get();
if (!repo.endsWith("/")) {
repo += "/";
}
Matcher matcher = URL_PATTERN.matcher(uri.getSchemeSpecificPart());
if (!matcher.matches()) {
throw new HumanReadableException("Unable to parse: " + uri);
}
String host = matcher.group("host");
if (Strings.isNullOrEmpty(host)) {
host = repo;
}
String group = matcher.group("group").replace('.', '/');
String artifactId = matcher.group("id");
String type = matcher.group("type");
String version = matcher.group("version");
Optional<String> classifier = Optional.ofNullable(matcher.group("classifier"));
if (!host.endsWith("/")) {
host += "/";
}
try {
String plainUri = String.format("%s%s/%s/%s/%s", host, group, artifactId, version, fileNameFor(artifactId, version, type, classifier));
URI generated = new URI(plainUri);
if ("https".equals(generated.getScheme()) || "http".equals(generated.getScheme())) {
return generated;
}
throw new HumanReadableException("Can only download maven artifacts over HTTP or HTTPS: %s", generated);
} catch (URISyntaxException e) {
throw new HumanReadableException("Unable to parse URL: " + uri);
}
}
Aggregations