List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:com.griddynamics.jagger.invoker.http.HttpInvoker.java
@Override protected HttpRequestBase getHttpMethod(HttpQuery query, String endpoint) { try {/* w w w . j a v a2 s .co m*/ URIBuilder uriBuilder = new URIBuilder(endpoint); if (!HttpQuery.Method.POST.equals(query.getMethod())) { for (Map.Entry<String, String> methodParam : query.getMethodParams().entrySet()) { uriBuilder.setParameter(methodParam.getKey(), methodParam.getValue()); } } return createMethod(query, uriBuilder.build()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:ext.deployit.onfailurehandler.OnReleaseFailureEventListener.java
private void invokeOnFailureHandler(Release release) throws IOException, URISyntaxException { String handlerEndpoint = getHandlerEndpoint(); // sentinel object so OK to use == if (handlerEndpoint == UNINITIALIZED) { logger.error("Global variable '{}' not found! Doing nothing", ENDPOINT_VARIABLE_NAME); return;//ww w . j a va2s. c om } URIBuilder requestUri = new URIBuilder().setScheme(ENDPOINT_SCHEME).setHost(ENDPOINT_HOST) .setPort(ENDPOINT_PORT).setPath(getHandlerEndpoint()).addParameter("releaseId", release.getId()) .addParameter("onFailureUser", ENDPOINT_USER); HttpGet request = new HttpGet(requestUri.build()); // without this, Apache HC will only send auth *after* a failure HttpClientContext authenticatingContext = HttpClientContext.create(); authenticatingContext.setAuthCache(PREEMPTIVE_AUTH_CACHE); logger.debug("About to execute callback to {}", request); CloseableHttpResponse response = HTTP_CLIENT.execute(request, authenticatingContext); try { logger.info("Response line from request: {}", response.getStatusLine()); logger.debug("Response body: {}", EntityUtils.toString(response.getEntity())); } finally { response.close(); } }
From source file:com.kurtraschke.nyctrtproxy.ProxyProvider.java
public void update() { _log.info("doing update"); GtfsRealtimeFullUpdate grfu = new GtfsRealtimeFullUpdate(); List<TripUpdate> tripUpdates = Lists.newArrayList(); MatchMetrics totalMetrics = new MatchMetrics(); // For each feed ID, read in GTFS-RT, process trip updates, push to output. for (int feedId : _feedIds) { URI feedUrl;/*from w ww . java 2 s.c om*/ try { URIBuilder ub = new URIBuilder("http://datamine.mta.info/mta_esi.php"); ub.addParameter("key", _key); ub.addParameter("feed_id", Integer.toString(feedId)); feedUrl = ub.build(); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } HttpGet get = new HttpGet(feedUrl); FeedMessage message = null; for (int tries = 0; tries < _nTries; tries++) { try { CloseableHttpResponse response = _httpClient.execute(get); try (InputStream streamContent = response.getEntity().getContent()) { message = FeedMessage.parseFrom(streamContent, _extensionRegistry); if (!message.getEntityList().isEmpty()) break; Thread.sleep(_retryDelay * 1000); } } catch (Exception e) { _log.error("Error parsing protocol buffer for feed={}. try={}, retry={}. Error={}", feedId, tries, tries < _nTries, e.getMessage()); } } if (message != null) { try { tripUpdates.addAll(_processor.processFeed(feedId, message, totalMetrics)); } catch (Exception e) { e.printStackTrace(); } } } for (TripUpdate tu : tripUpdates) { FeedEntity.Builder feb = FeedEntity.newBuilder(); feb.setTripUpdate(tu); feb.setId(tu.getTrip().getTripId()); grfu.addEntity(feb.build()); } _log.info("writing {} total trip updates", tripUpdates.size()); _tripUpdatesSink.handleFullUpdate(grfu); if (_listener != null) _listener.reportMatchesTotal(totalMetrics, _processor.getCloudwatchNamespace()); }
From source file:org.wso2.carbon.registry.notes.test.PublisherNotesTestCase.java
@Test(groups = "wso2.greg", description = "Add Schema without name", dependsOnMethods = "addNoteTestCase") public void getNoteTestCase() throws Exception { Thread.sleep(60000);/*from ww w . j a v a2s.c om*/ String session_id = authenticateJaggeryAPI(); CookieStore cookieStore = new BasicCookieStore(); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpClient client = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(); builder.setScheme("https").setHost("localhost:10343").setPath("/publisher/apis/assets") .setParameter("type", "note").setParameter("q", "overview_resourcepath\":\"/_system/governance/trunk/soapservices/4.5.0/SOAPService1\""); URI uri = builder.build(); HttpGet httpget = new HttpGet(uri); HttpResponse response = client.execute(httpget); assertEquals("OK", response.getStatusLine().getReasonPhrase()); }
From source file:ph.com.globe.connect.Sms.java
/** * Build request url./*from www. j ava2 s .com*/ * * @param url target url * @return String * @throws ApiException api exception */ protected String buildUrl(String url) throws ApiException { // try parsing url try { // build url url = String.format(url, this.senderAddress); // initialize url builder URIBuilder builder = new URIBuilder(url); // set access token parameter builder.setParameter("access_token", this.accessToken); // build the url url = builder.build().toString(); return url; } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } }
From source file:com.collective.celos.CelosClient.java
public Set<WorkflowID> getWorkflowList() throws Exception { URIBuilder uriBuilder = new URIBuilder(address); uriBuilder.setPath(uriBuilder.getPath() + WORKFLOW_LIST_PATH); HttpGet workflowListGet = new HttpGet(uriBuilder.build()); HttpResponse getResponse = execute(workflowListGet); InputStream content = getResponse.getEntity().getContent(); return parseWorkflowIdsList(content); }
From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java
public RouteSchedule downloadRouteScheduleInfo(String routeId, String date) throws WMATAAPIException { try {//from ww w. j a v a 2s .c om URIBuilder b = new URIBuilder("http://api.wmata.com/Bus.svc/json/JRouteSchedule"); b.addParameter(API_KEY_PARAM_NAME, _apiKey); b.addParameter("includeVariations", "false"); b.addParameter("date", date); b.addParameter("routeID", routeId); return mapUrl(b.build(), true, RouteSchedule.class, _jsonMapper); } catch (Exception e) { throw new WMATAAPIException(e); } }
From source file:de.unioninvestment.eai.portal.portlet.crud.domain.portal.Portal.java
/** * Opens a new portal page in the current browser window * * @param friendlyUrl the url of the target page * @param parameters map of strings that are passed as portal parameters * @throws URISyntaxException//from w ww . ja v a 2s. co m */ public void open(String friendlyUrl, Map<String, String> parameters) throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder(friendlyUrl); if (parameters != null) { for (Entry<String, String> entry : parameters.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } } String url = uriBuilder.build().toASCIIString(); UI.getCurrent().getPage().open(url, "_self"); }
From source file:ru.bozaro.protobuf.client.ProtobufClientGet.java
@NotNull public HttpUriRequest createRequest(@NotNull Descriptors.MethodDescriptor method, @NotNull Message request) throws IOException, URISyntaxException { final URIBuilder builder = new URIBuilder(getBaseUri().resolve(method.getService().getName().toLowerCase() + "/" + method.getName().toLowerCase() + getFormat().getSuffix())); for (Descriptors.FieldDescriptor field : method.getInputType().getFields()) { if (request.hasField(field)) { builder.addParameter(field.getName(), request.getField(field).toString()); }// ww w . j a va2s. c om } return new HttpGet(builder.build()); }