Package org.apache.http.client.utils

Examples of org.apache.http.client.utils.URIBuilder


        return sendRequest(filters.applyFilters(httpRequest));
    }

    private void updateURLAndHost(HttpRequest httpRequest, HttpForward httpForward) {
        try {
            URIBuilder uriBuilder = new URIBuilder(httpRequest.getURL());
            uriBuilder.setPath(httpRequest.getPath().startsWith("/") ? httpRequest.getPath() : "/" + httpRequest.getPath());
            uriBuilder.setHost(httpForward.getHost());
            uriBuilder.setPort(httpForward.getPort());
            uriBuilder.setScheme(httpForward.getScheme().name().toLowerCase());
            for (Parameter parameter : httpRequest.getQueryStringParameters()) {
                for (String value : parameter.getValues()) {
                    uriBuilder.addParameter(parameter.getName(), value);
                }
            }
            httpRequest.withURL(uriBuilder.toString());
            httpRequest.replaceHeader(header(HttpHeaders.Names.HOST, String.format("%s:%d", uriBuilder.getHost(), uriBuilder.getPort())));
        } catch (URISyntaxException e) {
            logger.warn("URISyntaxException for url " + httpRequest.getURL(), e);
        }
    }
View Full Code Here


  protected HttpResponseContent performHttpGetCall(String url, Map<String, String> headers) throws Exception,
      HttpCallException {

    myLogger.debug("Going to perform remote system HTTP GET request to the the {}", url);

    URIBuilder builder = new URIBuilder(url);
    HttpGet method = new HttpGet(builder.build());
    if (headers != null) {
      for (String headerName : headers.keySet())
        method.addHeader(headerName, headers.get(headerName));
    }
    try {

      BasicHttpContext localcontext = new BasicHttpContext();
      if (isAuthConfigured) {
        // Preemptive authentication enabled - see
        // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e1032
        HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
      }
View Full Code Here

  protected byte[] performJIRAGetRESTCall(String restOperation, List<NameValuePair> params) throws Exception {

    String url = jiraRestAPIUrlBase + restOperation;
    logger.debug("Go to perform JIRA REST API call to the {} with parameters {}", url, params);

    URIBuilder builder = new URIBuilder(url);
    if (params != null) {
      for (NameValuePair param : params) {
        builder.addParameter(param.getName(), param.getValue());
      }
    }
    HttpGet method = new HttpGet(builder.build());
    method.addHeader("Accept", "application/json");
    try {

      // Preemptive authentication enabled - see
      // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e1032
      HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
      AuthCache authCache = new BasicAuthCache();
      BasicScheme basicAuth = new BasicScheme();
      authCache.put(targetHost, basicAuth);
      BasicHttpContext localcontext = new BasicHttpContext();
      localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
View Full Code Here

      throw new IOException("Could not find image with txid " + txId);
    }

    HttpURLConnection connection = null;
    try {
      URIBuilder uriBuilder = new URIBuilder(url.toURI());

      // write all params for image upload request as query itself.
      // Request body contains the image to be uploaded.
      Map<String, String> params = ImageServlet.getParamsForPutImage(storage,
          txId, imageFile.length(), nnf);
      for (Entry<String, String> entry : params.entrySet()) {
        uriBuilder.addParameter(entry.getKey(), entry.getValue());
      }

      URL urlWithParams = uriBuilder.build().toURL();
      connection = (HttpURLConnection) connectionFactory.openConnection(
          urlWithParams, UserGroupInformation.isSecurityEnabled());
      // Set the request to PUT
      connection.setRequestMethod("PUT");
      connection.setDoOutput(true);
View Full Code Here

            if (entity == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method)
                    || HttpPut.METHOD_NAME.equalsIgnoreCase(method))) {
                entity = new UrlEncodedFormEntity(parameters, HTTP.DEF_CONTENT_CHARSET);
            } else {
                try {
                    uri = new URIBuilder(uri).addParameters(parameters).build();
                } catch (final URISyntaxException ex) {
                    // should never happen
                }
            }
        }
View Full Code Here

    /**
     * @since 4.1
     */
    protected URI createLocationURI(final String location) throws ProtocolException {
        try {
            final URIBuilder b = new URIBuilder(new URI(location).normalize());
            final String host = b.getHost();
            if (host != null) {
                b.setHost(host.toLowerCase(Locale.ENGLISH));
            }
            final String path = b.getPath();
            if (TextUtils.isEmpty(path)) {
                b.setPath("/");
            }
            return b.build();
        } catch (final URISyntaxException ex) {
            throw new ProtocolException("Invalid redirect URI: " + location, ex);
        }
    }
View Full Code Here

   */
  @Override
  public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig, String redirectUri, String nonce, String state, Map<String, String> options) {
    try {

      URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
      uriBuilder.addParameter("response_type", "code");
      uriBuilder.addParameter("client_id", clientConfig.getClientId());
      uriBuilder.addParameter("scope", Joiner.on(" ").join(clientConfig.getScope()));

      uriBuilder.addParameter("redirect_uri", redirectUri);

      uriBuilder.addParameter("nonce", nonce);

      uriBuilder.addParameter("state", state);

      // Optional parameters:
      for (Entry<String, String> option : options.entrySet()) {
        uriBuilder.addParameter(option.getKey(), option.getValue());
      }

      return uriBuilder.build().toString();

    } catch (URISyntaxException e) {
      throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);

    }
View Full Code Here

    JwtEncryptionAndDecryptionService encryptor = encrypterService.getEncrypter(serverConfig.getJwksUri());

    encryptor.encryptJwt(jwt);

    try {
      URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
      uriBuilder.addParameter("request", jwt.serialize());

      // build out the URI
      return uriBuilder.build().toString();
    } catch (URISyntaxException e) {
      throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
    }
  }
View Full Code Here

    SignedJWT jwt = new SignedJWT(new JWSHeader(signingAndValidationService.getDefaultSigningAlgorithm()), claims);

    signingAndValidationService.signJwt(jwt);

    try {
      URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
      uriBuilder.addParameter("request", jwt.serialize());

      // build out the URI
      return uriBuilder.build().toString();
    } catch (URISyntaxException e) {
      throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
    }
  }
View Full Code Here

     * @return URI which has been encoded as necessary
     * @throws URISyntaxException
     * @throws UnsupportedEncodingException
     */
    public static final URI sanitizeUrl(URL url) throws URISyntaxException, UnsupportedEncodingException {
        URIBuilder builder =
                new URIBuilder()
            .setScheme(url.getProtocol())
            .setHost(url.getHost())
            .setPort(url.getPort())
            .setUserInfo(url.getUserInfo())
            .setPath(url.getPath() != null ? URLDecoder.decode(url.getPath(), "UTF-8") : null) // $NON-NLS-1$
            .setQuery(url.getQuery());
        URI uri = builder.build();
        return uri;
    }
View Full Code Here

TOP

Related Classes of org.apache.http.client.utils.URIBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.