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:org.orbisgis.commons.utils.FileUtils.java

/**
 * Gets a convenient name from an URI.//from w w  w . jav a 2 s.  co m
 * 
 * The URI scheme can be file or anything with a 'tablename' querystring parameter.
 * Anything else is unsupported.
 * 
 * @param u an URI
 * @return a name for it
 * @throws UnsupportedOperationException if the URI is unsupported.
 */
public static String getNameFromURI(URI u) {
    if ("file".equalsIgnoreCase(u.getScheme())) {
        return FilenameUtils.removeExtension(new File(u.getPath()).getName());
    } else {
        if ("jdbc".equalsIgnoreCase(u.getScheme())) {
            try {
                u = URI.create(u.getSchemeSpecificPart());
            } catch (IllegalArgumentException ex) {
                //Ignore
            }
        }
        String q = u.getQuery();
        if (q != null && !q.isEmpty()) {
            // With & parameters
            String[] pat = q.split("&");
            for (String aPat : pat) {
                if (aPat.toLowerCase().startsWith(TABLE_PARAM)) {
                    // Extract Table name
                    return aPat.substring(TABLE_PARAM.length());
                } else if (aPat.toLowerCase().startsWith(TABLE_PARAM_JDBC)) {
                    // Extract Table name
                    return aPat.substring(TABLE_PARAM_JDBC.length());
                }
            }
        }
        String path = u.getPath();
        if (path != null && !path.isEmpty()) {
            String[] paths = path.split("/");
            if (paths.length >= 1) {
                if (!paths[paths.length - 1].isEmpty()) {
                    return paths[paths.length - 1];
                }
            }
        }

    }

    throw new UnsupportedOperationException();
}

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

/**
 * Method for get request information from a http exchange.
 *
 * @param request HttpExchange// w  w  w. java2  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:org.wheelmap.android.net.request.RequestProcessor.java

public <T> T get(final URI uri, Class<T> clazz) throws RestClientException {
    Log.d(TAG, uri.getQuery());
    return restTemplate.getForObject(uri, clazz);
}

From source file:org.wheelmap.android.net.request.RequestProcessor.java

public <T> void put(final URI uri, final T putObject) throws RestClientException {
    Log.d(TAG, uri.getQuery());
    restTemplate.put(uri, putObject);//from w  w w .j a  va 2s. c o  m
}

From source file:com.cloud.utils.rest.BasicRestClient.java

private void logRequestExecution(final HttpUriRequest request) {
    final URI uri = request.getURI();
    String query = uri.getQuery();
    query = query != null ? "?" + query : "";
    s_logger.debug("Executig " + request.getMethod() + " request on " + clientContext.getTargetHost()
            + uri.getPath() + query);/* w  w  w .j a v  a 2 s.com*/
}

From source file:com.codecarpet.fbconnect.FBLoginDialog.java

@Override
protected void dialogDidSucceed(URI url) {
    String q = url.getQuery();
    int start = q.indexOf("auth_token=");
    if (start != -1) {
        int end = q.indexOf("&");
        int offset = start + "auth_token=".length();
        String token = end == -1 ? q.substring(offset) : q.substring(offset, end - offset);

        if (token != null) {
            connectToGetSession(token);/*from  w  w  w  . j  a va  2  s .co m*/
        }
    }
    //        super.dialogDidSucceed(url);
}

From source file:org.wheelmap.android.net.request.RequestProcessor.java

public <T> T post(final URI uri, final T postObject, Class<T> clazz) throws RestClientException {
    Log.d(TAG, uri.getQuery());
    return restTemplate.postForObject(uri, postObject, clazz);
}

From source file:org.wso2.identity.iml.dsl.mediators.OIDCResponseProcessor.java

@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("Message received at " + getName());
    }// w w  w.j a  v a2  s .c om

    AuthenticationSuccessResponse successResponse = AuthenticationSuccessResponse
            .parse(new URI((String) carbonMessage.getProperty(Constants.TO)));

    Map<String, String> query_pairs = new HashMap<>();
    URI uri = new URI((String) carbonMessage.getProperty(Constants.TO));
    String query = uri.getQuery();
    String[] pairs = query.split("&");

    for (String pair : pairs) {
        int idx = pair.indexOf("=");
        query_pairs.put(URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8.name()),
                URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8.name()));
    }

    SignedJWT signedJWT = (SignedJWT) successResponse.getIDToken();

    //TODO JWT Sig validation

    String state = query_pairs.get("state");

    carbonMessage.setProperty("signedJWT", signedJWT);
    carbonMessage.setProperty("sessionID", state);

    return next(carbonMessage, carbonCallback);
}

From source file:org.asqatasun.ruleimplementation.link.AbstractDownloadableLinkRuleImplementation.java

/**
 * //from   www  .  j  av  a  2 s  .  com
 * @param uri
 * @return whether the current link has a proper extension (link.html)
 */
private boolean isLinkWithProperExtension(URI uri) {
    if (StringUtils.isNotBlank(uri.getQuery())) {
        return false;
    }
    String path = uri.getPath();
    if (StringUtils.isBlank(path) || StringUtils.equals(path, SLASH_CHAR)) {
        return false;
    }
    int lastSlash = StringUtils.lastIndexOf(path, SLASH_CHAR);
    return StringUtils.substring(path, lastSlash).contains(POINT_CHAR);
}

From source file:com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration.java

/**
 * Fix a serverUrl./*w  ww. j  a  v  a 2  s. c  o  m*/
 *
 * @param serverUrl the server URL.
 * @return the normalized server URL.
 */
@NonNull
public static String normalizeServerUrl(@CheckForNull String serverUrl) {
    serverUrl = StringUtils.defaultIfBlank(serverUrl, BitbucketCloudEndpoint.SERVER_URL);
    try {
        URI uri = new URI(serverUrl).normalize();
        String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            // we only expect http / https, but also these are the only ones where we know the authority
            // is server based, i.e. [userinfo@]server[:port]
            // DNS names must be US-ASCII and are case insensitive, so we force all to lowercase

            String host = uri.getHost() == null ? null : uri.getHost().toLowerCase(Locale.ENGLISH);
            int port = uri.getPort();
            if ("http".equals(scheme) && port == 80) {
                port = -1;
            } else if ("https".equals(scheme) && port == 443) {
                port = -1;
            }
            serverUrl = new URI(scheme, uri.getUserInfo(), host, port, uri.getPath(), uri.getQuery(),
                    uri.getFragment()).toASCIIString();
        }
    } catch (URISyntaxException e) {
        // ignore, this was a best effort tidy-up
    }
    return serverUrl.replaceAll("/$", "");
}