Example usage for org.apache.http.client.utils URIBuilder URIBuilder

List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder URIBuilder.

Prototype

public URIBuilder(final URI uri) 

Source Link

Document

Construct an instance from the provided URI.

Usage

From source file:org.talend.dataprep.api.service.command.folder.SearchFolders.java

private HttpRequestBase onExecute(final String name, final boolean strict) {
    try {// w w  w. ja  v a2s  . co  m

        URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders/search");
        uriBuilder.addParameter("name", name);
        uriBuilder.addParameter("strict", String.valueOf(strict));
        return new HttpGet(uriBuilder.build());

    } catch (URISyntaxException e) {
        throw new TDPException(UNEXPECTED_EXCEPTION, e);
    }
}

From source file:org.flowable.admin.service.engine.DecisionTableDeploymentService.java

public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) {

    URIBuilder builder = null;/*  ww w. j  av  a2  s. c  o m*/
    try {
        builder = new URIBuilder("dmn-repository/deployments");
    } catch (Exception e) {
        log.error("Error building uri", e);
        throw new FlowableServiceException("Error building uri", e);
    }

    for (String name : parameterMap.keySet()) {
        builder.addParameter(name, parameterMap.get(name)[0]);
    }
    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString()));
    return clientUtil.executeRequest(get, serverConfig);
}

From source file:com.thoughtworks.go.http.mocks.HttpRequestBuilder.java

