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:org.restheart.test.integration.HttpClientAbstactIT.java

protected static URI addCheckEtag(URI uri) throws URISyntaxException {
    return createURIBuilder(uri.getPath()).addParameter("checkEtag", null).addParameter("hal", "f").build();
}

From source file:org.apache.olingo.client.core.uri.URIUtils.java

public static URI addValueSegment(final URI uri) {
    final URI res;
    if (uri.getPath().endsWith(SegmentType.VALUE.getValue())) {
        res = uri;
    } else {/*from  w  ww.ja v  a  2s . c o  m*/
        try {
            res = new URIBuilder(uri).setPath(uri.getPath() + "/" + SegmentType.VALUE.getValue()).build();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }

    return res;
}

From source file:org.switchyard.component.http.endpoint.StandaloneEndpointPublisher.java

/**
 * Method for get request information from a http exchange.
 *
 * @param request HttpExchange//from www .  ja v a  2 s . c  o  m
 * @param type ContentType
 * @return Request information from a http exchange
 * @throws IOException when the request information could not be read
 */
public static HttpRequestInfo getRequestInfo(HttpExchange request, ContentType type) throws IOException {
    HttpRequestInfo requestInfo = new HttpRequestInfo();

    if (request.getHttpContext().getAuthenticator() instanceof BasicAuthenticator) {
        requestInfo.setAuthType(HttpServletRequest.BASIC_AUTH);
    }
    URI u = request.getRequestURI();
    URI requestURI = null;
    try {
        requestURI = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), null, null);
    } catch (URISyntaxException e) {
        // Strange that this could happen when copying from another URI.
        LOGGER.debug(e);
    }
    requestInfo.setCharacterEncoding(type.getCharset());
    requestInfo.setContentType(type.toString());
    requestInfo.setContextPath(request.getHttpContext().getPath());
    requestInfo.setLocalAddr(request.getLocalAddress().getAddress().getHostAddress());
    requestInfo.setLocalName(request.getLocalAddress().getAddress().getHostName());
    requestInfo.setMethod(request.getRequestMethod());
    requestInfo.setProtocol(request.getProtocol());
    requestInfo.setQueryString(u.getQuery());
    requestInfo.setRemoteAddr(request.getRemoteAddress().getAddress().getHostAddress());
    requestInfo.setRemoteHost(request.getRemoteAddress().getAddress().getHostName());
    if (request.getHttpContext().getAuthenticator() instanceof BasicAuthenticator) {
        requestInfo.setRemoteUser(request.getPrincipal().getUsername());
    }
    requestInfo.setContentLength(request.getRequestBody().available());
    // requestInfo.setRequestSessionId(request.getRequestedSessionId());
    if (requestURI != null) {
        requestInfo.setRequestURI(requestURI.toString());
    }
    requestInfo.setScheme(u.getScheme());
    requestInfo.setServerName(u.getHost());
    requestInfo.setRequestPath(u.getPath());

    // Http Query params...
    if (requestInfo.getQueryString() != null) {
        Charset charset = null;
        if (type.getCharset() != null) {
            try {
                charset = Charset.forName(type.getCharset());
            } catch (Exception exception) {
                LOGGER.debug(exception);
            }
        }
        for (NameValuePair nameValuePair : URLEncodedUtils.parse(requestInfo.getQueryString(), charset)) {
            requestInfo.addQueryParam(nameValuePair.getName(), nameValuePair.getValue());
        }
    }

    // Credentials...
    requestInfo.getCredentials().addAll(new HttpExchangeCredentialExtractor().extract(request));

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(requestInfo);
    }

    return requestInfo;
}

From source file:com.textocat.textokit.commons.util.DocumentUtils.java

public static String getFilename(String uriStr) throws URISyntaxException {
    URI uri = new URI(uriStr);
    String path;/*from   w  ww  .  jav  a  2  s. c  o  m*/
    if (uri.isOpaque()) {
        // TODO this is a hotfix. In future we should avoid setting opaque source URIs in DocumentMetadata
        path = uri.getSchemeSpecificPart();
    } else {
        path = uri.getPath();
    }
    return FilenameUtils.getName(path);
}

From source file:com.netflix.spinnaker.orca.config.RedisConfiguration.java

