Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:nl.mpi.tla.flat.deposit.action.PackageAssembly.java

@Override
public boolean perform(Context context) throws DepositException {
    try {/*from w  ww  .j  a va2s. c o  m*/
        File dir = new File(getParameter("dir", "./resources"));
        if (!dir.exists())
            FileUtils.forceMkdir(dir);
        int downloads = 0;
        for (Resource res : context.getSIP().getResources()) {
            if (res.hasFile()) {
                if (res.getFile().canRead()) {
                    logger.info("Previously download[" + res.getFile() + "] of Resource[" + res.getURI()
                            + "] is still available.");
                    continue;
                } else
                    logger.info("Previously download[" + res.getFile() + "] of Resource[" + res.getURI()
                            + "] isn't available anymore!");
            }
            URI uri = res.getURI();
            if (uri.toString().startsWith(dir.toString())) {
                // the file is already in the workdir resources directory
                res.setFile(new File(uri.toString()));
            } else if (uri.toString().startsWith("hdl:" + getParameter("prefix", "foo") + "/") || uri.toString()
                    .startsWith("http://hdl.handle.net/" + getParameter("prefix", "foo") + "/")) {
                // it has already a local handle
                // TODO: what to do? resolve to its local location, and check?
            } else {
                // download the content into a local file 
                String ext = FilenameUtils.getExtension(uri.getPath());
                File file = dir.toPath()
                        .resolve("./" + UUID.randomUUID().toString() + (!ext.equals("") ? "." + ext : ""))
                        .toFile();
                Request.Get(uri).execute().saveContent(file);
                res.setFile(file);
                logger.info("Downloaded Resource[" + (++downloads) + "][" + uri + "] to [" + file + "]");
            }
        }
        if (downloads > 0) {
            context.getSIP().save();
        }
    } catch (Exception ex) {
        throw new DepositException("Couldn't assemble the package!", ex);
    }
    return true;
}

From source file:com.ironiacorp.http.impl.httpclient3.GetRequest.java

public HttpJob call() {
    URI uri = job.getUri();
    GetMethod getMethod = new GetMethod(uri.toString());
    HttpMethodResult result = new HttpMethodResult();

    try {//from ww  w  . j  ava  2  s  .  c  o m
        int statusCode = client.executeMethod(getMethod);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + getMethod.getStatusLine());
        }

        InputStream inputStream = getMethod.getResponseBodyAsStream();
        if (inputStream != null) {
            result.setContent(inputStream);
            result.setStatusCode(statusCode);
            job.setResult(result);
        }
    } catch (HttpException e) {
    } catch (IOException e) {
        // In case of an IOException the connection will be released
        // back to the connection manager automatically
    } catch (RuntimeException ex) {
        // In case of an unexpected exception you may want to abort
        // the HTTP request in order to shut down the underlying
        // connection and release it back to the connection manager.
        getMethod.abort();
    }

    return job;
}

From source file:com.googlecode.jsonschema2pojo.ContentResolver.java

private JsonNode resolveFromClasspath(URI uri) {

    String path = removeStart(removeStart(uri.toString(), uri.getScheme() + ":"), "/");
    InputStream contentAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);

    if (contentAsStream == null) {
        throw new IllegalArgumentException("Couldn't read content from the classpath, file not found: " + uri);
    }//  www  . j  a  v  a 2  s. c o  m

    try {
        return OBJECT_MAPPER.readTree(contentAsStream);
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException("Error parsing document: " + uri, e);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
    }
}

From source file:com.google.mr4c.hadoop.MR4CGenericOptions.java

public void addJar(URI jar) {
    m_jars.add(jar.toString());
}

From source file:com.vmware.identity.idm.server.ServerUtils.java

/**
 * Checks the connectivity to an identity provider
 *
 * @param providerUri Location of identity provider. non-null non-empty, required
 * @param userName    Login identifier. non-null, required
 * @param pwd         Password    non-null non-empty, required
 * @param certVerifierCallback Callback called to validate SSL certificates
 * @return connection:  non-null/*from w w  w. ja va  2 s.  c  o  m*/
 * @throws IDMLoginException. If one or more of the input argument is illegal.
 *                                 Or URI syntax is incorrect.
 * @throws Exception     if no connection
 * @throws IllegalArgumentException  one or more input are empty
 */
