List of usage examples for org.apache.http.client.utils URIBuilder setScheme
public URIBuilder setScheme(final String scheme)
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());//w w w .j a v a 2 s . c om 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:org.metaservice.demo.securityalert.NotificationBackend.java
public void send(String api, String s, String cve) { LOGGER.info("Sending {} {}", s, cve); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost("www.notifymyandroid.com").setPort(80).setPath("/publicapi/notify"); try {/* w w w .jav a 2s. c o m*/ String result = Request.Post(uriBuilder.build()) .bodyForm(Form.form().add("apikey", api).add("event", s).add("application", "metaservice.org") .add("priority", "2").add("description", s).add("url", cve).build()) .connectTimeout(1000).socketTimeout(30000) // .setHeader("Accept", mimeType) .execute().returnContent().asString(); LOGGER.info(result); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } }
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 www. jav a 2 s. c om*/ 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:org.apache.streams.riak.http.RiakHttpClient.java
public void start() throws Exception { Objects.nonNull(config);//from w ww .ja v a 2 s. c o m assert (config.getScheme().startsWith("http")); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(config.getScheme()); uriBuilder.setHost(config.getHosts().get(0)); uriBuilder.setPort(config.getPort().intValue()); baseURI = uriBuilder.build(); client = HttpClients.createDefault(); }
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 a v a2s. 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:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java
private URI base(final URI uri) { try {/*from w w w. j ava 2 s . c om*/ URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(uri.getScheme()); uriBuilder.setHost(uri.getHost()); uriBuilder.setPort(uri.getPort()); uriBuilder.setPath(uri.getPath()); if (uri.getUserInfo() != null) { uriBuilder.setUserInfo(uri.getUserInfo()); } return uriBuilder.build(); } catch (final URISyntaxException ignored) { // This should never happen since we are using a valid URI to construct ours. return null; } }
From source file:nl.esciencecenter.ptk.web.URIQueryParameters.java
/** * Create URI encoded query String from this parameter list. * /*from w w w . j a va 2 s . com*/ * @return URI query string. * @throws UnsupportedEncodingException */ public String toQueryString() throws UnsupportedEncodingException { // Use Apache URI builder ! URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setHost("host"); uriBuilder.setScheme("scheme"); uriBuilder.setPath("/"); for (String key : this.keySet()) { uriBuilder.setParameter(key, this.get(key)); } // todo: better URI query encoding. return uriBuilder.toString().substring("scheme://host/?".length()); }
From source file:org.metaservice.frontend.rest.SparqlResourceService.java
public SparqlResourceService() throws URISyntaxException, IOException { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost("graph.metaservice.org").setPort(8080).setPath("/bigdata/sparql"); uri = uriBuilder.build();//from www. j a va 2s. co m namespaces = generateNamespaceString(); resourceQuery = loadSparql("/sparql/resourceWithLatest.sparql"); }
From source file:Control.SenderMsgToCentralServer.java
public void streamIsTerminatedOK(String idGephi, String jobStart, String app) throws URISyntaxException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(); builder.setScheme("http") .setHost(Admin.ipServerDispatch() + "webresources/CommunicationServers/TerminatedOK") .setParameter("jobStart", jobStart).setParameter("idGephi", idGephi).setParameter("app", app); URI uri = builder.build();/* w ww .ja v a2 s . c om*/ System.out.println("uri: " + uri); HttpGet httpget = new HttpGet(uri); HttpResponse response; HttpEntity entity; int codeStatus = 0; int attempts = 0; boolean success = false; while (!success && attempts < 4) { attempts++; response = httpclient.execute(httpget); entity = response.getEntity(); EntityUtils.consumeQuietly(entity); codeStatus = response.getStatusLine().getStatusCode(); success = (codeStatus == 200); } if (!success) { System.out.println( "server dispatcher could not be reached to tell about job termination - 3 failed attempts."); } else { System.out.println("message correctly sent to server dispatcherabout cloudbees job termination"); } }
From source file:org.trendafilov.odesk.notifier.connectivity.RequestHandler.java
private String buildUrl(SearchCriteria criteria) throws ConfigurationException { URIBuilder builder = new URIBuilder(); Configurable config = Configuration.getInstance(); builder.setScheme(config.getStringValue("api.scheme", "https")) .setHost(config.getStringValue("api.host", "www.odesk.com")) .setPath(config.getStringValue("api.query.path")) .setParameter("page", "0;" + config.getIntValue("api.item.count", 20)) .setParameter("q", criteria.getQuery()).setParameter("fb", criteria.getClientScore()) .setParameter("min", criteria.getMinBudget()).setParameter("t", criteria.getJobType()) .setParameter("wl", criteria.getWorkHours()).setParameter("dur", criteria.getDuration()); return builder.toString(); }