@Deprecated // rz - Kept for backwards compat with old connection configs
public static JedisPool createPool(GenericObjectPoolConfig redisPoolConfig, String connection, int timeout,
        Registry registry, String poolName) {
    URI redisConnection = URI.create(connection);

    String host = redisConnection.getHost();
    int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();

    String redisConnectionPath = isNotEmpty(redisConnection.getPath()) ? redisConnection.getPath()
            : "/" + DEFAULT_DATABASE;
    int database = Integer.parseInt(redisConnectionPath.split("/", 2)[1]);

    String password = redisConnection.getUserInfo() != null ? redisConnection.getUserInfo().split(":", 2)[1]
            : null;/*from  w w w  .  j a  v a  2s  .  c o m*/

    JedisPool jedisPool = new JedisPool(
            redisPoolConfig != null ? redisPoolConfig : new GenericObjectPoolConfig(), host, port, timeout,
            password, database, null);
    final Field poolAccess;
    try {
        poolAccess = Pool.class.getDeclaredField("internalPool");
        poolAccess.setAccessible(true);
        GenericObjectPool<Jedis> pool = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool);
        registry.gauge(registry.createId("redis.connectionPool.maxIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.minIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMinIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numActive", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getNumActive()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numWaiters", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        return jedisPool;
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new BeanCreationException("Error creating Redis pool", e);
    }
}

From source file:ch.entwine.weblounge.common.impl.util.TestUtils.java

/**
 * Issues the the given request.//from ww  w . j ava  2 s.co m
 * 
 * @param httpClient
 *          the http client
 * @param request
 *          the request
 * @param params
 *          the request parameters
 * @throws Exception
 *           if the request fails
 */
public static HttpResponse request(HttpClient httpClient, HttpUriRequest request, String[][] params)
        throws Exception {
    if (params != null) {
        if (request instanceof HttpGet) {
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            if (params.length > 0) {
                for (String[] param : params) {
                    if (param.length < 2)
                        continue;
                    qparams.add(new BasicNameValuePair(param[0], param[1]));
                }
            }
            URI requestURI = request.getURI();
            URI uri = URIUtils.createURI(requestURI.getScheme(), requestURI.getHost(), requestURI.getPort(),
                    requestURI.getPath(), URLEncodedUtils.format(qparams, "utf-8"), null);
            HeaderIterator headerIterator = request.headerIterator();
            request = new HttpGet(uri);
            while (headerIterator.hasNext()) {
                request.addHeader(headerIterator.nextHeader());
            }
        } else if (request instanceof HttpPost) {
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (String[] param : params)
                formparams.add(new BasicNameValuePair(param[0], param[1]));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8");
            ((HttpPost) request).setEntity(entity);
        } else if (request instanceof HttpPut) {
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (String[] param : params)
                formparams.add(new BasicNameValuePair(param[0], param[1]));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8");
            ((HttpPut) request).setEntity(entity);
        }
    } else {
        if (request instanceof HttpPost || request instanceof HttpPut) {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(new ArrayList<NameValuePair>(), "utf-8");
            ((HttpEntityEnclosingRequestBase) request).setEntity(entity);
        }
    }
    return httpClient.execute(request);
}

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static boolean areEqual(URI lhs, URI rhs) {
    Validate.notNull(lhs, "lhs");
    Validate.notNull(rhs, "rhs");

    URI lhsCopy;//  w  w w.ja  va2  s.c o m
    URI rhsCopy;
    try {
        lhsCopy = new URI(lhs.getScheme(), lhs.getUserInfo(), lhs.getHost(), URIUtils.getPort(lhs),
                lhs.getPath(), lhs.getQuery(), lhs.getFragment());
        rhsCopy = new URI(rhs.getScheme(), rhs.getUserInfo(), rhs.getHost(), URIUtils.getPort(rhs),
                rhs.getPath(), rhs.getQuery(), rhs.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to transform uri for equality check", e);
    }

    return lhsCopy.equals(rhsCopy);
}

From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java

private static File locateBootstrapperFile() {
    ProtectionDomain protectionDomain = Bootstrapper.class.getProtectionDomain();
    if (protectionDomain == null) {
        JOptionPane.showMessageDialog(null,
                "Error: Could not locate Bootstrapper. (ProtectionDomain was null)");
        throw new RuntimeException();
    }/*from   w ww.  j a v a2 s.c o m*/
    CodeSource codeSource = protectionDomain.getCodeSource();
    if (codeSource == null) {
        JOptionPane.showMessageDialog(null, "Error: Could not locate Bootstrapper. (CodeSource was null)");
        throw new RuntimeException();
    }
    URL url = codeSource.getLocation();
    if (url == null) {
        JOptionPane.showMessageDialog(null, "Error: Could not locate Bootstrapper. (Location was null)");
        throw new RuntimeException();
    }
    try {
        URI uri = url.toURI();
        File file = new File(uri.getPath());
        if (file.isDirectory()) {
            if (!Boolean.getBoolean("com.heliosdecompiler.isDebugging")) {
                JOptionPane.showMessageDialog(null,
                        "Error: Could not locate Bootstrapper. (File is directory)");
                throw new RuntimeException(file.getAbsolutePath());
            } else {
                System.out.println(
                        "Warning: Could not locate bootstrapper but com.heliosdecompiler.isDebugging was set to true");
            }
        } else if (!file.exists()) {
            JOptionPane.showMessageDialog(null, "Error: Could not locate Bootstrapper. (File does not exist)");
            throw new RuntimeException();
        } else if (!file.canRead()) {
            JOptionPane.showMessageDialog(null, "Error: Could not locate Bootstrapper. (File is not readable)");
            throw new RuntimeException();
        }
        return file;
    } catch (URISyntaxException e) {
        JOptionPane.showMessageDialog(null, "Error: Could not locate Bootstrapper. (URISyntaxException)");
        throw new RuntimeException();
    }
}

From source file:com.jaeksoft.searchlib.web.AbstractServlet.java

protected static URI buildUri(URI uri, String additionalPath, String indexName, String login, String apiKey,
        String additionnalQuery) throws URISyntaxException {
    StringBuilder path = new StringBuilder(uri.getPath());
    if (additionalPath != null)
        path.append(additionalPath);/* ww  w.  j av a2 s  . co m*/
    StringBuilder query = new StringBuilder();
    if (indexName != null) {
        query.append("index=");
        query.append(indexName);
    }
    if (login != null) {
        query.append("&login=");
        query.append(login);
    }
    if (apiKey != null) {
        query.append("&key=");
        query.append(apiKey);
    }
    if (additionnalQuery != null) {
        if (query.length() > 0)
            query.append("&");
        query.append(additionnalQuery);
    }
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path.toString(),
            query.toString(), uri.getFragment());

}

From source file:com.cloud.utils.UriUtils.java

public static boolean hostAndPathPresent(URI uri) {
    return !(uri.getHost() == null || uri.getHost().trim().isEmpty() || uri.getPath() == null
            || uri.getPath().trim().isEmpty());
}