List of usage examples for org.springframework.web.util UriComponentsBuilder toUriString
public String toUriString()
From source file:io.pivotal.github.GithubClient.java
public void createRepository() throws IOException { if (!shouldDeleteCreateRepository()) { return;/* w w w . j a v a2 s. c o m*/ } String slug = getRepositorySlug(); UriComponentsBuilder uri = UriComponentsBuilder.fromUriString("https://api.github.com/user/repos") .queryParam("access_token", getAccessToken()); Map<String, String> repository = new HashMap<>(); repository.put("name", slug.split("/")[1]); rest.postForEntity(uri.toUriString(), repository, String.class); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Retrieve the list of all Registrations * @return a list of registrations/*w w w .j a v a 2 s .c o m*/ */ public ListenableFuture<List<Registration>> getRegistrations() { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/registrations"); ListenableFuture<ResponseEntity<Registration[]>> e = request(HttpMethod.GET, builder.toUriString(), null, Registration[].class); return new ListenableFutureAdapter<List<Registration>, ResponseEntity<Registration[]>>(e) { @Override protected List<Registration> adapt(ResponseEntity<Registration[]> result) throws ExecutionException { return new ArrayList<>(Arrays.asList(result.getBody())); } }; }
From source file:alfio.manager.PaypalManager.java
public String createCheckoutRequest(Event event, String reservationId, OrderSummary orderSummary, CustomerName customerName, String email, String billingAddress, Locale locale, boolean postponeAssignment) throws Exception { APIContext apiContext = getApiContext(event); Optional<String> experienceProfileId = getOrCreateWebProfile(event, locale, apiContext); List<Transaction> transactions = buildPaymentDetails(event, orderSummary, reservationId, locale); String eventName = event.getShortName(); Payer payer = new Payer(); payer.setPaymentMethod("paypal"); Payment payment = new Payment(); payment.setIntent("sale"); payment.setPayer(payer);/* ww w . j av a 2 s. c o m*/ payment.setTransactions(transactions); RedirectUrls redirectUrls = new RedirectUrls(); String baseUrl = StringUtils.removeEnd( configurationManager.getRequiredValue( Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.BASE_URL)), "/"); String bookUrl = baseUrl + "/event/" + eventName + "/reservation/" + reservationId + "/book"; UriComponentsBuilder bookUrlBuilder = UriComponentsBuilder.fromUriString(bookUrl) .queryParam("fullName", customerName.getFullName()) .queryParam("firstName", customerName.getFirstName()) .queryParam("lastName", customerName.getLastName()).queryParam("email", email) .queryParam("billingAddress", billingAddress).queryParam("postponeAssignment", postponeAssignment) .queryParam("hmac", computeHMAC(customerName, email, billingAddress, event)); String finalUrl = bookUrlBuilder.toUriString(); redirectUrls.setCancelUrl(finalUrl + "&paypal-cancel=true"); redirectUrls.setReturnUrl(finalUrl + "&paypal-success=true"); payment.setRedirectUrls(redirectUrls); experienceProfileId.ifPresent(payment::setExperienceProfileId); Payment createdPayment = payment.create(apiContext); TicketReservation reservation = ticketReservationRepository.findReservationById(reservationId); //add 15 minutes of validity in case the paypal flow is slow ticketReservationRepository.updateValidity(reservationId, DateUtils.addMinutes(reservation.getValidity(), 15)); if (!"created".equals(createdPayment.getState())) { throw new Exception(createdPayment.getFailureReason()); } //extract url for approval return createdPayment.getLinks().stream().filter(l -> "approval_url".equals(l.getRel())).findFirst() .map(Links::getHref).orElseThrow(IllegalStateException::new); }
From source file:org.mitreid.multiparty.web.ResourceController.java
/** * @param server//from w w w . j av a 2s . c o m * @param client * @return */ private String redirectForPAT(MultipartyServerConfiguration server, RegisteredClient client, HttpSession session) { String state = new RandomValueStringGenerator().generate(); session.setAttribute("STATE", state); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(server.getAuthorizationEndpointUri()); builder.queryParam("client_id", client.getClientId()); builder.queryParam("response_type", "code"); builder.queryParam("state", state); builder.queryParam("scope", "uma_protection"); builder.queryParam("redirect_uri", "http://localhost:8080/multiparty-resource/pat_callback"); logger.warn("Redirecting to: " + builder.toUriString()); return "redirect:" + builder.toUriString(); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Retrieve a list of entity types// w ww.j a v a 2s.co m * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a pagined list of entity types */ public ListenableFuture<Paginated<EntityType>> getEntityTypes(int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/types"); addPaginationParams(builder, offset, limit); if (count) { addParam(builder, "options", "count"); } return adaptPaginated(request(HttpMethod.GET, builder.toUriString(), null, EntityType[].class), offset, limit); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Retrieve the list of all Subscriptions present in the system * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a pagined list of Subscriptions */// w ww.j a v a2 s.com public ListenableFuture<Paginated<Subscription>> getSubscriptions(int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/subscriptions"); addPaginationParams(builder, offset, limit); if (count) { addParam(builder, "options", "count"); } return adaptPaginated(request(HttpMethod.GET, builder.toUriString(), null, Subscription[].class), offset, limit); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Discover registration matching entities and their attributes * @param bulkQueryRequest defines the list of entities, attributes and scopes to match registrations * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a paginated list of registration *//*from w w w. j a va 2 s . c o m*/ public ListenableFuture<Paginated<Registration>> bulkDiscover(BulkQueryRequest bulkQueryRequest, int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/op/discover"); addPaginationParams(builder, offset, limit); if (count) { addParam(builder, "options", "count"); } return adaptPaginated( request(HttpMethod.POST, builder.toUriString(), bulkQueryRequest, Registration[].class), offset, limit); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Query multiple entities in a single operation * @param bulkQueryRequest defines the list of entities, attributes and scopes to match entities * @param orderBy an optional list of attributes to order the entities (null or empty for none) * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a paginated list of entities/*from www . j a va2 s .c om*/ */ public ListenableFuture<Paginated<Entity>> bulkQuery(BulkQueryRequest bulkQueryRequest, Collection<String> orderBy, int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/op/query"); addPaginationParams(builder, offset, limit); addParam(builder, "orderBy", orderBy); if (count) { addParam(builder, "options", "count"); } return adaptPaginated(request(HttpMethod.POST, builder.toUriString(), bulkQueryRequest, Entity[].class), offset, limit); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Retrieve a list of Entities//from ww w . java 2 s . co m * @param ids an optional list of entity IDs (cannot be used with idPatterns) * @param idPattern an optional pattern of entity IDs (cannot be used with ids) * @param types an optional list of types of entity * @param attrs an optional list of attributes to return for all entities * @param query an optional Simple Query Language query * @param geoQuery an optional Geo query * @param orderBy an option list of attributes to difine the order of entities * @param offset an optional offset (0 for none) * @param limit an optional limit (0 for none) * @param count true to return the total number of matching entities * @return a pagined list of Entities */ public ListenableFuture<Paginated<Entity>> getEntities(Collection<String> ids, String idPattern, Collection<String> types, Collection<String> attrs, String query, GeoQuery geoQuery, Collection<String> orderBy, int offset, int limit, boolean count) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/entities"); addParam(builder, "id", ids); addParam(builder, "idPattern", idPattern); addParam(builder, "type", types); addParam(builder, "attrs", attrs); addParam(builder, "query", query); addGeoQueryParams(builder, geoQuery); addParam(builder, "orderBy", orderBy); addPaginationParams(builder, offset, limit); if (count) { addParam(builder, "options", "count"); } return adaptPaginated(request(HttpMethod.GET, builder.toUriString(), null, Entity[].class), offset, limit); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.ExecuteServiceHandler.java
/** * Handles requests to execute a service. * TODO this needs to change to leverage pz-jbcommon ExecuteServiceMessage after it builds. * /* w ww . j a v a2 s .c om*/ * @param message * @return the Response as a String */ public ResponseEntity<String> handle(ExecuteServiceData data) { coreLogger.log("executeService serviceId=" + data.getServiceId(), PiazzaLogger.INFO); ResponseEntity<String> responseEntity = null; String serviceId = data.getServiceId(); Service sMetadata = null; // Default request mimeType application/json String requestMimeType = "application/json"; try { // Accessor throws exception if can't find service sMetadata = accessor.getServiceById(serviceId); ObjectMapper om = new ObjectMapper(); String result = om.writeValueAsString(sMetadata); coreLogger.log(result, PiazzaLogger.INFO); } catch (Exception ex) { ex.printStackTrace(); } if (sMetadata != null) { String rawURL = sMetadata.getUrl(); coreLogger.log("URL to use = " + rawURL, PiazzaLogger.INFO); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rawURL); Map<String, DataType> postObjects = new HashMap<>(); Iterator<Entry<String, DataType>> it = data.getDataInputs().entrySet().iterator(); String postString = ""; while (it.hasNext()) { Entry<String, DataType> entry = it.next(); String inputName = entry.getKey(); coreLogger.log("The parameter is " + inputName, PiazzaLogger.DEBUG); if (entry.getValue() instanceof URLParameterDataType) { String paramValue = ((URLParameterDataType) entry.getValue()).getContent(); if (inputName.length() == 0) { coreLogger.log("sMetadata.getResourceMeta=" + sMetadata.getResourceMetadata(), PiazzaLogger.DEBUG); builder = UriComponentsBuilder.fromHttpUrl(sMetadata.getUrl() + "?" + paramValue); coreLogger.log("Builder URL is " + builder.toUriString(), PiazzaLogger.DEBUG); } else { builder.queryParam(inputName, paramValue); coreLogger.log("Input Name=" + inputName + " paramValue=" + paramValue, PiazzaLogger.DEBUG); } } else if (entry.getValue() instanceof BodyDataType) { BodyDataType bdt = (BodyDataType) entry.getValue(); postString = bdt.getContent(); requestMimeType = bdt.getMimeType(); if ((requestMimeType == null) || (requestMimeType.length() == 0)) { coreLogger.log("Body mime type not specified", PiazzaLogger.ERROR); return new ResponseEntity<>("Body mime type not specified", HttpStatus.BAD_REQUEST); } } else { // Default behavior for other inputs, put them in list of objects // which are transformed into JSON consistent with default requestMimeType coreLogger.log("inputName =" + inputName + "entry Value=" + entry.getValue(), PiazzaLogger.INFO); postObjects.put(inputName, entry.getValue()); } } coreLogger.log("Final Builder URL" + builder.toUriString(), PiazzaLogger.INFO); if (postString.length() > 0 && postObjects.size() > 0) { coreLogger.log("String Input not consistent with other Inputs", PiazzaLogger.ERROR); return new ResponseEntity<>("String Input not consistent with other Inputs", HttpStatus.BAD_REQUEST); } else if (postObjects.size() > 0) { ObjectMapper mapper = makeObjectMapper(); try { postString = mapper.writeValueAsString(postObjects); } catch (JsonProcessingException e) { coreLogger.log(e.getMessage(), PiazzaLogger.ERROR); return new ResponseEntity<>("Could not marshal post requests", HttpStatus.BAD_REQUEST); } } URI url = URI.create(builder.toUriString()); if (sMetadata.getMethod().equals("GET")) { coreLogger.log("GetForEntity URL=" + url, PiazzaLogger.INFO); responseEntity = template.getForEntity(url, String.class); } else { HttpHeaders headers = new HttpHeaders(); // Set the mimeType of the request MediaType mediaType = createMediaType(requestMimeType); headers.setContentType(mediaType); HttpEntity<String> requestEntity = makeHttpEntity(headers, postString); coreLogger.log("PostForEntity URL=" + url, PiazzaLogger.INFO); responseEntity = template.postForEntity(url, requestEntity, String.class); } } else { return new ResponseEntity<>("Service Id" + data.getServiceId() + "not found", HttpStatus.NOT_FOUND); } return responseEntity; }