Java Code Examples for org.apache.http.client.utils.URIBuilder#setPath()

The following examples show how to use org.apache.http.client.utils.URIBuilder#setPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebServicesVersionConversion.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException
{
  URIBuilder uriBuilder = new URIBuilder(cr.getURI());
  String path = uriBuilder.getPath();
  uriBuilder.setPath(converter.convertCommandPath(path));
  try {
    cr.setURI(uriBuilder.build());
    ClientResponse response = getNext().handle(cr);
    String newEntity = converter.convertResponse(path, response.getEntity(String.class));
    response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes()));
    return response;
  } catch (Exception ex) {
    throw new ClientHandlerException(ex);
  }
}
 
Example 2
Source File: SalesforceExtractor.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
private static String buildUrl(String path, List<NameValuePair> qparams) throws RestApiClientException {
  URIBuilder builder = new URIBuilder();
  builder.setPath(path);
  ListIterator<NameValuePair> i = qparams.listIterator();
  while (i.hasNext()) {
    NameValuePair keyValue = i.next();
    builder.setParameter(keyValue.getName(), keyValue.getValue());
  }
  URI uri;
  try {
    uri = builder.build();
  } catch (Exception e) {
    throw new RestApiClientException("Failed to build url; error - " + e.getMessage(), e);
  }
  return new HttpGet(uri).getURI().toString();
}
 
Example 3
Source File: PxtAuthenticationServiceTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws Exception something bad happened
 */
public final void testRedirectToLoginSetsURLBounceRequestAttribute() throws Exception {
    setupPxtDelegate(true, false, 1234L);
    setupGetRequestURI("/rhn/YourRhn.do");
    setUpRedirectToLogin();

    URIBuilder uriBounceBuilder = new URIBuilder();
    uriBounceBuilder.setPath("/rhn/YourRhn.do");
    uriBounceBuilder.addParameter("question", "param 1 = 'Who is the one?'");
    uriBounceBuilder.addParameter("answer", "param 2 = 'Neo is the one!'");

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setPath("/rhn/manager/login");
    uriBuilder.addParameter("url_bounce", uriBounceBuilder.toString());
    uriBuilder.addParameter("request_method", "POST");

    context().checking(new Expectations() { {
        allowing(mockResponse).sendRedirect(uriBuilder.toString());
        will(returnValue(null));
        allowing(mockRequest).getRequestURI();
        will(returnValue("/rhn/YourRhn.do"));
    } });

    runRedirectToLoginTest();
}
 
