Example usage for java.net URI resolve

List of usage examples for java.net URI resolve

Introduction

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

Prototype

public URI resolve(String str) 

Source Link

Document

Constructs a new URI by parsing the given string and then resolving it against this URI.

Usage

From source file:org.eclipse.orion.server.cf.commands.GetSpaceCommand.java

@Override
protected ServerStatus _doIt() {
    try {//from ww  w  .  ja v a2  s  . c om
        URI targetURI = URIUtil.toURI(getCloud().getUrl());

        /* get space */
        URI spacesURI = targetURI.resolve("/v2/spaces/" + this.spaceId);

        GetMethod getSpaceMethod = new GetMethod(spacesURI.toString());
        HttpUtil.configureHttpMethod(getSpaceMethod, getCloud());
        getSpaceMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(getSpaceMethod);
        if (!status.isOK())
            return status;

        space = new Space().setCFJSON(status.getJsonData());
        JSONObject result = space.toJSON();

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (ConnectTimeoutException e) {
        String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_GATEWAY_TIMEOUT, msg, e);
    } catch (Exception e) {
        String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:com.google.appengine.tck.util.GaeAuthClient.java

protected String getCookieUrl(String servletUrl, String authToken) throws URISyntaxException {
    URI servletUri = new URI(servletUrl);
    URI cookieUri = servletUri.resolve("/_ah/login?auth=" + authToken);
    return cookieUri.toString();
}

From source file:org.wso2.carbon.humantask.core.integration.HumanTaskSchemaURIResolver.java

public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
    if (log.isDebugEnabled()) {
        log.debug("resolveEntity: targetNamespace=" + targetNamespace + " schemaLocation=" + schemaLocation
                + " baseUri=" + baseUri);
    }/*from www . ja v  a  2s . c o  m*/
    InputStream is;
    try {
        URI base = new URI("file:" + baseUri);
        URI uri = base.resolve(schemaLocation);
        is = uri.toURL().openStream();
        if (is == null) {
            log.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri);
            return null;
        }
        InputSource source = new InputSource(is);
        source.setSystemId(uri.toString());
        source.setPublicId(schemaLocation);
        return new InputSource(is);
    } catch (Exception e) {
        log.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri, e);
        return null;
    }
}

From source file:org.jboss.aerogear.unifiedpush.admin.ui.utils.UpsOpenshiftStatusCheck.java

@Override
public void target(URI uri) {
    Validate.notNull(uri, "target URI to check status of can not be a null object");
    this.uri = uri.getPath().contains("extension") ? uri.resolve(uri.getPath() + "/status") : uri;
}

From source file:org.ballerinalang.composer.service.workspace.rest.datamodel.BLangJSONModelTest.java

private HttpURLConnection request(String path, String method) throws IOException, URISyntaxException {
    URI baseURI = new URI("http://localhost:9091");
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) {
        urlConn.setDoOutput(true);/*from w  w w  . j av a 2  s. co  m*/
    }
    urlConn.setRequestMethod(method);
    return urlConn;
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.PopulationStatisticsGeneratorStep.java

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    ObjectMap variantOptions = jobOptions.getVariantOptions();
    ObjectMap pipelineOptions = jobOptions.getPipelineOptions();

    //                HashMap<String, Set<String>> samples = new HashMap<>(); // TODO fill properly. if this is null overwrite will take on
    //                samples.put("SOME", new HashSet<>(Arrays.asList("HG00096", "HG00097")));

    VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager();
    VariantSource variantSource = variantOptions.get(VariantStorageManager.VARIANT_SOURCE, VariantSource.class);
    VariantDBAdaptor dbAdaptor = variantStorageManager
            .getDBAdaptor(variantOptions.getString(VariantStorageManager.DB_NAME), variantOptions);
    URI outdirUri = URLHelper.createUri(pipelineOptions.getString("output.dir.statistics"));
    URI statsOutputUri = outdirUri.resolve(VariantStorageManager.buildFilename(variantSource));

    VariantStatisticsManager variantStatisticsManager = new VariantStatisticsManager();
    QueryOptions statsOptions = new QueryOptions(variantOptions);

    // actual stats creation
    variantStatisticsManager.createStats(dbAdaptor, statsOutputUri, null, statsOptions); // TODO allow subset of samples

    return RepeatStatus.FINISHED;
}

