List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:org.n52.sos.service.it.SosITBase.java
/** * Get URI for the relative sos path and query using test host, port, and * basepath/* w ww .ja va2s.c o m*/ * * @param path * The relative test endpoint * @param query * Query parameters to add to the request * @return Constructed URI * @throws URISyntaxException */ protected URI getURI(String path, String query) throws URISyntaxException { URIBuilder b = new URIBuilder(); b.setScheme("http"); b.setHost(host); b.setPort(port); b.setPath(getPath(path)); b.setQuery(query); b.setFragment(null); return b.build(); }
From source file:com.munichtrading.tracking.camera.APIIPCamera.java
private boolean getSettings() { try {/* w ww . j av a 2 s . co m*/ URIBuilder builder = new URIBuilder().setScheme("http").setHost(this.device.getHostName()) .setPath("/parameters"); HttpClient client = HttpClients.createDefault(); HttpGet request = new HttpGet(builder.build()); request.addHeader("User-Agent", USER_AGENT); HttpResponse response = client.execute(request); logger.info("Sending request: " + builder.toString()); logger.info("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } this.updateSettings(result.toString()); } catch (Exception e) { return false; } return true; }
From source file:com.anrisoftware.simplerest.oanda.rest.OandaRestPrices.java
private URI getRequestURI0() throws URISyntaxException { URIBuilder builder = new URIBuilder(propertiesProvider.getOandaPricesURI()); builder.setParameter(ACCOUNT_ID_PARAM, account.getAccount()); String names = join(instruments.keySet(), COMMA); builder.setParameter(INSTRUMENTS_PARAM, names); return builder.build(); }
From source file:ar.edu.ubp.das.src.chat.actions.ActualizarUsuariosAction.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 ultima_actualizacion = String.valueOf(request.getSession().getAttribute("ultima_actualizacion")); String authToken = String.valueOf(request.getSession().getAttribute("token")); if (ultima_actualizacion.equals("null") || ultima_actualizacion.isEmpty()) { ultima_actualizacion = String.valueOf(System.currentTimeMillis()); }/*from w w w . j av a 2s.co m*/ URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("25.136.78.82").setPort(8080) .setPath("/actualizaciones/sala/" + sala.getId()); builder.setParameter("ultima_act", ultima_actualizacion); HttpGet getRequest = new HttpGet(); getRequest.setURI(builder.build()); getRequest.addHeader("Authorization", "BEARER " + authToken); getRequest.addHeader("accept", "application/json; charset=ISO-8859-1"); 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); } if (restResp.equals("null") || restResp.isEmpty()) { return mapping.getForwardByName("success"); } //parse actualizacion data from response Gson gson = new Gson(); Type listType = new TypeToken<LinkedList<ActualizacionBean>>() { }.getType(); List<ActualizacionBean> actualizaciones = gson.fromJson(restResp, listType); List<UsuarioBean> usuarios = actualizaciones.stream() .filter(a -> a.getNombre_tipo().equals("UsuarioSala")).map(m -> m.getUsuario()) .collect(Collectors.toList()); request.getSession().setAttribute("ultima_actualizacion", String.valueOf(System.currentTimeMillis())); if (!usuarios.isEmpty()) { request.setAttribute("usuarios", usuarios); } return mapping.getForwardByName("success"); } catch (IOException | URISyntaxException | RuntimeException e) { SalaBean sala = (SalaBean) request.getSession().getAttribute("sala"); request.setAttribute("message", "Error al intentar actualizar usuarios de Sala " + sala.getId() + ": " + e.getMessage()); response.setStatus(400); return mapping.getForwardByName("failure"); } }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsUploadFile.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); String statusPath = String.format("%s%s%s", extraPath, propertiesProvider.getOwncloudWebdavPath(), remotePath);// w w w . j a va 2 s .c o m builder.setPath(statusPath); return builder.build(); }
From source file:com.gogh.plugin.translator.YoudaoTranslator.java
@NotNull @Override// ww w .j ava 2s .c o m public URI createUrl(String query) throws URISyntaxException { String[] apiKey = ApiConfig.getAPISet(); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("fanyi.youdao.com").setPath("/openapi.do") .addParameter("keyfrom", apiKey[0]).addParameter("key", apiKey[1]).addParameter("type", "data") .addParameter("version", "1.1").addParameter("doctype", "json").addParameter("q", query); return builder.build(); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationCopy.java
private HttpRequestBase onExecute(final String preparationId, final String destination, final String newName) { try {//from w w w . jav a2 s .c o m URIBuilder uriBuilder = new URIBuilder( preparationServiceUrl + "/preparations/" + preparationId + "/copy"); if (StringUtils.isNotBlank(destination)) { uriBuilder.addParameter("destination", destination); } if (StringUtils.isNotBlank(newName)) { uriBuilder.addParameter("name", newName); } return new HttpPost(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:io.seldon.external.ExternalPredictionServer.java
public JsonNode predict(String client, JsonNode jsonNode, OptionsHolder options) { long timeNow = System.currentTimeMillis(); URI uri = URI.create(options.getStringOption(URL_PROPERTY_NAME)); try {/* www . jav a 2s . c om*/ URIBuilder builder = new URIBuilder().setScheme("http").setHost(uri.getHost()).setPort(uri.getPort()) .setPath(uri.getPath()).setParameter("client", client) .setParameter("json", jsonNode.toString()); uri = builder.build(); } catch (URISyntaxException e) { throw new APIException(APIException.GENERIC_ERROR); } HttpContext context = HttpClientContext.create(); HttpGet httpGet = new HttpGet(uri); try { if (logger.isDebugEnabled()) logger.debug("Requesting " + httpGet.getURI().toString()); CloseableHttpResponse resp = httpClient.execute(httpGet, context); try { if (resp.getStatusLine().getStatusCode() == 200) { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(resp.getEntity().getContent()); JsonNode actualObj = mapper.readTree(parser); return actualObj; } else { logger.error( "Couldn't retrieve prediction from external prediction server -- bad http return code: " + resp.getStatusLine().getStatusCode()); throw new APIException(APIException.GENERIC_ERROR); } } finally { if (resp != null) resp.close(); if (logger.isDebugEnabled()) logger.debug( "External prediction server took " + (System.currentTimeMillis() - timeNow) + "ms"); } } catch (IOException e) { logger.error("Couldn't retrieve prediction from external prediction server - ", e); throw new APIException(APIException.GENERIC_ERROR); } catch (Exception e) { logger.error("Couldn't retrieve prediction from external prediction server - ", e); throw new APIException(APIException.GENERIC_ERROR); } finally { } }
From source file:uk.org.openeyes.oink.itest.adapters.ITFacadeToHl7v2.java
@Test public void testPatientQueryIsPossibleUsingMockedHl7Server() throws Exception { Thread.sleep(45000);//from w ww . j a v a2 s . c o m // Mock an HL7 Server Hl7Server hl7Server = new Hl7Server(Integer.parseInt(hl7Props.getProperty("remote.port")), false); final Message searchResults = Hl7Helper.loadHl7Message("/example-messages/hl7v2/ADR-A19-mod.txt"); hl7Server.setMessageHandler("QRY", "A19", new ReceivingApplication() { @Override public Message processMessage(Message in, Map<String, Object> metadata) throws ReceivingApplicationException, HL7Exception { // Always return search results log.debug("Returning search results"); return searchResults; } @Override public boolean canProcess(Message message) { return true; } }); hl7Server.start(); // Make a Patient Query URIBuilder builder = new URIBuilder(facadeProps.getProperty("facade.uri") + "/Patient"); builder.addParameter("identifier", "NHS|123456"); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(builder.build()); httpGet.addHeader("Accept", "application/json+fhir; charset=UTF-8"); CloseableHttpResponse response1 = httpclient.execute(httpGet); // Check results assertEquals(200, response1.getStatusLine().getStatusCode()); String json = null; try { HttpEntity entity1 = response1.getEntity(); json = EntityUtils.toString(entity1); } finally { response1.close(); hl7Server.stop(); } assertNotNull(json); BundleParser conv = new BundleParser(); AtomFeed response = conv.fromJsonOrXml(json); assertNotEquals(0, response.getEntryList().size()); }
From source file:com.gsma.mobileconnect.impl.OIDCImpl.java
/** * Build a HttpPost for the requestToken call. * * @param uri The URI of the token service. * @param redirectURL Redirect URL required by the token service. * @param code The code obtained from the authorization service. * @return A HttpPost./* w ww . j a v a 2s. c o m*/ * @throws URISyntaxException * @throws UnsupportedEncodingException */ private HttpPost buildHttpPostForAccessToken(URI uri, String redirectURL, String code) throws URISyntaxException, UnsupportedEncodingException { URIBuilder uriBuilder = new URIBuilder(uri); HttpPost httpPost = new HttpPost(uriBuilder.build()); httpPost.setHeader(Constants.CONTENT_TYPE_HEADER_NAME, Constants.CONTENT_TYPE_HEADER_VALUE); httpPost.setHeader(Constants.ACCEPT_HEADER_NAME, Constants.ACCEPT_JSON_HEADER_VALUE); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); nameValuePairs.add(new BasicNameValuePair(Constants.REDIRECT_URI_PARAMETER_NAME, redirectURL)); nameValuePairs.add( new BasicNameValuePair(Constants.GRANT_TYPE_PARAMETER_NAME, Constants.GRANT_TYPE_PARAMETER_VALUE)); nameValuePairs.add(new BasicNameValuePair(Constants.CODE_PARAMETER_NAME, code)); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); return httpPost; }