List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder()
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 w w . j av a 2 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.wuspba.ctams.ws.ITBandContestEntryController.java
@Test public void testListAll() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); LOG.info("Connecting to " + uri.toString()); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getBandContestEntry().size(), 1); testEquality(doc.getBandContestEntry().get(0), TestFixture.INSTANCE.bandContestEntry); EntityUtils.consume(entity);//from w ww .j a v a2 s. c o m } }
From source file:org.wuspba.ctams.ws.ITSoloContestEntryController.java
@Test public void testListAll() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); LOG.info("Connecting to " + uri.toString()); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getSoloContestEntry().size(), 1); testEquality(doc.getSoloContestEntry().get(0), TestFixture.INSTANCE.soloContestEntry); EntityUtils.consume(entity);//from w w w . j a v a2s.c o m } }
From source file:com.ibm.subway.NewYorkSubway.java
public StationList getTrainList(String stationId, Locale locale, boolean translate) throws Exception { logger.debug("Station {}", stationId); StationList returnedList = new StationList(); WatsonTranslate watson = new WatsonTranslate(locale); try {/*from w w w . j a v a 2 s . c o m*/ if (stationId != null) { RequestConfig config = RequestConfig.custom().setSocketTimeout(10 * 1000) .setConnectTimeout(10 * 1000).build(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(config).build(); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost(url).setPath("/by-id/" + stationId); URI uri = builder.build(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Content-Type", "text/plain"); HttpResponse httpResponse = httpclient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == 200) { BufferedReader rd = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); // Read all the trains from the list ObjectMapper mapper = new ObjectMapper(); returnedList = mapper.readValue(rd, StationList.class); // Set the direction of the trains ArrayList<Station> stations = returnedList.getStationList(); for (Station station : stations) { String northString = "North"; String southString = "South"; if (translate) { northString = watson.translate(northString); southString = watson.translate(southString); } ArrayList<Train> north = station.getNorthTrains(); for (Train train : north) { train.setDirection(northString); } ArrayList<Train> south = station.getSouthTrains(); for (Train train : south) { train.setDirection(southString); } } } else { logger.error("could not get list from MTA http code {}", httpResponse.getStatusLine().getStatusCode()); } } } catch (Exception e) { logger.error("could not get list from MTA {}", e.getMessage()); throw e; } return returnedList; }
From source file:org.ireas.mediawiki.MediaWikiUtils.java
/** * Constructs an {@code URI} object from {@code scheme}, {@code host}, * {@code port} and {@code apiPath}. The constructed URI will have the * structure {@code "<scheme>://<host>:<port>/<apiPath>"}. * * @param scheme//from w w w.j a va2 s.c o m * the scheme of the URI, e. g. {@code "https"} * @param host * the host of the URI, e. g. {@code "example.org"} * @param port * the port of the URI, e. g. {@code 443}. The port must be * non-negative. * @param path * the path of the URI, e. g. {@code "/index.html"} * @return an {@code URI} constructed from the given parts * @throws MediaWikiException * if the given parts do not form a valid URI * @throws NullPointerException * if {@code scheme}, {@code host} or {@code path} is * {@code null} * @throws IllegalArgumentException * if {@code port} is negative */ public static URI buildUri(final String scheme, final String host, final int port, final String path) throws MediaWikiException { Preconditions.checkNotNull(scheme); Preconditions.checkNotNull(host); Preconditions.checkNotNull(path); Preconditions.checkArgument(port >= 0); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(scheme); uriBuilder.setHost(host); uriBuilder.setPort(port); uriBuilder.setPath(path); try { return uriBuilder.build(); } catch (URISyntaxException exception) { throw new MediaWikiException(exception); } }
From source file:org.apache.heron.uploader.http.HttpUploaderTest.java
@Before public void setUp() throws Exception { super.setUp(); this.serverBootstrap.registerHandler("/*", (HttpRequestHandler) (request, response, context) -> { response.setStatusCode(HttpStatus.SC_OK); response.setEntity(new StringEntity(EXPECTED_URI)); });/*from w w w.j a va 2 s . c o m*/ httpHost = start(); final URI uri = new URIBuilder().setScheme("http").setHost(httpHost.getHostName()) .setPort(httpHost.getPort()).setPath(EXPECTED_URI).build(); // Create the minimum config for tests config = Config.newBuilder().put(Key.CLUSTER, "cluster").put(Key.ROLE, "role") .put(Key.TOPOLOGY_NAME, "topology").put(Key.TOPOLOGY_PACKAGE_TYPE, PackageType.TAR) .put(Key.TOPOLOGY_PACKAGE_FILE, tempFile.getCanonicalPath()) .put(HttpUploaderContext.HERON_UPLOADER_HTTP_URI, uri.getPath()).build(); }
From source file:org.bedework.synch.cnctrs.file.FileConnectorInstance.java
@Override public URI getUri() throws SynchException { try {//from w ww. j a v a2s.c o m //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:com.vmware.identity.rest.core.client.AffinitizedHostRetriever.java
@Override public URIBuilder getURIBuilder() throws ClientException { CdcDCEntry entry = getAvailableDomainController(); URIBuilder builder = new URIBuilder().setScheme(getScheme()).setHost(entry.dcName); if (hasPort()) { builder.setPort(port);/*from w w w .j a v a 2 s .c o m*/ } return builder; }
From source file:com.clxcommunications.xms.BatchDeliveryReportParamsTest.java
@Property public void generatesValidQueryParameters(BatchDeliveryReportParams.ReportType reportType, Set<Integer> codes) throws Exception { BatchDeliveryReportParams filter = ClxApi.batchDeliveryReportParams().reportType(reportType) .addStatus(DeliveryStatus.EXPIRED, DeliveryStatus.DELIVERED).codes(codes).build(); List<NameValuePair> params = filter.toQueryParams(); // Will throw IllegalArgumentException if an invalid URI is attempted. new URIBuilder().addParameters(params).build(); }
From source file:nl.stil4m.ideal.executor.RequestExecutor.java
private HttpGet buildHttpRequest(IdealRequest request) throws URISyntaxException { URIBuilder builder = new URIBuilder().setScheme(scheme).setHost(url).setPath(path); Map<String, String> data = request.getData(); Set<Map.Entry<String, String>> set = data.entrySet(); for (Map.Entry<String, String> entry : set) { builder.addParameter(entry.getKey(), entry.getValue()); }// ww w . j av a2 s . c om URI uri = builder.build(); return new HttpGet(uri); }