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.GetRouteByGuidCommand.java

public ServerStatus _doIt() {
    try {/*  w  ww. j a  v a 2  s.  c  o m*/
        URI targetURI = URIUtil.toURI(getCloud().getUrl());

        // Get the app
        URI appsURI = targetURI.resolve("/v2/routes/" + routeGuid);
        GetMethod getRoutesMethod = new GetMethod(appsURI.toString());
        HttpUtil.configureHttpMethod(getRoutesMethod, getCloud());

        ServerStatus getStatus = HttpUtil.executeMethod(getRoutesMethod);
        if (!getStatus.isOK())
            return getStatus;

        JSONObject routeJSON = getStatus.getJsonData();
        this.route = new Route().setCFJSON(routeJSON);

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, this.route.toJSON());
    } 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);
    }
}

From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java

private static URI followRedirectsInternal(URI url, int maxRedirections) {
    URI response = url;/*from  w  w w .  j a  v  a 2s.  co  m*/
    HttpClient client = new HttpClient();
    DefaultHttpMethodRetryHandler handler = new DefaultHttpMethodRetryHandler(1, false);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, handler);
    HttpMethod method = new HeadMethod(url.toASCIIString());
    //method.setRequestHeader("Accept-Language", locale.getLanguage() + ",en");
    method.setFollowRedirects(false);
    try {
        int statusCode = client.executeMethod(method);
        if ((statusCode == HttpStatus.SC_MOVED_PERMANENTLY) | (statusCode == HttpStatus.SC_MOVED_TEMPORARILY)) {
            if (maxRedirections > 0) {
                Header location = method.getResponseHeader("Location");
                if (!location.getValue().equals("")) {
                    // recursively check URL until it's not redirected any more
                    // locations can be relative to previous URL
                    URI target = url.resolve(location.getValue());
                    response = followRedirectsInternal(target, maxRedirections - 1);
                }
            }
        }
    } catch (Exception e) {
        //HttpClient can also throw IllegalArgumentException when URLs are malformed
    }
    return response;
}

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

@Override
protected ServerStatus _doIt() {
    try {//from   w  w w .  j a  v a2s.  c o  m
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI servicesURI = targetURI.resolve("/v2/stacks"); //$NON-NLS-0$//$NON-NLS-1$

        GetMethod getStacksMethod = new GetMethod(servicesURI.toString());
        NameValuePair[] params = new NameValuePair[] { //
                new NameValuePair("q", "name:" + stackName), //$NON-NLS-0$ //$NON-NLS-1$
                new NameValuePair("inline-relations-depth", "1") //$NON-NLS-0$ //$NON-NLS-1$
        };
        getStacksMethod.setQueryString(params);

        ServerStatus confStatus = HttpUtil.configureHttpMethod(getStacksMethod, target.getCloud());
        if (!confStatus.isOK())
            return confStatus;

        ServerStatus getStacksStatus = HttpUtil.executeMethod(getStacksMethod);
        if (!getStacksStatus.isOK())
            return getStacksStatus;

        JSONObject stacksJSON = getStacksStatus.getJsonData();
        if (stacksJSON.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
            return getStacksStatus;
        }

        JSONArray resources = stacksJSON.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
        JSONObject stackJSON = resources.getJSONObject(0);
        stack = new Stack().setCFJSON(stackJSON);

        return getStacksStatus;
    } 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);
    }
}

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

@Override
protected ServerStatus _doIt() {
    try {/*from w  ww  . j a va  2s  . c o m*/

        /* attach route to application */
        URI targetURI = URIUtil.toURI(target.getUrl());
        PutMethod attachRouteMethod = new PutMethod(
                targetURI.resolve("/v2/apps/" + application.getGuid() + "/routes/" + routeGUID).toString()); //$NON-NLS-1$//$NON-NLS-2$
        HttpUtil.configureHttpMethod(attachRouteMethod, target);
        return HttpUtil.executeMethod(attachRouteMethod);

    } 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);
    }
}

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

@Override
protected ServerStatus _doIt() {
    try {/*from  w  w w .  j av a  2  s. c o  m*/

        /* unmap route from application */
        URI targetURI = URIUtil.toURI(target.getUrl());
        DeleteMethod unmapRouteMethod = new DeleteMethod(
                targetURI.resolve("/v2/apps/" + app.getGuid() + "/routes/" + route.getGuid()).toString()); //$NON-NLS-1$//$NON-NLS-2$
        HttpUtil.configureHttpMethod(unmapRouteMethod, target);
        return HttpUtil.executeMethod(unmapRouteMethod);

    } 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);
    }
}

