Search in sources :

Example 21 with URISyntaxException

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());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException)

Example 22 with URISyntaxException

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);
        }
    }
}
Also used : MethodRef(org.eclipse.jdt.core.dom.MethodRef) SimpleName(org.eclipse.jdt.core.dom.SimpleName) MethodRefParameter(org.eclipse.jdt.core.dom.MethodRefParameter) MemberRef(org.eclipse.jdt.core.dom.MemberRef) URISyntaxException(java.net.URISyntaxException) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name)

Example 23 with URISyntaxException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 24 with URISyntaxException

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());
    }
}
Also used : CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with URISyntaxException

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);
    }
}
Also used : Matcher(java.util.regex.Matcher) HumanReadableException(com.facebook.buck.util.HumanReadableException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

URISyntaxException (java.net.URISyntaxException)4043 URI (java.net.URI)2496 IOException (java.io.IOException)1273 File (java.io.File)716 URL (java.net.URL)702 ArrayList (java.util.ArrayList)407 Test (org.junit.Test)274 MalformedURLException (java.net.MalformedURLException)270 InputStream (java.io.InputStream)224 HashMap (java.util.HashMap)212 Response (javax.ws.rs.core.Response)194 Test (org.testng.annotations.Test)175 Parameters (org.testng.annotations.Parameters)166 Builder (javax.ws.rs.client.Invocation.Builder)165 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)165 Map (java.util.Map)162 StorageException (com.microsoft.azure.storage.StorageException)142 Path (java.nio.file.Path)141 URIBuilder (org.apache.http.client.utils.URIBuilder)140 List (java.util.List)125