public HttpRequestBuilder withPath(String path) {
    try {/*from   ww w.  j a  v a  2 s  .c o  m*/
        URIBuilder uri = new URIBuilder(path);
        request.setServerName("test.host");
        request.setContextPath(CONTEXT_PATH);
        request.setParameters(splitQuery(uri));
        request.setRequestURI(CONTEXT_PATH + uri.getPath());
        request.setServletPath(uri.getPath());
        if (!uri.getQueryParams().isEmpty()) {
            request.setQueryString(URLEncodedUtils.format(uri.getQueryParams(), UTF_8));
        }
        return this;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ch.newscron.shortUrlUtils.ShortenerURL.java

/**
 * Given a shortened goo.gl URL, the function makes a request to the Google API (with key), receives information as a response in JSONObject format and stores data into a ShortLinkStat object.
 * @param shortURL is a String representing the shortened goo.gl URL
 * @return a ShortLinkStat object consisting of the most important information (clicks, long and short URL)
 *//*from ww w. j  av a 2  s. c  o  m*/
public static ShortLinkStat getURLJSONObject(String shortURL) {
    ShortLinkStat linkStat;

    try {
        // Creating the URL with Google API
        URIBuilder urlData = new URIBuilder(google_url);
        urlData.addParameter("shortUrl", shortURL);
        urlData.addParameter("projection", "FULL");
        URL url = urlData.build().toURL();

        // Get the JSONObject format of shortURL as String
        ObjectMapper mapper = new ObjectMapper();
        JsonNode rootNode = mapper.readTree(url);
        if (rootNode == null) {
            return null;
        }

        linkStat = setData(rootNode);
        return linkStat;

    } catch (Exception e) {
    }

    return null;
}

From source file:org.talend.dataprep.api.service.command.folder.FolderDataSetList.java

private HttpRequestBase onExecute(String sort, String order, String folder) {
    try {//w  w w.  j a  v  a2s  . co  m
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/folders/datasets");
        uriBuilder.addParameter("sort", sort);
        uriBuilder.addParameter("order", order);
        if (StringUtils.isNotEmpty(folder)) {
            uriBuilder.addParameter("folder", folder);
        }
        return new HttpGet(uriBuilder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:com.redhat.refarch.microservices.warehouse.service.WarehouseService.java

public void fulfillOrder(Result result) throws Exception {

    HttpClient client = new DefaultHttpClient();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status", "Shipped");

    URIBuilder uriBuilder = new URIBuilder("http://gateway-service:9091/customers/" + result.getCustomerId()
            + "/orders/" + result.getOrderNumber());
    HttpPatch patch = new HttpPatch(uriBuilder.build());
    patch.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
    logInfo("Executing " + patch);
    HttpResponse response = client.execute(patch);
    String responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got response " + responseString);
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationSearchByDataSetId.java

/**
 * Private constructor used to construct the generic command used to list of preparations based on a dataset id.
 *
 * @param datasetId the dataset id.// w ww .jav  a 2s .c  o m
 */
private PreparationSearchByDataSetId(String datasetId) {
    super(GenericCommand.PREPARATION_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/search");
            uriBuilder.addParameter("dataSetId", datasetId);
            return new HttpGet(uriBuilder.build());
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    on(HttpStatus.OK).then(pipeStream());
}

From source file:client.Traveller.java

public void searchFlights(FlightSearch flightSearch) {
    // Keeps current search in order to store session variables
    currentFlightSearch = flightSearch;/*from w  w w  . ja v  a  2  s . c  o m*/

    try {
        // Builds URL for HTTP request that queries for departing flights
        URIBuilder uriBuilder = new URIBuilder(hostURL + "/search/flight");
        uriBuilder.addParameter("origin", flightSearch.getOrigin());
        uriBuilder.addParameter("destination", flightSearch.getDestination());
        uriBuilder.addParameter("departureDate", flightSearch.getDepartureDate());
        uriBuilder.addParameter("numberOfPassengers", String.valueOf(flightSearch.getNumberOfPassengers()));

        // Converts URL to string
        String urlString = uriBuilder.build().toString();

        // Send GET request and waits for response
        String response = httpConnector.sendGet(urlString);

        // Handles response (REST API returns a JSON array)
        ArrayList<Flight> departingFlights = new ArrayList<>();
        JSONArray flights = new JSONArray(response);
        int n = flights.length();
        Flight f;
        for (int i = 0; i < n; ++i) {
            final JSONObject flight = flights.getJSONObject(i);
            String flightNumber = (flight.getString("flightNumber"));
            String airline = (flight.getString("airline"));
            String origin = (flight.getString("origin"));
            String destination = (flight.getString("destination"));
            String departureDate = (flight.getString("departureDate"));
            String arrivalDate = (flight.getString("arrivalDate"));
            departureDate = (flight.getString("departureDate"));
            String departureTime = (flight.getString("departureTime"));
            String arrivalTime = (flight.getString("arrivalTime"));
            String airfare = (flight.getString("airfare"));
            int availableSeats = (flight.getInt("availableSeats"));
            f = new Flight(flightNumber, airline, origin, destination, departureDate, departureTime,
                    arrivalTime, Double.parseDouble(airfare), availableSeats);
            departingFlights.add(f);
        }

        // Creates array for returning flights
        ArrayList<Flight> returningFlights = new ArrayList<>();

        // Prepares second GET request if user searched for a round trip flights
        if (flightSearch.getRoundTrip()) {

            // Builds URL for HTTP request that queries for returning flights
            uriBuilder = new URIBuilder(hostURL + "/search/flight");
            uriBuilder.addParameter("destination", flightSearch.getOrigin());
            uriBuilder.addParameter("origin", flightSearch.getDestination());
            uriBuilder.addParameter("departureDate", flightSearch.getReturnDate());
            uriBuilder.addParameter("numberOfPassengers", String.valueOf(flightSearch.getNumberOfPassengers()));

            // Converts URL to string
            urlString = uriBuilder.build().toString();

            // Sends second GET request and waits for response
            response = httpConnector.sendGet(urlString);

            // Handles response from second GET request
            flights = new JSONArray(response);
            n = flights.length();
            for (int i = 0; i < n; ++i) {
                final JSONObject flight = flights.getJSONObject(i);
                String flightNumber = (flight.getString("flightNumber"));
                String airline = (flight.getString("airline"));
                String origin = (flight.getString("origin"));
                String destination = (flight.getString("destination"));
                String departureDate = (flight.getString("departureDate"));
                departureDate = (flight.getString("departureDate"));
                String departureTime = (flight.getString("departureTime"));
                String arrivalTime = (flight.getString("arrivalTime"));
                String airfare = (flight.getString("airfare"));
                int availableSeats = (flight.getInt("availableSeats"));
                f = new Flight(flightNumber, airline, origin, destination, departureDate, departureTime,
                        arrivalTime, Double.parseDouble(airfare), availableSeats);
                returningFlights.add(f);
            }

        }

        // Display search results in a new window
        flightSearchResultsFrame = new FlightSearchResultsFrame(this, departingFlights, returningFlights);
        flightSearchResultsFrame.setLocationRelativeTo(null);
        flightSearchResultsFrame.setVisible(true);

    } catch (URISyntaxException ex) {
        this.displayBookingConfirmation("ERROR | Invalid search");
    }
}

From source file:asterixReadOnlyClient.AsterixReadOnlyClientUtility.java

@Override
public void init() {
    httpclient = new DefaultHttpClient();
    httpGet = new HttpGet();
    try {/*from  ww w .j a v  a 2s . co m*/
        roBuilder = new URIBuilder("http://" + ccUrl + ":" + Constants.ASTX_AQL_REST_API_PORT + "/query");
    } catch (URISyntaxException e) {
        System.err.println("Problem in initializing Read-Only URI Builder");
        e.printStackTrace();
    }
}

From source file:com.activiti.service.activiti.JobService.java

public JsonNode listJobs(ServerConfig serverConfig, Map<String, String[]> parameterMap) {

    URIBuilder builder = null;//w ww.  j  ava2  s.  c o m
    try {
        builder = new URIBuilder("management/jobs");
    } catch (Exception e) {
        log.error("Error building uri", e);
        throw new ActivitiServiceException("Error building uri", e);
    }

    for (String name : parameterMap.keySet()) {
        builder.addParameter(name, parameterMap.get(name)[0]);
    }
    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString()));
    return clientUtil.executeRequest(get, serverConfig);
}