Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:de.thingweb.thing.Thing.java

public String resolvePropertyUri(String name, int index) {

    URI uri = getUri(index);

    Property p = getProperty(name);//from w  w w .j  a  va 2  s  .  co  m

    if (p != null) {
        try {
            // String scheme, String userInfo, String host, int port, String path, String query, String fragment
            String path = uri.getPath();
            if (path.endsWith("/")) {
                path = path + p.getHrefs().get(index);
            } else {
                path = path + "/" + p.getHrefs().get(index);
            }
            uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path,
                    uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            throw new RuntimeException("TD with malformed hrefs");
        }
    } else {
        throw new RuntimeException("No such Property");
    }

    return uri.toString();
}

From source file:com.github.fedorchuck.webstore.config.DataConfig.java

@SuppressWarnings("ConstantConditions")
private void getConfigEnv(Map<String, String> env) {
    URI dbUri = null;
    try {/*from w w  w .  ja  v a2  s.c  o  m*/
        dbUri = new URI(System.getenv("DATABASE_URL"));
    } catch (URISyntaxException e) {
        logger.error("problem read config. reason: ", e);
    }

    driverClassName = "org.postgresql.Driver";
    username = dbUri.getUserInfo().split(":")[0];
    password = dbUri.getUserInfo().split(":")[1];
    url = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
}

From source file:com.microsoftopentechnologies.azchat.web.mediaservice.AzureChatMediaService.java

/**
 * This method retrieve the MP4 streaming URL from assetInfoFile.
 * /*from  ww w .j av  a2s.  c  o  m*/
 * @param streaming
 * @param streamingAssetFile
 * @param streamingAsset
 * @return
 * @throws Exception
 */
private String getMP4StreamngURL(AccessPolicyInfo streaming, AssetFileInfo streamingAssetFile,
        AssetInfo streamingAsset) throws Exception {
    String streamingURL = null;
    LocatorInfo locator = mediaService
            .create(Locator.create(streaming.getId(), streamingAsset.getId(), LocatorType.SAS));
    URI mp4Uri = new URI(locator.getPath());
    mp4Uri = new URI(mp4Uri.getScheme(), mp4Uri.getUserInfo(), mp4Uri.getHost(), mp4Uri.getPort(),
            mp4Uri.getPath() + AzureChatConstants.CONSTANT_BACK_SLASH + streamingAssetFile.getName(),
            mp4Uri.getQuery(), mp4Uri.getFragment());
    streamingURL = mp4Uri.toString();
    return streamingURL;

}

From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java