From source file:org.ldp4j.server.data.TripleResolverTest.java

@Test
public void testCornerCase() throws ContentTransformationException {
    URI application = URI.create("http://localhost:8080/ldp4j-server-tckf/ldp4j/");
    URI endpoint = application.resolve("api/basic_container/");
    URI alternative = URI.create("http://www.ldp4j.org/ldp4j-server-tckf/ldp4j/api/basic_container/");

    String rawEntity = loadResource("/data/public-uri-clash.ttl");
    TripleResolver safeResolver = TripleResolver.builder().withApplication(application).withEndpoint(endpoint)
            .withAlternative(alternative).withEntity(rawEntity, this.mediaType).build();
    int count = 0;
    for (TripleResolution resolution : safeResolver.tripleResolutions()) {
        System.out.printf("[%03d] %s%n  - Subject: %s%n  - Object.: %s%n", ++count, resolution.triple(),
                resolution.subjectResolution(), resolution.objectResolution());
    }//from w w w  .ja va2  s  .  c  o m
}

From source file:net.ripe.rpki.validator.commands.TopDownWalker.java

void processManifestEntry(ManifestCms manifestCms, CertificateRepositoryObjectValidationContext context,
        URI repositoryURI, String fileName) {
    URI uri = repositoryURI.resolve(fileName);
    validationResult.setLocation(new ValidationLocation(uri));
    CertificateRepositoryObject object = certificateRepositoryObjectFetcher.getObject(uri, context,
            manifestCms.getFileContentSpecification(fileName), validationResult);
    addToWorkQueueIfObjectIssuer(context, uri, object);
}

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

public ServerStatus _doIt() {
    try {//from   ww w. j a  v  a2  s .c  om
        URI infoURI = URIUtil.toURI(target.getUrl());

        infoURI = infoURI.resolve("/v2/organizations");

        GetMethod getMethod = new GetMethod(infoURI.toString());
        HttpUtil.configureHttpMethod(getMethod, target);
        ServerStatus getStatus = HttpUtil.executeMethod(getMethod);
        if (!getStatus.isOK())
            return getStatus;

        JSONObject result = getStatus.getJsonData();
        JSONArray orgs = result.getJSONArray("resources");

        if (orgs.length() == 0) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found",
                    null);
        }

        if (this.org == null || "".equals(this.org)) {
            JSONObject org = orgs.getJSONObject(0);
            target.setOrg(new Org().setCFJSON(org));
        } else {
            for (int i = 0; i < orgs.length(); i++) {
                JSONObject orgJSON = orgs.getJSONObject(i);
                if ((!isGuid && org.equals(orgJSON.getJSONObject("entity").getString("name")))
                        || (isGuid && org.equals(orgJSON.getJSONObject("metadata").getString("guid")))) {
                    target.setOrg(new Org().setCFJSON(orgJSON));
                    break;
                }
            }
        }

        if (target.getOrg() == null) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found",
                    null);
        }

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, target.getOrg().toJSON());
    } 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);
    }
}

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

private ServerStatus getSpaces(List<Space> spaces, JSONObject orgJSON) throws Exception {
    URI targetURI = URIUtil.toURI(target.getUrl());
    URI spaceURI = targetURI.resolve(orgJSON.getJSONObject("entity").getString("spaces_url"));

    GetMethod getDomainsMethod = new GetMethod(spaceURI.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 spaces */
    JSONObject orgs = status.getJsonData();

    if (orgs.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
    }/*w  w w.jav a 2 s.co  m*/

    /* look if the domain is available */
    int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
    for (int k = 0; k < resources; ++k) {
        JSONObject spaceJSON = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
        spaces.add(new Space().setCFJSON(spaceJSON));
    }

    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
}

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

@Override
protected ServerStatus _doIt() {
    try {//ww w .  j  av  a  2 s .  c o m

        /* create cloud foundry application */
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI routesURI = targetURI.resolve("/v2/routes"); //$NON-NLS-1$

        GetMethod findRouteMethod = new GetMethod(routesURI.toString());
        HttpUtil.configureHttpMethod(findRouteMethod, target);
        findRouteMethod
                .setQueryString("inline-relations-depth=1&q=host:" + appHost + ";domain_guid:" + domainGUID); //$NON-NLS-1$ //$NON-NLS-2$

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

        JSONObject response = status.getJsonData();
        if (response.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1)
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Route not found", null);

        /* retrieve the GUID */
        JSONArray resources = response.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
        JSONObject route = resources.getJSONObject(0);

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, route);

    } 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);
    }
}