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:com.funambol.LDAP.security.LDAPMailUserProvisioningOfficer.java

/**
 * return an URI from the server, eventually using a default protocol
 *//*  w ww .j av  a2 s .  c  o  m*/
protected URI getServerUri(String s, String proto) {
    URI u = null;
    String protocol;
    int port;
    try {
        if (s.indexOf(URL_SCHEME_SEPARATOR) < 0) {
            s = proto + URL_SCHEME_SEPARATOR + s;
        }
        u = new URI(s);
        protocol = (u.getSchemeSpecificPart() != null) ? u.getScheme() : proto;

        if (u.getPort() == -1) {
            if (PROTO_IMAP.equals(protocol)) {
                port = 143;
            } else if (PROTO_IMAPS.equals(protocol)) {
                port = 993;
            } else if (PROTO_SMTP.equals(protocol)) {
                port = 25;
            } else if (PROTO_SMTPS.equals(protocol)) {
                port = 465;
            } else if (PROTO_POP.equals(protocol)) {
                port = 110;
            } else if (PROTO_POPS.equals(protocol)) {
                port = 995;
            } else {
                throw new URISyntaxException(protocol, "Invalid protocol: " + protocol);
            }
            //            else {
            //               port = -1;
            //               if (log.isDebugEnabled()) {
            //                  log.debug("no protocol defined, an error will rise if no default protocol defined in DefaultMailServer.xml");
            //               }
            //            }
        } else {
            port = u.getPort();
        }
        u = new URI(protocol, null, u.getHost(), port, null, null, null);

    } catch (URISyntaxException e) {
        log.error("can't parse uri from string: " + s);
        e.printStackTrace();
    }
    return u;
}

From source file:org.cloudfoundry.identity.uaa.util.UaaTokenUtils.java

public static String constructTokenEndpointUrl(String issuer) throws URISyntaxException {
    try {//from   w w  w.j ava  2s  .co  m
        new URL(issuer);
    } catch (MalformedURLException x) {
        throw new URISyntaxException(issuer, x.getMessage());
    }
    URI uri = new URI(issuer);
    String hostToUse = uri.getHost();
    if (hasText(IdentityZoneHolder.get().getSubdomain())) {
        hostToUse = IdentityZoneHolder.get().getSubdomain() + "." + hostToUse;
    }
    return UriComponentsBuilder.fromUriString(issuer).host(hostToUse).pathSegment("oauth/token").build()
            .toUriString();
}

From source file:com.aol.advertising.qiao.util.CommonUtils.java

/**
 * Extends scheme to include 'classpath'.
 *
 * @param uriString/*  w w  w  .  ja v  a  2 s.c o  m*/
 * @return
 * @throws URISyntaxException
 * @throws IOException
 */
public static URL uriToURL(String uriString) throws URISyntaxException, IOException {
    URI uri = new URI(uriString);
    String scheme = uri.getScheme();
    if (scheme == null)
        throw new URISyntaxException(uriString, "Invalid URI syntax: missing scheme => " + uriString);

    if (scheme.equals("classpath")) {
        ClassPathResource res = new ClassPathResource(uri.getSchemeSpecificPart());
        return res.getURL();
    } else {
        return uri.toURL();
    }
}

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

private List<Map<String, String>> computeExcludeList(String excludeString) throws URISyntaxException {
    String excludes[] = excludeString.split(",");
    List<Map<String, String>> excludeList = new LinkedList<Map<String, String>>();
    for (String exclude : excludes) {
        Map<String, String> tempMap = new HashMap<String, String>();
        String args[] = exclude.split(":");
        if (args.length != 2) {
            throw new URISyntaxException(excludeString,
                    "Invalid exclude string: expected 'org:module,org:module,..', found " + excludeString);
        }//from   w w  w  .j  a  va  2  s  .  c o m
        tempMap.put("group", args[0]);
        tempMap.put("module", args[1]);
        excludeList.add(tempMap);
    }
    return excludeList;
}

From source file:org.hl7.fhir.client.ResourceAddress.java

public static URI buildAbsoluteURI(String absoluteURI) {

    if (StringUtils.isBlank(absoluteURI)) {
        throw new EFhirClientException("Invalid URI",
                new URISyntaxException(absoluteURI, "URI/URL cannot be blank"));
    }//from   w  ww .  j  av  a2 s  .  c o m

    String endpoint = appendForwardSlashToPath(absoluteURI);

    return buildEndpointUriFromString(endpoint);
}

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

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 {//from ww  w . j  a va 2  s . c  o  m
        syncResponseListener.get();
        fail("get should have failed");
    } catch (RuntimeException e) {
        assertEquals("error while performing request", e.getMessage());
        assertSame(exception, e.getCause());
    }
}

