Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
        throws URISyntaxException 

Source Link

Document

Constructs a hierarchical URI from the given components.

Usage

From source file:org.apache.hadoop.gateway.hbase.HBaseCookieManager.java

protected HttpRequest createKerberosAuthenticationRequest(HttpUriRequest userRequest) {
    URI userUri = userRequest.getURI();
    try {/*  ww w .j  a v  a 2s .c  om*/
        URI authUri = new URI(userUri.getScheme(), null, userUri.getHost(), userUri.getPort(), "/version",
                userUri.getQuery(), null);
        HttpRequest authRequest = new HttpGet(authUri);
        return authRequest;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(userUri.toString(), e);
    }
}

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList,
        boolean removeFragment) {

    if (href == null)
        return null;
    href = href.trim();/* w ww.j  av a2 s . c o m*/
    if (href.length() == 0)
        return null;

    String fragment = null;
    try {
        URI u = URIUtils.resolve(currentURL.toURI(), href);
        href = u.toString();
        href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList);
        URI uri = URI.create(href);
        uri = uri.normalize();

        String p = uri.getPath();
        if (p != null)
            if (p.contains("/./") || p.contains("/../"))
                return null;

        if (!removeFragment)
            fragment = uri.getRawFragment();

        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
                uri.getQuery(), fragment).normalize().toURL();
    } catch (MalformedURLException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (URISyntaxException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (IllegalArgumentException e) {
        Logging.info(e.getMessage());
        return null;
    }
}

From source file:SageCollegeProject.guideBox.java

public static String GetEncWebCall(String webcall) {
    try {/*www .  j  a  v a 2s  .c om*/
        URL url = new URL(webcall);
        URI test = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        return test.toASCIIString();
    } catch (URISyntaxException | MalformedURLException ex) {
        Logger.getLogger(guideBox.class.getName()).log(Level.SEVERE, null, ex);
    }
    return "";
}

From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpRequest.java

SimpleHttpRequest(String method, String pathBase, String... pathParam) throws URISyntaxException {
    this.httpMethod = method;

    URIBuilder baseBuilder = new URIBuilder(pathBase);
    if (baseBuilder.getScheme() == null) {
        baseBuilder = new URIBuilder("http://" + pathBase);
    }/*from w  w  w .j a  v a  2s  . c  o  m*/

    final StringBuilder pathBuilder = new StringBuilder(baseBuilder.getPath());
    for (String param : pathParam) {
        pathBuilder.append("/").append(param);
    }

    this.setURI(new URI(baseBuilder.getScheme(), baseBuilder.getUserInfo(), baseBuilder.getHost(),
            baseBuilder.getPort(), pathBuilder.toString(), null, null));
}

From source file:de.shadowhunt.subversion.RepositoryFactory.java

private static URI sanitise(final URI uri, final Resource path) {
    try {/*from  w  w w  .  java2  s  . c o m*/
        return new URI(uri.getScheme(), DEFAULT_USER_INFO, uri.getHost(), uri.getPort(), path.getValue(),
                DEFAULT_QUERY, DEFAULT_FRAGMENT);
    } catch (final URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the full request {@link URL} including the query parameter
 *
 * @return Request {@link URL} with query parameter
 * @throws IOException/*  ww  w .j  a va 2 s .  c o m*/
 * @throws URISyntaxException
 */
public static String resolveFullRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String query = request.getQueryString();

    URI uri = new URI(scheme, userInfo, host, port, path, query, null);
    return uri.toString();
}

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 {//  ww  w  .j a  va  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:com.collective.celos.ci.deploy.JScpWorker.java

URI getURIRespectingUsername(URI uri) throws URISyntaxException {

    if (userName != null && uri.getUserInfo() == null) {
        uri = new URI(uri.getScheme(), userName, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
                uri.getFragment());//w ww. j a  va2s .c o  m
    }
    return uri;
}

From source file:com.mooregreatsoftware.gitprocess.lib.CredentialHelperCredentialsProvider.java

@Nullable
@Override//from  ww w .  j  ava  2 s .co  m
@SuppressWarnings("override.return.invalid")
public Credentials getCredentials(AuthScope authscope) {
    if (authscope == null)
        return null;

    @SuppressWarnings("argument.type.incompatible")
    URI uri = e(() -> new URI(authscope.getScheme(), null, authscope.getHost(), authscope.getPort(), null, null,
            null));
    final String credentialHelper = remoteConfig.credentialHelper(uri);

    if (credentialHelper == null)
        return null;

    final String progName;
    if (credentialHelper.startsWith("/")) {
        progName = credentialHelper;
    } else {
        progName = "git-credential-" + credentialHelper;
    }

    return null;
}

From source file:jails.server.servlet.ServletServerHttpRequest.java

public URI getURI() {
    try {// ww  w .j a v a  2s  . c o m
        return new URI(servletRequest.getScheme(), null, servletRequest.getServerName(),
                servletRequest.getServerPort(), servletRequest.getRequestURI(), servletRequest.getQueryString(),
                null);
    } catch (URISyntaxException ex) {
        throw new IllegalStateException("Could not get HttpServletRequest URI: " + ex.getMessage(), ex);
    }
}