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:com.github.adam6806.mediarequest.sonarrservice.SonarrService.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    try {//from www  .  j ava2s  . c  om
        HttpClient httpClient = new HttpClient();
        String term = request.getParameter("searchTerm");
        URI uri = new URIBuilder().setScheme(sonarrURL.getProtocol()).setHost(sonarrURL.getHost())
                .setPort(sonarrURL.getPort()).setPath("/api/Series/lookup").setParameter("term", term)
                .setParameter("apikey", apiKey).build();
        GetMethod getMethod = new GetMethod(uri.toString());
        getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));
        httpClient.executeMethod(getMethod);
        String responseBody = getMethod.getResponseBodyAsString();
        response.getWriter().write(responseBody);
    } catch (URISyntaxException ex) {
        Logger.getLogger(SonarrService.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(SonarrService.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.github.adam6806.mediarequest.couchpotatoservice.CouchPotatoService.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    try {//  w ww.  j a  v  a  2  s. c o m
        HttpClient httpClient = new HttpClient();
        String term = request.getParameter("searchTerm");
        URI uri = new URIBuilder().setScheme(couchPotatoURL.getProtocol()).setHost(couchPotatoURL.getHost())
                .setPort(couchPotatoURL.getPort()).setPath("/api/" + apiKey + "/movie.search")
                .setParameter("q", term).build();
        GetMethod getMethod = new GetMethod(uri.toString());
        getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));
        httpClient.executeMethod(getMethod);
        String responseBody = getMethod.getResponseBodyAsString();
        response.getWriter().write(responseBody);
    } catch (URISyntaxException ex) {
        Logger.getLogger(CouchPotatoService.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CouchPotatoService.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Vdisk.java

public URI authorize(String response_type, String state) throws URISyntaxException {
    if (response_type == null)
        response_type = "token";
    if (state == null)
        state = "";
    URI uri = new URIBuilder().setScheme("https").setHost("auth.sina.com.cn/oauth2/authorize")
            .setParameter("client_id", this.app_key).setParameter("redirect_uri", this.call_back_url)
            .setParameter("response_type", response_type).setParameter("state", state).build();
    return uri;//from  w ww  .  j ava  2 s.  co  m
}

From source file:com.intuit.wasabi.export.rest.impl.DefaultRestEndPoint.java

@Override
public URI getRestEndPointURI() {
    URI assignmentURI = null;/* w ww .  j a v  a2 s  . co  m*/
    try {
        URIBuilder uriBuilder = new URIBuilder().setScheme(configuration.getScheme())
                .setHost(configuration.getHost()).setPath(configuration.getPath());
        int port = configuration.getPort();
        if (port != 0) {
            uriBuilder.setPort(port);
        }
        assignmentURI = uriBuilder.build();
    } catch (URISyntaxException e) {
        LOGGER.error("URL Syntax Error: ", e);
    }
    return assignmentURI;
}

From source file:sms.SendRequest.java

/**
 * /*www . java  2s .  c o m*/
 * @param moId
 * @param sender
 * @param serviceId
 * @param receiver
 * @param contentType
 * @param messageType
 * @param username
 * @param messageIndex
 * @param message
 * @param operator
 * @param commandCode
 * @return
 * @throws URISyntaxException
 * @throws IOException 
 */
public String sendRequests(String moId, String sender, String serviceId, String message, String operator,
        String commandCode, String username) throws URISyntaxException, IOException {
    Date d = new Date();
    SimpleDateFormat fm = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    URI uri = new URIBuilder().setScheme("http").setHost("222.255.167.6:8080").setPath("/SMS/Ctnet/sms")
            .setParameter("mo_id", moId).setParameter("username", username)
            .setParameter("key", Common.getMD5(username + "|" + moId + "|ctnet2015"))
            .setParameter("sender", sender).setParameter("serviceId", serviceId)
            .setParameter("message", message).setParameter("operator", operator)
            .setParameter("commandCode", commandCode).build();
    HttpGet httpPost = new HttpGet(uri);
    httpPost.addHeader("content-type", "application/x-www-form-urlencoded");
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse response = httpclient.execute(httpPost);

    try {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            long len = entity.getContentLength();
            if (len != -1 && len < 2048) {
                return EntityUtils.toString(entity);
            } else {
                // Stream content out
            }
        }
    } finally {
        response.close();
    }
    return "";
}

From source file:FlowPusher.ApacheHttpClient.java

public void postFloodlightClient(String jsonBody) throws UnsupportedEncodingException, IOException {

    try {// w  w  w.j a v  a2 s  .  c o m

        CloseableHttpClient httpClient = HttpClients.createDefault();

        URI uri = new URIBuilder().setScheme("http").setHost(controllerIP + ":8080")
                .setPath("/wm/staticflowentrypusher/json").build();

        HttpPost httpPost = new HttpPost(uri);

        StringEntity params = new StringEntity(jsonBody);
        httpPost.addHeader("content-type", "application/json");
        httpPost.setEntity(params);
        HttpResponse response = httpClient.execute(httpPost);

        String x = "kostas";
    } catch (URISyntaxException ex) {
        Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.example.analytics.AnalyticsServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String trackingId = System.getenv("GA_TRACKING_ID");
    HttpClient client = HttpClientBuilder.create().build();
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect").addParameter("v", "1") // API Version.
            .addParameter("tid", trackingId) // Tracking ID / Property ID.
            // Anonymous Client Identifier. Ideally, this should be a UUID that
            // is associated with particular user, device, or browser instance.
            .addParameter("cid", "555").addParameter("t", "event") // Event hit type.
            .addParameter("ec", "example") // Event category.
            .addParameter("ea", "test action"); // Event action.
    URI uri = null;//  w  w  w .  ja  va  2  s  .  c o m
    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new ServletException("Problem building URI", e);
    }
    HttpPost request = new HttpPost(uri);
    client.execute(request);
    resp.getWriter().println("Event tracked.");
}

From source file:eu.seaclouds.platform.dashboard.http.HttpDeleteRequestBuilder.java

public String build() throws IOException, URISyntaxException {

    URI uri = new URIBuilder().setHost(host).setPath(path).setScheme(scheme).setParameters(params).build();

    this.requestBase = new HttpDelete(uri);

    for (NameValuePair header : super.headers) {
        requestBase.addHeader(header.getName(), header.getValue());
    }//from  w  ww .j a va 2s  .c  om

    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        return httpClient.execute(requestBase, responseHandler, context);
    }
}

From source file:ar.edu.ubp.das.src.chat.actions.EliminarMensajeAction.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_mensaje = form.getItem("id_mensaje");
        String authToken = String.valueOf(request.getSession().getAttribute("token"));

        URIBuilder builder = new URIBuilder();
        builder.setScheme("http").setHost("25.136.78.82").setPort(8080).setPath("/mensajes/" + id_mensaje);

        HttpDelete delete = new HttpDelete();
        delete.setURI(builder.build());/*ww  w .j  a  va  2s .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_mensaje = form.getItem("id_mensaje");
        request.setAttribute("message",
                "Error al intentar eliminar mensaje " + id_mensaje + "; " + e.getMessage());
        response.setStatus(400);
        return mapping.getForwardByName("failure");
    }
}

From source file:ng.logentries.logs.LogReader.java

public <T extends LogEntryData> List<T> readLogs(Class<? extends LogEntryData> cls, Account account,
        FilterOptions options) throws Exception {
    List<T> list = new ArrayList<>();
    LogEntryData instance = cls.newInstance();
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    try {// w  ww  . j  a v  a  2 s  .co m
        URIBuilder uriBuilder = new URIBuilder().setScheme("https").setHost("pull.logentries.com/")
                .setPath(account.getAccessKey() + "/hosts/" + account.getLogSetName() + "/"
                        + account.getLogName() + "/");
        if (options.getLimit() != -1) {
            uriBuilder.addParameter("limit", "" + options.getLimit());
        }
        uriBuilder.addParameter("filter", instance.getPattern());
        if (options.getsTime() != -1) {
            uriBuilder.addParameter("start", "" + options.getsTime());
        }
        if (options.geteTime() != -1) {
            uriBuilder.addParameter("end", "" + options.geteTime());
            System.out.println(options.geteTime());
        }
        HttpGet get = new HttpGet(uriBuilder.build());
        HttpResponse httpResponse = httpClient.execute(get);
        HttpEntity entity = httpResponse.getEntity();
        Scanner in = new Scanner(entity.getContent());
        while (in.hasNext()) {
            T parse = (T) LogDataMapper.parse(in.nextLine(), cls);
            list.add(parse);
            //System.out.println(parse);
        }
    } catch (Exception e) {
        System.out.println("Error while trying to read logs: " + e);
    } finally {
        if (httpClient != null) {
            httpClient.close();
        }
    }

    return list;
}