From source file:org.wso2.msf4j.osgi.test.MSF4JOSGiTest.java

private HttpURLConnection request(String path, String method, boolean keepAlive) throws IOException {
    URI baseURI = URI.create(String.format("http://%s:%d", HOSTNAME, PORT));
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) {
        urlConn.setDoOutput(true);//from  www .  ja v  a  2s .  c o m
    }
    urlConn.setRequestMethod(method);
    if (!keepAlive) {
        urlConn.setRequestProperty(HttpHeaderNames.CONNECTION.toString(), HEADER_VAL_CLOSE);
    }

    return urlConn;
}

From source file:org.callimachusproject.client.UnavailableRequestDirector.java

@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request,
        HttpClientContext clientContext, HttpExecutionAware execAware) throws IOException, HttpException {
    BasicHttpResponse _503 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 503, "Service Disconnected");
    HttpHost target = route.getTargetHost();
    try {//from   w  w w.  j a  v  a  2s.c  o  m
        URI root = new URI(target.getSchemeName(), null, target.getHostName(), target.getPort(), "/", null,
                null);
        return new HttpUriResponse(root.resolve(request.getURI()).toASCIIString(), _503);
    } catch (URISyntaxException e) {
        return new HttpUriResponse(request.getURI().toASCIIString(), _503);
    }
}

From source file:org.eclipse.orion.server.cf.commands.GetOrgsCommand.java

@Override
protected ServerStatus _doIt() {
    try {//from   w  w  w.  jav  a2  s .  com
        /* get available orgs */
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI orgsURI = targetURI.resolve("/v2/organizations");

        GetMethod getDomainsMethod = new GetMethod(orgsURI.toString());
        HttpUtil.configureHttpMethod(getDomainsMethod, target);
        getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(getDomainsMethod);
        if (!status.isOK())
            return status;

        /* extract available orgs */
        JSONObject orgs = status.getJsonData();

        if (orgs == null || orgs.optInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS, 0) < 1) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NO_CONTENT,
                    "Server did not return any organizations.", null);
        }

        /* look if the domain is available */
        JSONObject result = new JSONObject();
        int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
        for (int k = 0; k < resources; ++k) {
            JSONObject orgJSON = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
            List<Space> spaces = new ArrayList<Space>();
            status = getSpaces(spaces, orgJSON);
            if (!status.isOK())
                return status;
            OrgWithSpaces orgWithSpaces = new OrgWithSpaces();
            orgWithSpaces.setCFJSON(orgJSON);
            orgWithSpaces.setSpaces(spaces);
            result.append("Orgs", orgWithSpaces.toJSON());
        }

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (Exception e) {
        String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.orion.server.cf.commands.CreateRouteCommand.java

@Override
protected ServerStatus _doIt() {
    try {/* ww  w.  ja v a2s.  c o  m*/
        /* create cloud foundry application */
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI routesURI = targetURI.resolve("/v2/routes"); //$NON-NLS-1$

        PostMethod createRouteMethod = new PostMethod(routesURI.toString());
        HttpUtil.configureHttpMethod(createRouteMethod, target);

        /* set request body */
        JSONObject routeRequest = new JSONObject();
        routeRequest.put(CFProtocolConstants.V2_KEY_SPACE_GUID, target.getSpace().getCFJSON()
                .getJSONObject(CFProtocolConstants.V2_KEY_METADATA).getString(CFProtocolConstants.V2_KEY_GUID));
        routeRequest.put(CFProtocolConstants.V2_KEY_HOST, hostName);
        routeRequest.put(CFProtocolConstants.V2_KEY_DOMAIN_GUID, domain.getGuid());
        createRouteMethod.setRequestEntity(
                new StringRequestEntity(routeRequest.toString(), "application/json", "utf-8")); //$NON-NLS-1$//$NON-NLS-2$
        createRouteMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

        ServerStatus createRouteStatus = HttpUtil.executeMethod(createRouteMethod);
        if (!createRouteStatus.isOK())
            return createRouteStatus;

        route = new Route().setCFJSON(createRouteStatus.getJsonData());

        return createRouteStatus;
    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}