Example usage for java.net URISyntaxException URISyntaxException

List of usage examples for java.net URISyntaxException URISyntaxException

Introduction

In this page you can find the example usage for java.net URISyntaxException URISyntaxException.

Prototype

public URISyntaxException(String input, String reason) 

Source Link

Document

Constructs an instance from the given input string and reason.

Usage

From source file:URISupport.java

public static Map<String, String> parseQuery(String uri) throws URISyntaxException {
    try {//from  w w  w. ja v  a2  s .  c  o  m
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    rc.put(parameters[i], null);
                }
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:org.apache.hadoop.hive.ql.session.DependencyResolver.java

/**
 *
 * @param uri//w  w w  .j a  v  a 2s .  co  m
 * @return List of URIs of downloaded jars
 * @throws URISyntaxException
 * @throws IOException
 */
public List<URI> downloadDependencies(URI uri) throws URISyntaxException, IOException {
    Map<String, Object> dependencyMap = new HashMap<String, Object>();
    String authority = uri.getAuthority();
    if (authority == null) {
        throw new URISyntaxException(authority, "Invalid url: Expected 'org:module:version', found null");
    }
    String[] authorityTokens = authority.toLowerCase().split(":");

    if (authorityTokens.length != 3) {
        throw new URISyntaxException(authority,
                "Invalid url: Expected 'org:module:version', found " + authority);
    }

    dependencyMap.put("org", authorityTokens[0]);
    dependencyMap.put("module", authorityTokens[1]);
    dependencyMap.put("version", authorityTokens[2]);
    Map<String, Object> queryMap = parseQueryString(uri.getQuery());
    if (queryMap != null) {
        dependencyMap.putAll(queryMap);
    }
    return grab(dependencyMap);
}

From source file:uk.co.flax.biosolr.ontology.core.owl.OWLOntologyHelper.java

/**
 * Construct a new ontology helper instance.
 *
 * @param ontologyUri the URI giving the location of the ontology.
 * @param config the ontology configuration, containing the property URIs
 * for labels, synonyms, etc.//w  w w  . j a  v  a  2  s .  c  om
 * @throws URISyntaxException if the URI cannot be parsed.
 */
public OWLOntologyHelper(URI ontologyUri, OWLOntologyConfiguration config) throws URISyntaxException {
    this.config = config;

    if (!ontologyUri.isAbsolute()) {
        // Try to read as a file from the resource path
        LOGGER.debug("Ontology URI {} is not absolute - loading from classpath", ontologyUri);
        URL fileUrl = this.getClass().getClassLoader().getResource(ontologyUri.toString());
        if (fileUrl != null) {
            ontologyUri = fileUrl.toURI();
        } else {
            throw new URISyntaxException(ontologyUri.toString(), "Could not build URL for file");
        }
    }

    this.dataManager = new OWLDataManager(ontologyUri);
}

From source file:pl.nask.hsn2.service.urlfollower.Link.java

public Link(String baseUrl, String relativeUrl, boolean enableIISdecode) throws URISyntaxException {
    decodeIIS = enableIISdecode;/*from   w  w  w .jav a 2 s  . c  om*/
    this.baseUrl = baseUrl;
    URI baseURI = new URI(format(baseUrl));
    if (!decodeIIS && IISEncDec.isIISencoded(relativeUrl)) {
        this.relativeUrl = relativeUrl;
        int i = relativeUrl.indexOf("%u");
        String rel = format(relativeUrl.substring(0, i));
        append = format(relativeUrl.substring(i));
        if (rel.length() == 0) {
            rel = "/";
        }
        absoluteUrl = URIUtils.resolve(baseURI, rel);
        return;
    } else if (decodeIIS && IISEncDec.isIISencoded(relativeUrl)) {
        this.relativeUrl = IISEncDec.convertToUTF8(format(relativeUrl));
    } else {
        this.relativeUrl = relativeUrl;
    }
    append = "";
    try {
        absoluteUrl = URIUtils.resolve(baseURI, format(this.relativeUrl));
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Error while processing URI", e);
        throw new URISyntaxException("Cannot convert to absolute URL: " + relativeUrl,
                e.getCause().getMessage());
    }
}

From source file:com.limegroup.gnutella.licenses.LicenseFactoryImpl.java

/** Gets a CC license URI from the given license string. */
private static URI getCCLicenseURI(String license) {
    license = license.toLowerCase(Locale.US);

    // find where the URL should begin.
    int verifyAt = license.indexOf(CCConstants.URL_INDICATOR);
    if (verifyAt == -1)
        return null;

    int urlStart = verifyAt + CCConstants.URL_INDICATOR.length();
    if (urlStart >= license.length())
        return null;

    String url = license.substring(urlStart).trim();
    URI uri = null;//from  w w w . j  a  v a2 s.c o m
    try {
        uri = URIUtils.toURI(url);

        // Make sure the scheme is HTTP.
        String scheme = uri.getScheme();
        if (scheme == null || !scheme.equalsIgnoreCase("http"))
            throw new URISyntaxException(uri.toString(), "Invalid scheme: " + scheme);
        // Make sure the scheme has some authority.
        String authority = uri.getAuthority();
        if (authority == null || authority.equals("") || authority.indexOf(' ') != -1)
            throw new URISyntaxException(uri.toString(), "Invalid authority: " + authority);

    } catch (URISyntaxException e) {
        //URIUtils.error(e);
        uri = null;
        LOG.error("Unable to create URI", e);
    }

    return uri;
}

From source file:org.apache.activemq.utils.uri.URISchema.java

public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides)
        throws URISyntaxException {
    try {/*  w w  w  .ja  va 2s  . c  o  m*/
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null && !uri.isEmpty()) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    rc.put(parameters[i], null);
                }
            }
        }

        if (propertyOverrides != null) {
            for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) {
                rc.put(entry.getKey(), entry.getValue());
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:org.jbpm.formbuilder.server.menu.GuvnorMenuServiceTest.java

private GuvnorMenuService createMockedService(final Class<?> exceptionType) {
    GuvnorMenuService service = new GuvnorMenuService() {
        @Override/*from   ww  w .  jav a  2  s.  c  o  m*/
        protected URL asURL(String path) throws URISyntaxException {
            if (exceptionType != null && exceptionType.equals(URISyntaxException.class))
                throw new URISyntaxException(path, "mocking");
            return super.asURL(path);
        }

        @Override
        protected Reader createReader(URL url) throws FileNotFoundException, IOException {
            if (exceptionType != null) {
                if (exceptionType.equals(FileNotFoundException.class))
                    throw new FileNotFoundException(url.toExternalForm());
                if (exceptionType.equals(IOException.class))
                    throw new IOException(url.toExternalForm());
                throw new NullPointerException();
            }
            return super.createReader(url);
        }

        @Override
        protected String readURL(URL url) throws FileNotFoundException, IOException {
            if (exceptionType != null) {
                if (exceptionType.equals(FileNotFoundException.class))
                    throw new FileNotFoundException(url.toExternalForm());
                if (exceptionType.equals(IOException.class))
                    throw new IOException(url.toExternalForm());
                throw new NullPointerException();
            }
            return super.readURL(url);
        }

        @Override
        protected void writeToURL(URL url, String json) throws FileNotFoundException, IOException {
            if (exceptionType != null) {
                if (exceptionType.equals(FileNotFoundException.class))
                    throw new FileNotFoundException(url.toExternalForm());
                if (exceptionType.equals(IOException.class))
                    throw new IOException(url.toExternalForm());
                throw new NullPointerException();
            }
            super.writeToURL(url, json);
        }
    };
    return service;
}

From source file:org.apache.activemq.artemis.utils.uri.URISchema.java

public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides)
        throws URISyntaxException {
    try {/*  www. java 2 s .c  o m*/
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null && !uri.isEmpty()) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    if (!parameters[i].trim().isEmpty()) {
                        rc.put(parameters[i], null);
                    }
                }
            }
        }

        if (propertyOverrides != null) {
            for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) {
                rc.put(entry.getKey(), entry.getValue());
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:uk.co.flax.biosolr.ontology.core.ols.OLSHttpClientTest.java

public static File getFile(String filepath) throws URISyntaxException {
    URL fileUrl = OLSHttpClientTest.class.getClassLoader().getResource(filepath);
    if (fileUrl == null) {
        throw new URISyntaxException(filepath, "Cannot build file URL");
    }//from   www .  j  ava 2 s . c om
    return new File(fileUrl.toURI());
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectEndServletTest.java

/**
 * Run servlet with invalid authentication response URI.
 * /*from  w ww.ja va2s .c  o m*/
 * @throws Exception
 */
@Test
public void testInvalidAuthnResponseUri() throws Exception {
    final MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.getSession().setAttribute(SocialUserOpenIdConnectStartServlet.SESSION_ATTR_FLOWKEY,
            conversationKey);
    final SocialUserOpenIdConnectContext suOidcCtx = Mockito.mock(SocialUserOpenIdConnectContext.class);
    Mockito.doThrow(new URISyntaxException("mockException", "mock")).when(suOidcCtx)
            .setAuthenticationResponseURI(httpRequest);
    httpRequest.getSession().setAttribute(SocialUserOpenIdConnectStartServlet.SESSION_ATTR_SUCTX, suOidcCtx);
    Assert.assertTrue(SocialUserOpenIdConnectStartServletTest.runService(servlet, httpRequest,
            new MockHttpServletResponse()));
}