Example 4
Source File: Utilities.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getDcaCMCredentialUrl(@NotNull final String protocol,
                                           @NotNull final String dcaHost,
                                           @NotNull final String dcaPort,
                                           @NotNull final String credentialUuid) {
    final URIBuilder uriBuilder = getUriBuilder(protocol, dcaHost, dcaPort);
    uriBuilder.setPath(String.format("%s/%s/%s", DCA_CM_CREDENTIAL_PATH, credentialUuid, DATA_PATH));

    try {
        return uriBuilder.build().toURL().toString();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: RunImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getApplyDetailsUrl(@NotNull final String applyId) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder();
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(API_VERSION)
            .append(APPLY_DETAILS_PATH)
            .append(PATH_SEPARATOR)
            .append(applyId);
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 6
Source File: TaskImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getTaskDetailsURL(NutanixGetTaskDetailsInputs nutanixGetTaskDetailsInputs) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder(nutanixGetTaskDetailsInputs.getCommonInputs());
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(nutanixGetTaskDetailsInputs.getCommonInputs().getAPIVersion())
            .append(GET_TASK_DETAILS_PATH)
            .append(PATH_SEPARATOR)
            .append(nutanixGetTaskDetailsInputs.getTaskUUID());
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 7
Source File: VMImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String createVMURL(NutanixCreateVMInputs nutanixCreateVMInputs) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder(nutanixCreateVMInputs.getCommonInputs());
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(nutanixCreateVMInputs.getCommonInputs().getAPIVersion())
            .append(GET_VM_DETAILS_PATH);
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 8
Source File: NicImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String AddNicURL(NutanixAddNicInputs nutanixAttachNicInputs) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder(nutanixAttachNicInputs.getCommonInputs());
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(nutanixAttachNicInputs.getCommonInputs().getAPIVersion())
            .append(GET_VM_DETAILS_PATH)
            .append(PATH_SEPARATOR)
            .append(nutanixAttachNicInputs.getVmUUID())
            .append(ADD_NIC_PATH);
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 9
Source File: Utilities.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getDcaResourceUrl(@NotNull final String protocol,
                                       @NotNull final String dcaHost,
                                       @NotNull final String dcaPort,
                                       @NotNull final String resourceUuid) {
    final URIBuilder uriBuilder = getUriBuilder(protocol, dcaHost, dcaPort);
    uriBuilder.setPath(String.format("%s/%s", DCA_RESOURCE_PATH, resourceUuid));

    try {
        return uriBuilder.build().toURL().toString();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: JettyServer.java    From celos with Apache License 2.0 5 votes vote down vote up
private void startServer() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("WEB-INF");
    URIBuilder uriBuilder = new URIBuilder(url.toURI());
    uriBuilder.setPath(Paths.get(url.getPath()).getParent().toString());

    context = new WebAppContext(uriBuilder.toString() + "/", "/");
    context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    context.setExtractWAR(false);

    server.setHandler(context);
    server.start();
}
 
Example 11
Source File: VMImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String updateVMURL(NutanixUpdateVMInputs nutanixUpdateVMInputs) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder(nutanixUpdateVMInputs.getCommonInputs());
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(nutanixUpdateVMInputs.getCommonInputs().getAPIVersion())
            .append(GET_VM_DETAILS_PATH)
            .append(PATH_SEPARATOR)
            .append(nutanixUpdateVMInputs.getVmUUID());
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 12
Source File: HttpClientUtil.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
public static String httpGetRequest(String url, Map<String, Object> params) throws URISyntaxException {
    URIBuilder ub = new URIBuilder();
    ub.setPath(url);

    ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
    ub.setParameters(pairs);

    HttpGet httpGet = new HttpGet(ub.build());
    return getResult(httpGet);
}
 
Example 13
Source File: Utilities.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getDcaDeployUrl(@NotNull final String protocol,
                                     @NotNull final String dcaHost,
                                     @NotNull final String dcaPort) {
    final URIBuilder uriBuilder = getUriBuilder(protocol, dcaHost, dcaPort);
    uriBuilder.setPath(DCA_DEPLOYMENT_PATH);

    try {
        return uriBuilder.build().toURL().toString();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: RemoteHttpService.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected <T> T executeGetMethod(String uriSuffix, Consumer<URIBuilder> uriCustomizer, Consumer<HttpGet> requestCustomizer, IOFunction<T> resultConverter,
                Supplier<String> errorSupplier) throws URISyntaxException, IOException {
    URIBuilder builder = buildURI();
    builder.setPath(serviceURI() + uriSuffix);
    uriCustomizer.accept(builder);
    HttpGet getRequest = new HttpGet(builder.build());
    requestCustomizer.accept(getRequest);
    return execute(getRequest, resultConverter, errorSupplier);
}
 
Example 15
Source File: IRIBuilderServiceImpl.java    From elucidate-server with MIT License 5 votes vote down vote up
private String buildIri(String id, Map<String, Object> params) {
    try {
        URIBuilder builder = new URIBuilder(baseUrl);
        builder.setPath(String.format("%s/%s", builder.getPath(), id));
        if (params != null && !params.isEmpty()) {
            for (Entry<String, Object> param : params.entrySet()) {
                builder.addParameter(param.getKey(), String.valueOf(param.getValue()));
            }
        }
        return builder.toString();
    } catch (URISyntaxException e) {
        throw new InvalidIRIException(String.format("An error occurred building IRI with base URL [%s] with ID [%s] and parameters [%s]", baseUrl, id, params), e);
    }
}
 
Example 16
Source File: VMImpl.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String getVMDetailsURL(NutanixGetVMDetailsInputs nutanixGetVMDetailsInputs) throws Exception {

    final URIBuilder uriBuilder = getUriBuilder(nutanixGetVMDetailsInputs.getCommonInputs());
    StringBuilder pathString = new StringBuilder()
            .append(API)
            .append(nutanixGetVMDetailsInputs.getCommonInputs().getAPIVersion())
            .append(GET_VM_DETAILS_PATH)
            .append(PATH_SEPARATOR)
            .append(nutanixGetVMDetailsInputs.getVMUUID());
    uriBuilder.setPath(pathString.toString());
    return uriBuilder.build().toURL().toString();
}
 
Example 17
Source File: SessionUtilExternalBrowser.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
/**
 * Gets SSO URL and proof key
 *
 * @return SSO URL.
 * @throws SFException           if Snowflake error occurs
 * @throws SnowflakeSQLException if Snowflake SQL error occurs
 */
private String getSSOUrl(int port) throws SFException, SnowflakeSQLException
{
  try
  {
    String serverUrl = loginInput.getServerUrl();
    String authenticator = loginInput.getAuthenticator();

    URIBuilder fedUriBuilder = new URIBuilder(serverUrl);
    fedUriBuilder.setPath(SessionUtil.SF_PATH_AUTHENTICATOR_REQUEST);
    URI fedUrlUri = fedUriBuilder.build();

    HttpPost postRequest = this.handlers.build(fedUrlUri);

    ClientAuthnDTO authnData = new ClientAuthnDTO();
    Map<String, Object> data = new HashMap<>();

    data.put(ClientAuthnParameter.AUTHENTICATOR.name(), authenticator);
    data.put(ClientAuthnParameter.ACCOUNT_NAME.name(),
             loginInput.getAccountName());
    data.put(ClientAuthnParameter.LOGIN_NAME.name(),
             loginInput.getUserName());
    data.put(ClientAuthnParameter.BROWSER_MODE_REDIRECT_PORT.name(),
             Integer.toString(port));
    data.put(ClientAuthnParameter.CLIENT_APP_ID.name(), loginInput.getAppId());
    data.put(ClientAuthnParameter.CLIENT_APP_VERSION.name(),
             loginInput.getAppVersion());

    authnData.setData(data);
    String json = mapper.writeValueAsString(authnData);

    // attach the login info json body to the post request
    StringEntity input = new StringEntity(json, StandardCharsets.UTF_8);
    input.setContentType("application/json");
    postRequest.setEntity(input);

    postRequest.addHeader("accept", "application/json");

    String theString = HttpUtil.executeGeneralRequest(
        postRequest,
        loginInput.getLoginTimeout(),
        loginInput.getOCSPMode());

    logger.debug("authenticator-request response: {}", theString);

    // general method, same as with data binding
    JsonNode jsonNode = mapper.readTree(theString);

    // check the success field first
    if (!jsonNode.path("success").asBoolean())
    {
      logger.debug("response = {}", theString);
      String errorCode = jsonNode.path("code").asText();
      throw new SnowflakeSQLException(
          SqlState.SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION,
          Integer.valueOf(errorCode),
          jsonNode.path("message").asText());
    }

    JsonNode dataNode = jsonNode.path("data");

    // session token is in the data field of the returned json response
    this.proofKey = dataNode.path("proofKey").asText();
    return dataNode.path("ssoUrl").asText();
  }
  catch (IOException | URISyntaxException ex)
  {
    throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage());
  }
}
 
Example 18
Source File: InstanceImpl.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
@NotNull
private static String getInstanceDefaultCredentialsUrl(@NotNull final String region, @NotNull final String instanceId) throws Exception {
    final URIBuilder uriBuilder = HttpUtils.getUriBuilder(region);
    uriBuilder.setPath(getInstanceDefaultCredentialsPath(instanceId));
    return uriBuilder.build().toURL().toString();
}
 
Example 19
Source File: StateVersionImpl.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
@NotNull
private static String getCurrentStateVersionUrl(@NotNull final String workspaceId) throws Exception {
    final URIBuilder uriBuilder = getUriBuilder();
    uriBuilder.setPath(getCurrentStateVersionPath(workspaceId));
    return uriBuilder.build().toURL().toString();
}
 
Example 20
Source File: OrganizationImpl.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
@NotNull
private static String getOrganizationDetailsUrl(@NotNull final String organizationName) throws Exception {
    final URIBuilder uriBuilder = getUriBuilder();
    uriBuilder.setPath(getOrganizationDetailsPath(organizationName));
    return uriBuilder.build().toURL().toString();
}