Example usage for org.springframework.web.util UriComponentsBuilder fromHttpUrl

List of usage examples for org.springframework.web.util UriComponentsBuilder fromHttpUrl

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder fromHttpUrl.

Prototype

public static UriComponentsBuilder fromHttpUrl(String httpUrl) 

Source Link

Document

Create a URI components builder from the given HTTP URL String.

Usage

From source file:edu.harvard.i2b2.fhir.FetchInterceptor.java

void alterResponse(HttpServletResponse response, String path) throws IOException {
    ourLog.info("altering response");

    RestTemplate restTemplate = new MyGlobal().getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", "application/json");

    HttpEntity entity = new HttpEntity(headers);
    Map<String, String> params = new HashMap<String, String>();
    String url = "http://localhost:8080/fhirRest/" + path;
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
    HttpEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
            entity, String.class);
    String responseTxt = responseEntity.getBody();
    response.getWriter().println(responseTxt);

}

From source file:com.jvoid.core.controller.HomeController.java

@RequestMapping(value = "/jvoid-checkout-cart", method = RequestMethod.POST)
public @ResponseBody String jvoidChrckoutCart(@RequestParam("params") String jsonParams) {
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);

    System.out.println("jsonParams=>" + jsonParams);
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(ServerUris.QUOTE_SERVER_URI + URIConstants.CHECKOUT_CART)
            .queryParam("params", jsonParams);
    HttpEntity<?> entity = new HttpEntity<>(headers);
    HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity,
            String.class);

    JSONObject returnJsonObj = null;//from  w w w.j  a  v a2s .c o  m
    try {
        returnJsonObj = new JSONObject(returnString.getBody());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("returnJsonObj=>" + returnJsonObj);

    String result = "";
    try {
        result = returnJsonObj.getString("result");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String response = "";
    if (result.equals("Success")) {
        UriComponentsBuilder builder1 = UriComponentsBuilder
                .fromHttpUrl(ServerUris.ORDER_SERVER_URI + URIConstants.ADD_ORDER)
                .queryParam("params", jsonParams);
        HttpEntity<?> entity1 = new HttpEntity<>(headers);
        HttpEntity<String> returnString1 = restTemplate.exchange(builder1.build().toUri(), HttpMethod.GET,
                entity1, String.class);
        response = returnString1.getBody();
    }

    return response;
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Create a new subscription//w ww  .  j  a v  a 2s . c o  m
 * @param subscription the Subscription to add
 * @return subscription Id
 */
public ListenableFuture<String> addSubscription(Subscription subscription) {
    ListenableFuture<ResponseEntity<Void>> s = request(HttpMethod.POST,
            UriComponentsBuilder.fromHttpUrl(baseURL).path("v2/subscriptions").toUriString(), subscription,
            Void.class);
    return new ListenableFutureAdapter<String, ResponseEntity<Void>>(s) {
        @Override
        protected String adapt(ResponseEntity<Void> result) throws ExecutionException {
            return extractId(result);
        }
    };
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Get a Subscription by subscription ID
 * @param subscriptionId the subscription ID
 * @return the subscription/*from  w w w  .  ja  va 2 s .co m*/
 */
public ListenableFuture<Subscription> getSubscription(String subscriptionId) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/subscriptions/{subscriptionId}");
    return adapt(request(HttpMethod.GET, builder.buildAndExpand(subscriptionId).toUriString(), null,
            Subscription.class));
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Update the subscription by subscription ID
 * @param subscriptionId the subscription ID
 * @return//from  www . j  av  a  2  s .c  o m
 */
public ListenableFuture<Void> updateSubscription(String subscriptionId, Subscription subscription) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/subscriptions/{subscriptionId}");
    return adapt(request(HttpMethod.PATCH, builder.buildAndExpand(subscriptionId).toUriString(), subscription,
            Void.class));
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Delete the subscription by subscription ID
 * @param subscriptionId the subscription ID
 * @return//  w  w w  .  j  a va 2 s.  co  m
 */
public ListenableFuture<Void> deleteSubscription(String subscriptionId) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/subscriptions/{subscriptionId}");
    return adapt(
            request(HttpMethod.DELETE, builder.buildAndExpand(subscriptionId).toUriString(), null, Void.class));
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Update, append or delete multiple entities in a single operation
 * @param bulkUpdateRequest a BulkUpdateRequest with an actionType and a list of entities to update
 * @return Nothing on success/*from   w w w  . j  a v  a 2  s. c  om*/
 */
public ListenableFuture<Void> bulkUpdate(BulkUpdateRequest bulkUpdateRequest) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/op/update");
    return adapt(request(HttpMethod.POST, builder.toUriString(), bulkUpdateRequest, Void.class));
}

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// w  w w. ja  va  2s. 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

/**
 * Create, update or delete registrations to multiple entities in a single operation
 * @param bulkRegisterRequest defines the list of entities to register
 * @return a list of registration ids/*from   w  w  w.j av a2  s.c o m*/
 */
public ListenableFuture<String[]> bulkRegister(BulkRegisterRequest bulkRegisterRequest) {
    return adapt(request(HttpMethod.POST,
            UriComponentsBuilder.fromHttpUrl(baseURL).path("v2/op/register").toUriString(), bulkRegisterRequest,
            String[].class));
}