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() 

Source Link

Document

Constructs an empty instance.

Usage

From source file:ar.edu.ubp.das.src.chat.actions.ExpulsarUsuarioAction.java

@Override
public ForwardConfig execute(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, RuntimeException {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {

        //get request data
        String id_usuario = form.getItem("id_usuario");
        String id_sala = form.getItem("id_sala");
        String authToken = String.valueOf(request.getSession().getAttribute("token"));

        URIBuilder builder = new URIBuilder();
        builder.setScheme("http").setHost("25.136.78.82").setPort(8080)
                .setPath("/usuarios-salas/" + id_usuario + "/" + id_sala);

        HttpDelete delete = new HttpDelete();
        delete.setURI(builder.build());//from   ww w  . j ava  2 s.c  o m
        delete.addHeader("Authorization", "BEARER " + authToken);
        delete.addHeader("accept", "application/json");

        CloseableHttpResponse deleteResponse = httpClient.execute(delete);

        HttpEntity responseEntity = deleteResponse.getEntity();
        StatusLine responseStatus = deleteResponse.getStatusLine();
        String restResp = EntityUtils.toString(responseEntity);

        if (responseStatus.getStatusCode() != 200) {
            throw new RuntimeException(restResp);
        }

        return mapping.getForwardByName("success");

    } catch (IOException | URISyntaxException | RuntimeException e) {
        String id_usuario = form.getItem("id_usuario");
        request.setAttribute("message",
                "Error al intentar expulsar usuario: " + id_usuario + "; " + e.getMessage());
        response.setStatus(400);
        return mapping.getForwardByName("failure");
    }
}

From source file:tisseows.RequestTisseo.java

public void resetURIB() {
    this.urib = new URIBuilder().setScheme("http").setHost("pt.data.tisseo.fr");
}

From source file:org.apache.james.jmap.methods.integration.cucumber.MainStepdefs.java

public URIBuilder baseUri() {
    return new URIBuilder().setScheme("http").setHost("localhost").setPort(jmapServer.getJmapPort())
            .setCharset(Charsets.UTF_8);
}

From source file:tisseows.RequestJCDecaux.java

public void resetURIB() {
    this.urib = new URIBuilder().setScheme("https").setHost("api.jcdecaux.com");
}

From source file:org.dbrane.cloud.util.httpclient.HttpClientHelper.java

public static String httpGetRequest(String url, Map<String, Object> params) {
    try {/*  ww w . ja  v a  2s  .c om*/
        URIBuilder ub = new URIBuilder();
        ub.setPath(url);

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

        HttpGet httpGet = new HttpGet(ub.build());
        return getResult(httpGet);
    } catch (Exception e) {
        logger.debug(ErrorType.Httpclient.toString(), e);
        throw new BaseException(ErrorType.Httpclient, e);
    }
}

From source file:ar.edu.ubp.das.src.chat.actions.UsuariosListAction.java

@Override
public ForwardConfig execute(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, RuntimeException {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        //prepare http get
        SalaBean sala = (SalaBean) request.getSession().getAttribute("sala");
        String authToken = String.valueOf(request.getSession().getAttribute("token"));

        URIBuilder builder = new URIBuilder();
        builder.setScheme("http").setHost("25.136.78.82").setPort(8080)
                .setPath("/usuarios-salas/sala/" + sala.getId());

        HttpGet getRequest = new HttpGet();
        getRequest.setURI(builder.build());
        getRequest.addHeader("Authorization", "BEARER " + authToken);
        getRequest.addHeader("accept", "application/json");

        CloseableHttpResponse getResponse = httpClient.execute(getRequest);
        HttpEntity responseEntity = getResponse.getEntity();
        StatusLine responseStatus = getResponse.getStatusLine();
        String restResp = EntityUtils.toString(responseEntity);

        if (responseStatus.getStatusCode() != 200) {
            throw new RuntimeException(restResp);
        }/*from w w w  .j av  a 2 s .  c  o m*/
        //parse message data from response
        Gson gson = new Gson();
        UsuarioBean[] usrList = gson.fromJson(restResp, UsuarioBean[].class);
        request.setAttribute("usuarios", usrList);

        return mapping.getForwardByName("success");

    } catch (IOException | URISyntaxException | RuntimeException e) {
        request.setAttribute("message", "Error al intentar listar Usuarios " + e.getMessage());
        response.setStatus(400);
        return mapping.getForwardByName("failure");
    }

}

From source file:ee.ria.xroad.common.util.healthcheck.MaintenanceModeTest.java

/**
 * Setup for all tests//from   w  w  w  .j a  v  a  2 s .  c  o m
 * @throws Exception throws an Exception if unable to setup
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    URI healthCheckURI = new URIBuilder().setScheme("http").setHost("localhost").setPort(TEST_PORT_NUMBER)
            .build();

    healthCheckGet = new HttpGet(healthCheckURI);
    testClient = HttpClients.createDefault();

    testProvider = mock(StoppableCombinationHealthCheckProvider.class);
    testPort = new HealthCheckPort(testProvider, TEST_PORT_NUMBER);
    testPort.start();
}

From source file:webrequester.AbstractWebRequest.java

protected URI buildURI() {
    try {/*www. j a v a2  s .  c o m*/
        URIBuilder uriB = new URIBuilder();
        uriB.setScheme(scheme).setHost(host);
        if (port > 0) {
            uriB.setPort(port);
        }

        uriB.setPath(path);
        for (NameValuePair pair : listParameters) {
            uriB.setParameter(pair.getName(), pair.getValue());
        }
        return uriB.build();
    } catch (URISyntaxException ex) {
        return null;
    }
}

From source file:at.yawk.buycraft.BuycraftApiImpl.java

@Override
public InfoResponse info(String port, String onlineMode, String playerLimit, String version)
        throws IOException {
    Objects.requireNonNull(port);
    Objects.requireNonNull(onlineMode);
    Objects.requireNonNull(playerLimit);
    Objects.requireNonNull(version);
    JsonObject object = get("info",
            new URIBuilder().setParameter("serverPort", port).setParameter("onlineMode", onlineMode)
                    .setParameter("playersMax", playerLimit).setParameter("version", version));
    JsonObject payload = object.getAsJsonObject("payload");
    return new InfoResponse(payload.get("latestVersion").getAsDouble(),
            payload.get("latestDownload").getAsString(), payload.get("serverId").getAsInt(),
            payload.get("serverCurrency").getAsString(), payload.get("serverName").getAsString(),
            payload.get("serverStore").getAsString(), payload.get("updateUsernameInterval").getAsInt(),
            payload.get("onlineMode").getAsBoolean());
}

From source file:org.wso2.security.tools.dependencycheck.scanner.NotificationManager.java

private static void notifyStatus(String path, boolean status) throws NotificationManagerException {
    int i = 0;// ww w .jav  a  2  s  . co  m
    while (i < 10) {
        try {
            URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort)
                    .setScheme("http").setPath(path).addParameter("containerId", myContainerId)
                    .addParameter("status", String.valueOf(status)).build();
            HttpClient httpClient = HttpClientBuilder.create().build();
            HttpGet get = new HttpGet(uri);

            HttpResponse response = httpClient.execute(get);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                LOGGER.info("Notified successfully");
                return;
            } else {
                i++;
            }
            Thread.sleep(2000);
        } catch (URISyntaxException | InterruptedException | IOException e) {
            LOGGER.error("Error occurred while notifying the status to automation manager", e);
            i++;
        }
    }
    throw new NotificationManagerException("Error occurred while notifying status to Automation Manager");
}