From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java

private FileObject[] getPidFiles(Project project) throws URISyntaxException, FileSystemException {
    ZeppelinConfig zepConf = zeppelinConfFactory.getProjectConf(project.getName());
    if (zepConf == null) {
        return new FileObject[0];
    }/*from   www.  j ava 2s  .com*/
    ZeppelinConfiguration conf = zepConf.getConf();
    URI filesystemRoot;
    FileSystemManager fsManager;
    String runPath = conf.getRelativeDir("run");
    try {
        filesystemRoot = new URI(runPath);
    } catch (URISyntaxException e1) {
        throw new URISyntaxException("Not a valid URI", e1.getMessage());
    }

    if (filesystemRoot.getScheme() == null) { // it is local path
        try {
            filesystemRoot = new URI(new File(runPath).getAbsolutePath());
        } catch (URISyntaxException e) {
            throw new URISyntaxException("Not a valid URI", e.getMessage());
        }
    }
    FileObject[] pidFiles = null;
    try {
        fsManager = VFS.getManager();
        //      pidFiles = fsManager.resolveFile(filesystemRoot.toString() + "/").
        pidFiles = fsManager.resolveFile(filesystemRoot.getPath()).getChildren();
    } catch (FileSystemException ex) {
        throw new FileSystemException("Directory not found: " + filesystemRoot.getPath(), ex.getMessage());
    }
    return pidFiles;
}

From source file:com.hp.autonomy.searchcomponents.hod.view.HodViewServerService.java

