Search in sources :

Example 96 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project sling by apache.

the class HttpTransportUtils method getDeleteUri.

private static URI getDeleteUri(URI uri, String id) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter("operation", "delete");
    uriBuilder.addParameter("id", id);
    return uriBuilder.build();
}
Also used : URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 97 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project sling by apache.

the class RequestUtils method appendDistributionRequest.

public static URI appendDistributionRequest(URI uri, DistributionRequest distributionRequest) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter(DistributionParameter.ACTION.toString(), distributionRequest.getRequestType().name());
    String[] paths = distributionRequest.getPaths();
    if (paths != null) {
        for (String path : paths) {
            uriBuilder.addParameter(DistributionParameter.PATH.toString(), path);
        }
    }
    return uriBuilder.build();
}
Also used : URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 98 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project sling by apache.

the class AbstractSlingClient method getUrl.

/**
     * Creates a full URL for a given path with additional parameters. Same as {@link #getUrl(String)}, but adds the parameters in the URI.
     *
     * @param path path relative to server url; can start with / but should not include the server context path
     * @param parameters url parameters to be added to the url
     * @return full url as URI
     * @throws IllegalArgumentException if path or parameters cannot be parsed into an URI
     * @throws NullPointerException if path is null
     */
public URI getUrl(String path, List<NameValuePair> parameters) {
    // add server url and path
    URIBuilder uriBuilder = new URIBuilder(getUrl(path));
    // add parameters
    parameters = (parameters != null) ? parameters : new ArrayList<NameValuePair>(0);
    uriBuilder.addParameters(parameters);
    try {
        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 99 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project cas by apereo.

the class ShibbolethIdPEntityIdAuthenticationServiceSelectionStrategy method getEntityIdAsParameter.

/**
 * Gets entity id as parameter.
 *
 * @param service the service
 * @return the entity id as parameter
 */
protected static Optional<String> getEntityIdAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional<NameValuePair> param = builder.getQueryParams().stream().filter(p -> p.getName().equals(SamlProtocolConstants.PARAMETER_ENTITY_ID)).findFirst();
        if (param.isPresent()) {
            return Optional.of(param.get().getValue());
        }
        final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext();
        if (request != null && StringUtils.isNotBlank(request.getQueryString())) {
            final String[] query = request.getQueryString().split("&");
            final Optional<String> paramRequest = Arrays.stream(query).map(p -> {
                final List<String> params = Splitter.on("=").splitToList(p);
                return Pair.of(params.get(0), params.get(1));
            }).filter(p -> p.getKey().equals(SamlProtocolConstants.PARAMETER_ENTITY_ID)).map(Pair::getValue).findFirst();
            return paramRequest;
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : Ordered(org.springframework.core.Ordered) Arrays(java.util.Arrays) URIBuilder(org.apache.http.client.utils.URIBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) AllArgsConstructor(lombok.AllArgsConstructor) NameValuePair(org.apache.http.NameValuePair) WebUtils(org.apereo.cas.web.support.WebUtils) Splitter(com.google.common.base.Splitter) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) NameValuePair(org.apache.http.NameValuePair) List(java.util.List) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 100 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project cas by apereo.

the class BaseWSFederationRequestController method constructServiceUrl.

/**
 * Construct service url string.
 *
 * @param request      the request
 * @param response     the response
 * @param wsfedRequest the ws federation request
 * @return the service url
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final WSFederationRequest wsfedRequest) {
    try {
        final URIBuilder builder = new URIBuilder(this.callbackService.getId());
        builder.addParameter(WSFederationConstants.WA, wsfedRequest.getWa());
        builder.addParameter(WSFederationConstants.WREPLY, wsfedRequest.getWreply());
        builder.addParameter(WSFederationConstants.WTREALM, wsfedRequest.getWtrealm());
        if (StringUtils.isNotBlank(wsfedRequest.getWctx())) {
            builder.addParameter(WSFederationConstants.WCTX, wsfedRequest.getWctx());
        }
        if (StringUtils.isNotBlank(wsfedRequest.getWfresh())) {
            builder.addParameter(WSFederationConstants.WREFRESH, wsfedRequest.getWfresh());
        }
        if (StringUtils.isNotBlank(wsfedRequest.getWhr())) {
            builder.addParameter(WSFederationConstants.WHR, wsfedRequest.getWhr());
        }
        if (StringUtils.isNotBlank(wsfedRequest.getWreq())) {
            builder.addParameter(WSFederationConstants.WREQ, wsfedRequest.getWreq());
        }
        final URI url = builder.build();
        LOGGER.trace("Built service callback url [{}]", url);
        return org.jasig.cas.client.util.CommonUtils.constructServiceUrl(request, response, url.toString(), casProperties.getServer().getName(), CasProtocolConstants.PARAMETER_SERVICE, CasProtocolConstants.PARAMETER_TICKET, false);
    } catch (final Exception e) {
        throw new SamlException(e.getMessage(), e);
    }
}
Also used : SamlException(org.apereo.cas.support.saml.SamlException) URI(java.net.URI) SamlException(org.apereo.cas.support.saml.SamlException) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

URIBuilder (org.apache.http.client.utils.URIBuilder)107 URISyntaxException (java.net.URISyntaxException)42 URI (java.net.URI)37 HttpGet (org.apache.http.client.methods.HttpGet)22 IOException (java.io.IOException)21 NameValuePair (org.apache.http.NameValuePair)13 HttpEntity (org.apache.http.HttpEntity)10 NotNull (org.jetbrains.annotations.NotNull)9 Map (java.util.Map)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpResponse (org.apache.http.HttpResponse)7 List (java.util.List)6 HttpClient (org.apache.http.client.HttpClient)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 Gson (com.google.gson.Gson)4 URL (java.net.URL)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 HttpPost (org.apache.http.client.methods.HttpPost)4