public static ILdapConnectionEx getLdapConnectionByURIs(Collection<URI> uris, String userName, String password,
        AuthenticationType authType, boolean useGcPort,
        LdapCertificateValidationSettings certValidationsettings) throws Exception {
    ValidateUtil.validateNotEmpty(uris, "uris");

    // NB: not checking whether the port is Kerberos port 88.

    ILdapConnectionEx result = null;
    Exception latestEx = null;
    for (URI uri : uris) {
        if (!DirectoryStoreProtocol.isProtocolSupported(uri.getScheme())) {
            logger.warn(String.format("protocol scheme for the specified URI is not supported: [%s]",
                    uri.toString()));
            continue; //skip unsupported protocol
        }

        logger.trace("start creating connection {}", uri);
        try {
            result = getLdapConnection(uri, userName, password, authType, useGcPort, certValidationsettings);
            if (null != result) {
                logger.trace("done creating connection");

                return result; //done
            }
        } catch (Exception e) { //log an error, pin down the latest and continue
            latestEx = e;
            logger.error("cannot establish connection with uri: {}", uri);
        }
    }

    assert (result == null);
    if (latestEx != null) {
        throw latestEx; // could not get connection from any of them
    }
    return null;
}

From source file:org.trustedanalytics.user.invite.EmailOrgUserInvitationService.java

private String getEmailHtml(String username) {
    final Context ctx = new Context();
    ctx.setVariable("serviceName", "Trusted Analytics");
    ctx.setVariable("username", username);
    URI authorizationUrl = URI.create(authorizationHost);
    String resetPasswordUrl = authorizationUrl.toString().replaceAll(authorizationUrl.getPath(),
            "/forgot_password");
    ctx.setVariable("resetPasswordUrl", resetPasswordUrl);
    ctx.setVariable("consoleUrl", getConsoleUrl());
    return templateEngine.process("invite_org", ctx);
}

From source file:org.openxrd.discovery.impl.AbstractHttpDiscoveryMethod.java

/**
 * Fetch the contents of the specified URI using the internal HTTP client.
 * /* w ww. j  a v  a  2 s  . c o m*/
 * @param uri URI to fetch
 * @return HTTP response
 * @throws IOException in case of a problem or the connection was aborted
 */
protected HttpResponse fetch(URI uri) throws IOException {
    LOG.debug("Fetching URI: {}", uri.toString());

    HttpGet httpGet = new HttpGet(uri);
    HttpResponse response = httpClient.execute(httpGet);

    return response;
}

From source file:com.google.mr4c.hadoop.MR4CGenericOptions.java

public void addFile(URI file) {
    m_files.add(file.toString());
}

From source file:com.appglu.impl.DefaultHeadersHttpRequestInterceptor.java

public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {

    HttpRequestWrapper wrapper = new HttpRequestWrapper(request) {

        @Override/*  w w w  . j a va2  s . c o  m*/
        public URI getURI() {
            URI uri = super.getURI();
            String fragment = uri.toString();
            String url = baseUrl + fragment;
            try {
                return new URI(url);
            } catch (URISyntaxException ex) {
                throw new IllegalArgumentException("Could not create HTTP URL from [" + url + "]: " + ex, ex);
            }
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = super.getHeaders();

            if (StringUtils.isNotEmpty(applicationEnvironment)) {
                headers.put("X-AppGlu-Environment", Arrays.asList(applicationEnvironment));
            }

            headers.putAll(defaultHeaders);
            return headers;
        }

    };

    return execution.execute(wrapper, body);
}

From source file:at.ac.univie.isc.asio.Asio.java

@Bean
@ConditionalOnProperty(AsioFeatures.VPH_METADATA)
public DescriptorService descriptorService(final Client http) {
    final WebTarget endpoint = http.target(config.getMetadataRepository());
    final AtosMetadataRepository atos = new AtosMetadataRepository(endpoint);
    return new DescriptorService() {
        @Override// www .  ja  va2 s.c  om
        public Observable<SchemaDescriptor> metadata(final URI identifier) {
            return atos.findByLocalId(identifier.toString()).map(DescriptorConversion.asFunction());
        }
    };
}