@Override
public void viewDocument(final String reference, final ResourceIdentifier index,
        final OutputStream outputStream) throws IOException, HodErrorException {
    final GetContentRequestBuilder getContentParams = new GetContentRequestBuilder().setPrint(Print.all);
    final Documents<Document> documents = getContentService.getContent(Collections.singletonList(reference),
            index, getContentParams);//w ww. ja  v a2 s  .  com

    // This document will always exist because the GetContentService.getContent throws a HodErrorException if the
    // reference doesn't exist in the index
    final Document document = documents.getDocuments().get(0);

    final Map<String, Serializable> fields = document.getFields();
    final Object urlField = fields.get(URL_FIELD);

    final String documentUrl = urlField instanceof List ? ((List<?>) urlField).get(0).toString()
            : document.getReference();

    final UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
    InputStream inputStream = null;

    try {
        try {
            final URL url = new URL(documentUrl);
            final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
            final String encodedUrl = uri.toASCIIString();

            if (urlValidator.isValid(encodedUrl)) {
                inputStream = viewDocumentService.viewUrl(encodedUrl, new ViewDocumentRequestBuilder());
            } else {
                throw new URISyntaxException(encodedUrl, "Invalid URL");
            }
        } catch (URISyntaxException | MalformedURLException e) {
            // URL was not valid, fall back to using the document content
            inputStream = formatRawContent(document);
        } catch (final HodErrorException e) {
            if (e.getErrorCode() == HodErrorCode.BACKEND_REQUEST_FAILED) {
                // HOD failed to read the url, fall back to using the document content
                inputStream = formatRawContent(document);
            } else {
                throw e;
            }
        }

        IOUtils.copy(inputStream, outputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:org.apache.marmotta.platform.core.services.triplestore.ContextServiceImpl.java

@Override
public URI createContext(String uri, String label) throws URISyntaxException {
    if (uri == null) {
        return null;
    }/*from w w w.ja v a 2s  . c om*/
    if (!UriUtil.validate(uri)) {
        uri = configurationService.getBaseContext() + uri;
        if (!UriUtil.validate(uri)) {
            throw new URISyntaxException(uri, "not valid context uri");
        }
    }
    try {
        RepositoryConnection conn = sesameService.getConnection();
        try {
            conn.begin();
            checkConnectionNamespace(conn);
            ValueFactory valueFactory = conn.getValueFactory();
            URI ctx = valueFactory.createURI(uri);
            if (StringUtils.isNotBlank(label)) {
                conn.add(ctx, RDFS.LABEL, Literals.createLiteral(valueFactory, label), ctx);
            }
            return ctx;
        } finally {
            conn.commit();
            conn.close();
        }
    } catch (RepositoryException ex) {
        handleRepositoryException(ex, ContextServiceImpl.class);
    }
    return null;
}

From source file:org.ardverk.daap.DaapRequest.java

/**
 * Sets and parses the URI. Note: if URIException is thrown then is this
 * Request in an inconsistent state!//from  w ww . j a  v a2 s .  c  o  m
 * 
 * @param uri
 * @throws URIException
 */
private void setURI(URI uri) throws URISyntaxException {

    this.uri = uri;

    if (uri != null) {

        String path = uri.getPath();

        this.queryMap = DaapUtil.parseQuery(uri.getQuery());

        if (path.equals("/server-info")) {
            requestType = SERVER_INFO;
        } else if (path.equals("/content-codes")) {
            requestType = CONTENT_CODES;
        } else if (path.equals("/login")) {
            requestType = LOGIN;
        } else if (path.equals("/logout")) {
            requestType = LOGOUT;
        } else if (path.equals("/update")) {
            requestType = UPDATE;
        } else if (path.equals("/resolve")) {
            requestType = RESOLVE;
        }

        if (queryMap.containsKey("session-id")) {
            sessionId = SessionId.parseSessionId(queryMap.get("session-id"));
        }

        if (!SessionId.INVALID.equals(sessionId)) {

            if (queryMap.containsKey("revision-number")) {
                revisionNumber = Integer.parseInt(queryMap.get("revision-number"));
            }

            if (queryMap.containsKey("delta")) {
                delta = Integer.parseInt(queryMap.get("delta"));
            }

            if (delta > revisionNumber) {
                throw new URISyntaxException(uri.toASCIIString(),
                        "Delta must be less or equal to revision-number: " + delta + "/" + revisionNumber);
            }

            if (queryMap.containsKey("meta")) {
                metaString = queryMap.get("meta");
            }

            isUpdateType = (delta != DaapUtil.NULL) && (delta < revisionNumber);

            // "/databases/id/items" 3 tokens
            // "/databases/id/containers" 3 tokens
            // "/databases/id/items/id.format" 4 tokens
            // "/databases/id/containers/id/items" 5 tokens
            if (path.equals("/databases")) {
                requestType = DATABASES;

            } else if (path.startsWith("/databases")) {

                StringTokenizer tok = new StringTokenizer(path, "/");
                int count = tok.countTokens();

                if (count >= 3) {
                    String token = tok.nextToken();

                    if (token.equals("databases") == false) {
                        throw new URISyntaxException(uri.toASCIIString(),
                                "Unknown token in path: " + path + " [" + token + "]@1");
                    }

                    databaseId = DaapUtil.parseUInt(tok.nextToken());
                    token = tok.nextToken();

                    if (token.equals("items")) {
                        requestType = DATABASE_SONGS;
                    } else if (token.equals("containers")) {
                        requestType = DATABASE_PLAYLISTS;
                    } else {
                        throw new URISyntaxException(uri.toASCIIString(),
                                "Unknown token in path: " + path + " [" + token + "]@2");
                    }

                    if (count == 3) {
                        // do nothing...

                    } else if (count == 4) {

                        token = tok.nextToken();

                        StringTokenizer fileTokenizer = new StringTokenizer(token, ".");

                        if (fileTokenizer.countTokens() == 2) {
                            itemId = DaapUtil.parseUInt(fileTokenizer.nextToken());
                            requestType = SONG;

                        } else {
                            throw new URISyntaxException(uri.toASCIIString(),
                                    "Unknown token in path: " + path + " [" + token + "]@3");
                        }

                    } else if (count == 5) {
                        containerId = DaapUtil.parseUInt(tok.nextToken());
                        token = tok.nextToken();

                        if (token.equals("items")) {
                            requestType = PLAYLIST_SONGS;

                        } else {
                            throw new URISyntaxException(uri.toASCIIString(),
                                    "Unknown token in path: " + path + " [" + token + "@4");
                        }

                    } else {
                        throw new URISyntaxException(uri.toASCIIString(),
                                "Unknown token in path: " + path + " [" + token + "]@5");
                    }
                } else {
                    throw new URISyntaxException(uri.toASCIIString(), "Unknown token in path: " + path);
                }
            }
        }

    } else {

        queryMap = null;
        metaString = null;
        isUpdateType = false;

        requestType = DaapUtil.NULL;
        databaseId = DaapUtil.NULL;
        containerId = DaapUtil.NULL;
        itemId = DaapUtil.NULL;

        sessionId = SessionId.INVALID;
        revisionNumber = DaapUtil.NULL;
        delta = DaapUtil.NULL;
    }
}