public URI assignExperiment(URI submissionUri, Experiment experiment) {
    ObjectMapper objectMapper = restTemplateService.getObjectMapperWithHalModule();
    String experimentsUri = RestClientConfiguration.BASE_URL + "/" + "experiments";
    ObjectNode jsonNodeExperiment = (ObjectNode) objectMapper.valueToTree(experiment);
    jsonNodeExperiment.put("submission", submissionUri.getPath());

    URI experimentUri = restTemplate.postForLocation(experimentsUri, jsonNodeExperiment);
    ResponseEntity<Resource<Experiment>> experimentResponseEntity = restTemplate.exchange(experimentUri,
            HttpMethod.GET, null, new ParameterizedTypeReference<Resource<Experiment>>() {
            });/*from  w w w .  j a v a  2 s.co m*/

    Resource<Experiment> experimentResource = experimentResponseEntity.getBody();
    Link submissionLinkThroughExperiment = experimentResource.getLink("submission");
    System.out.println("Submission Link through Experiment = " + submissionLinkThroughExperiment);
    return experimentUri;
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java

private URI resolveAsFileURI(URI relativeTo, String username) {
    URI userRoot = getResolvedRootUri(username);
    if (relativeTo == null || StringUtils.isBlank(relativeTo.getPath())) {
        return userRoot;
    }/*from w w w. ja  v  a 2s.  c o  m*/
    return URI.create(UriComponentsBuilder.fromUri(userRoot).path(relativeTo.getPath()).toUriString())
            .normalize();
}

From source file:com.microsoft.windowsazure.messaging.NotificationHub.java

private String createRegistrationId() throws Exception {
    Connection conn = new Connection(mConnectionString);

    String resource = mNotificationHubPath + "/registrationids/";
    String response = conn.executeRequest(resource, null, XML_CONTENT_TYPE, "POST",
            NEW_REGISTRATION_LOCATION_HEADER);

    URI regIdUri = new URI(response);
    String[] pathFragments = regIdUri.getPath().split("/");
    String result = pathFragments[pathFragments.length - 1];

    return result;
}

From source file:in.thunk.camel.component.job.JobComponent.java

@Override
protected JobEndpoint createEndpoint(final String uri, final String remaining,
        final Map<String, Object> parameters) throws Exception {

    // lets split the remaining into a group/name
    URI u = new URI(uri);
    String jobString = ObjectHelper.after(u.getPath(), "/");
    String group = u.getHost();//from   w  w  w .ja  v  a 2 s . c  o m

    String[] fragments = jobString.split("/");
    String name = fragments[0];
    String stepName = fragments.length > 1 ? fragments[1] : null;

    String expression = getAndRemoveParameter(parameters, "jobId", String.class);
    String cron = getAndRemoveParameter(parameters, "cron", String.class);
    Boolean fireNow = getAndRemoveParameter(parameters, "fireNow", Boolean.class, Boolean.FALSE);

    if (ObjectHelper.isEmpty(group) || ObjectHelper.isEmpty(name)) {
        throw new IllegalArgumentException("Cannot create a Job Endopoint without Group and Job Names");
    }

    Map<String, Object> triggerParameters = IntrospectionSupport.extractProperties(parameters, "trigger.");
    Map<String, Object> jobParameters = IntrospectionSupport.extractProperties(parameters, "job.");

    JobKey key = new JobKey(group, name, stepName);

    Collection<JobEndpoint> tasksEndpoints = endpoints.get(key);

    for (JobEndpoint jobEndpoint : tasksEndpoints) {
        if (uri.equals(jobEndpoint.getEndpointUri())) {

            if (!jobParameters.isEmpty()) {
                if (jobEndpoint.isJobParamSet()) {
                    throw new IllegalArgumentException(
                            "Job parameters can be set only once for a specific job. Failing at uri " + uri);
                }
                setProperties(jobEndpoint.getJobDetail(), jobParameters);
                jobEndpoint.setJobParamSet(true);
            }
            return jobEndpoint;
        }
    }

    JobEndpoint answer = new JobEndpoint(key, expression, this);
    tasksEndpoints.add(answer);

    answer.setStateful(true); //set it true by default, and the route definition can override
    setProperties(answer.getJobDetail(), jobParameters);

    if (!triggerParameters.isEmpty()) { // setting regular Quartz consumer with trigger and stuff

        Trigger trigger = null;

        // if we're starting up and not running in Quartz clustered mode
        // then check for a name conflict.
        if (!isClustered()) {
            // check to see if this trigger already exists
            trigger = getScheduler().getTrigger(name, group);
            if (trigger != null) {
                String msg = "A Quartz job already exists with the name/group: " + name + "/" + group;
                throw new IllegalArgumentException(msg);
            }
        }

        // create the trigger either cron or simple
        if (ObjectHelper.isNotEmpty(cron)) {
            trigger = createCronTrigger(cron);
        } else {
            trigger = new SimpleTrigger();
            if (fireNow) {
                String intervalString = (String) triggerParameters.get("repeatInterval");
                if (intervalString != null) {
                    long interval = Long.valueOf(intervalString);
                    trigger.setStartTime(new Date(System.currentTimeMillis() - interval));
                }
            }
        }

        setProperties(trigger, triggerParameters);
        trigger.setName(name);
        trigger.setGroup(group);

        answer.addTrigger(trigger);
    }

    return answer;

}

From source file:com.splout.db.dnode.Fetcher.java

private File s3Fetch(URI uri, Reporter reporter) throws IOException, InterruptedException {
    String bucketName = uri.getHost();
    String path = uri.getPath();
    UUID uniqueId = UUID.randomUUID();
    File destFolder = new File(tempDir, uniqueId.toString() + "/" + path);
    if (destFolder.exists()) {
        FileUtils.deleteDirectory(destFolder);
    }/*from w w  w .j a  v  a 2  s .c  o  m*/
    destFolder.mkdirs();

    Throttler throttler = new Throttler((double) bytesPerSecThrottle);

    boolean done = false;
    try {
        s3Service = new RestS3Service(getCredentials());
        if (s3Service.checkBucketStatus(bucketName) != RestS3Service.BUCKET_STATUS__MY_BUCKET) {
            throw new IOException("Bucket doesn't exist or is already claimed: " + bucketName);
        }

        if (path.startsWith("/")) {
            path = path.substring(1, path.length());
        }

        for (S3Object object : s3Service.listObjects(new S3Bucket(bucketName), path, "")) {
            long bytesSoFar = 0;

            String fileName = path;
            if (path.contains("/")) {
                fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
            }
            File fileDest = new File(destFolder, fileName);
            log.info("Downloading " + object.getKey() + " to " + fileDest + " ...");

            if (fileDest.exists()) {
                fileDest.delete();
            }

            object = s3Service.getObject(new S3Bucket(bucketName), object.getKey());
            InputStream iS = object.getDataInputStream();
            FileOutputStream writer = new FileOutputStream(fileDest);
            byte[] buffer = new byte[downloadBufferSize];

            int nRead;
            while ((nRead = iS.read(buffer, 0, buffer.length)) != -1) {
                // Needed to being able to be interrupted at any moment.
                if (Thread.interrupted()) {
                    iS.close();
                    writer.close();
                    cleanDirNoExceptions(destFolder);
                    throw new InterruptedException();
                }

                bytesSoFar += nRead;
                writer.write(buffer, 0, nRead);
                throttler.incrementAndThrottle(nRead);
                if (bytesSoFar >= bytesToReportProgress) {
                    reporter.progress(bytesSoFar);
                    bytesSoFar = 0l;
                }
            }

            if (reporter != null) {
                reporter.progress(bytesSoFar);
            }

            writer.close();
            iS.close();
            done = true;
        }

        if (!done) {
            throw new IOException("Bucket is empty! " + bucketName + " path: " + path);
        }
    } catch (S3ServiceException e) {
        throw new IOException(e);
    }

    return destFolder;
}

From source file:com.offbytwo.jenkins.client.JenkinsHttpClient.java

/**
 * Create an unauthenticated Jenkins HTTP client
 *
 * @param uri/*from   w  ww.ja va2s. c o m*/
 *            Location of the jenkins server (ex. http://localhost:8080)
 */
public JenkinsHttpClient(URI uri) {
    this(uri, HttpClientBuilder.create());
    this.context = uri.getPath();

    if (!context.endsWith("/")) {
        context += "/";
    }
    this.uri = uri;
    this.mapper = getDefaultMapper();

    HttpParams httpParams = new BasicHttpParams();
    httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT_IN_MILLISECONDS);
    httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_IN_MILLISECONDS);

    this.httpResponseValidator = new HttpResponseValidator();
    LOGGER.debug("uri={}", uri.toString());
}