Example usage for java.net URI getQuery

List of usage examples for java.net URI getQuery

Introduction

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

Prototype

public String getQuery() 

Source Link

Document

Returns the decoded query component of this URI.

Usage

From source file:com.mellanox.jxio.ServerPortal.java

private URI replaceIPinURI(URI uriForForward, String uriIPAddress) {
    URI newUri = null;//from  www.  j  a  v a 2  s  .c  o m
    try {
        newUri = new URI(uriForForward.getScheme(), uriForForward.getUserInfo(),
                new URI(uriIPAddress).getHost(), uriForForward.getPort(), uriForForward.getPath(),
                uriForForward.getQuery(), uriForForward.getFragment());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        LOG.error(this.toLogString() + "URISyntaxException occured while trying to create a new URI");
    }
    return newUri;
}

From source file:com.cloud.hypervisor.xen.resource.XenServerStorageResource.java

private Map<String, String> getParameters(URI uri) {
    String parameters = uri.getQuery();
    Map<String, String> params = new HashMap<String, String>();
    List<String> paraLists = Arrays.asList(parameters.split("&"));
    for (String para : paraLists) {
        String[] pair = para.split("=");
        params.put(pair[0], pair[1]);//  w  w  w .j av a2 s .  co m
    }
    return params;
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitRemoteTest.java

@Test
public void testGetUnknownRemote() throws Exception {
    // clone a  repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    clone(clonePath);//  w  ww . j  a v a  2  s. c  o m

    // get project metadata
    WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    request = getGetGitRemoteRequest(gitRemoteUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    assertNotNull(remoteLocation);

    URI u = URI.create(toRelativeURI(remoteLocation));
    IPath p = new Path(u.getPath());
    p = p.uptoSegment(2).append("xxx").append(p.removeFirstSegments(3));
    URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    ServerStatus status = waitForTask(response);
    assertEquals(status.toString(), status.getHttpCode(), HttpURLConnection.HTTP_NOT_FOUND);

    p = new Path(u.getPath());
    p = p.uptoSegment(3).append("xxx").append(p.removeFirstSegments(3));
    nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
}

From source file:org.lockss.util.UrlUtil.java

/** Resolve child relative to base */
// This version is a wrapper for java.net.URI.resolve().  Java class has
// two undesireable behaviors: it resolves ("http://foo.bar", "a.html")
// to "http://foo.bara.html" (fails to supply missing "/" to base with no
// path), and it resolves ("http://foo.bar/xxx.php", "?foo=bar") to
// "http://foo.bar/?foo=bar" (in accordance with RFC 2396), while all the
// browsers resolve it to "http://foo.bar/xxx.php?foo=bar" (in accordance
// with RFC 1808).  This mimics enough of the logic of
// java.net.URI.resolve(URI, URI) to detect those two cases, and defers
// to the URI code for other cases.

private static java.net.URI resolveUri0(java.net.URI base, java.net.URI child) throws MalformedURLException {

    // check if child is opaque first so that NPE is thrown 
    // if child is null.
    if (child.isOpaque() || base.isOpaque()) {
        return child;
    }/*from w  ww . j  av a2s.c  o m*/

    try {
        String scheme = base.getScheme();
        String authority = base.getAuthority();
        String path = base.getPath();
        String query = base.getQuery();
        String fragment = child.getFragment();

        // If base has null path, ensure authority is separated from path in
        // result.  (java.net.URI resolves ("http://foo.bar", "x.y") to
        // http://foo.barx.y)
        if (StringUtil.isNullString(base.getPath())) {
            path = "/";
            base = new java.net.URI(scheme, authority, path, query, fragment);
        }

        // Absolute child
        if (child.getScheme() != null)
            return child;

        if (child.getAuthority() != null) {
            // not relative, defer to URI
            return base.resolve(child);
        }

        // Fragment only, return base with this fragment
        if (child.getPath().equals("") && (child.getFragment() != null) && (child.getQuery() == null)) {
            if ((base.getFragment() != null) && child.getFragment().equals(base.getFragment())) {
                return base;
            }
            java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment);
            return ru;
        }

        query = child.getQuery();

        authority = base.getAuthority();

        if (StringUtil.isNullString(child.getPath())) {
            // don't truncate base path if child has no path
            path = base.getPath();
        } else if (child.getPath().charAt(0) == '/') {
            // Absolute child path
            path = child.getPath();
        } else {
            // normal relative path, defer to URI
            return base.resolve(child);
        }
        // create URI from relativized components
        java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment);
        return ru;
    } catch (URISyntaxException e) {
        throw newMalformedURLException(e);
    }
}

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

/**
 * This method retrieve the MP4 streaming URL from assetInfoFile.
 * /*from  ww w .j  a v a 2s .  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.soundcloud.playerapi.Request.java

/**
 * constructs a a request from URI. the hostname+scheme will be ignored
 * @param uri - the uri// w ww. j  av  a  2 s  .  c om
 */
public Request(URI uri) {
    this(uri.getPath() == null ? "/" : uri.getPath() + (uri.getQuery() == null ? "" : "?" + uri.getQuery()));
}

From source file:org.ldp4j.tutorial.client.CachedRepresentationManager.java

private File createFile(String resource) {
    URI uri = URI.create(resource);
    StringBuilder builder = new StringBuilder();
    builder.append(uri.getScheme()).append("_");
    String userInfo = uri.getUserInfo();
    if (userInfo != null) {
        builder.append(userInfo).append("@");
    }//from w  w w.j av a 2s.  c  o m
    builder.append(uri.getHost());
    if (uri.getPort() >= 0) {
        builder.append("_").append(uri.getPort());
    }
    if (uri.getPath() != null) {
        builder.append(uri.getRawPath().replace("/", "_"));
    }
    if (uri.getQuery() != null) {
        builder.append("?").append(uri.getRawQuery());
    }
    if (uri.getFragment() != null) {
        builder.append("#").append(uri.getRawFragment());
    }
    builder.append(".dat");
    File file = new File(this.cacheDirectory, builder.toString());
    return file;
}

From source file:org.dthume.maven.xpom.impl.saxon.XPomUri.java

public XPomUri(final String uriString) throws URISyntaxException {
    if (null == uriString)
        throw new URISyntaxException(uriString, "Cannot parse null URI");

    final URI jUri = new URI(uriString);

    if (!"xpom".equals(jUri.getScheme())) {
        throw new URISyntaxException(uriString, "Not in xpom://<coords>[/<path>] format");
    }/*from w  w  w  .  j a  v a2 s .  com*/

    final Matcher matcher = ARTIFACT_PATTERN.matcher(jUri.getPath());
    if (!matcher.matches()) {
        throw new URISyntaxException(uriString, "XPOM scheme but not in xpom://<coords>[/<path>] format");
    }

    final String groupId = jUri.getAuthority();

    coords = toCoords(matcher, groupId);
    resource = toResource(matcher);
    params = unmodifiableMap(toParams(jUri.getQuery()));
}

From source file:com.pwc.sns.testsupport.WireMockTestClient.java

public WireMockResponse getViaProxy(String url, int proxyPort) {
    URI targetUri = URI.create(url);

    HttpHost proxy = new HttpHost(address, proxyPort, targetUri.getScheme());

    DefaultHttpClient httpclient = new DefaultHttpClient(createClientConnectionManagerWithSSLSettings());
    try {//w  w w .j  a va 2  s  .  c o m
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        HttpHost target = new HttpHost(targetUri.getHost(), targetUri.getPort(), targetUri.getScheme());
        HttpGet req = new HttpGet(
                targetUri.getPath() + (isNullOrEmpty(targetUri.getQuery()) ? "" : "?" + targetUri.getQuery()));
        req.removeHeaders("Host");

        System.out.println("executing request to " + targetUri + "(" + target + ") via " + proxy);
        HttpResponse httpResponse = httpclient.execute(target, req);
        return new WireMockResponse(httpResponse);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java

/**
 * <p>//from   w ww. j  ava  2 s  .c om
 * TEE will automatically correct the endpoints registered URL when creating
 * the web service, however we must provide a mechansim to correct fully
 * qualified URI's provided as additional URI from the same webservice.
 * </p>
 * <p>
 * We compare the passed uri with the registered web service endpoint, if
 * they share the same root (i.e. http://TFSERVER) then we correct the
 * passed uri to be the same as the corrected web service enpoint (i.e.
 * http://tfsserver.mycompany.com)
 * </p>
 *
 * @see WSSClient#getFixedURI(String)
 */
public String getFixedURI(final String uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    try {
        // Get what the server thinks the url is.
        String url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE,
                ServiceInterfaceNames.REPORTING);

        if (url == null || url.length() == 0) {
            // Might be a Rosario server
            url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE,
                    ServiceInterfaceNames.REPORTING_WEB_SERVICE_URL);
            if (url == null || url.length() == 0) {
                // Couldn't figure this out - just give up and return what
                // we
                // were passed.
                return uri;
            }
            is2010Server = true;
        }

        final URI registeredEndpointUri = new URI(url);

        final URI passedUri = new URI(uri);

        if (passedUri.getScheme().equals(registeredEndpointUri.getScheme())
                && passedUri.getHost().equals(registeredEndpointUri.getHost())
                && passedUri.getPort() == registeredEndpointUri.getPort()) {
            final URI endpointUri = ((SOAPService) getProxy()).getEndpoint();
            final URI fixedUri = new URI(endpointUri.getScheme(), endpointUri.getHost(), passedUri.getPath(),
                    passedUri.getQuery(), passedUri.getFragment());
            return fixedUri.toASCIIString();
        }
    } catch (final URISyntaxException e) {
        // ignore;
    }
    return uri;
}