Example usage for org.springframework.http HttpMethod GET

List of usage examples for org.springframework.http HttpMethod GET

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod GET.

Prototype

HttpMethod GET

To view the source code for org.springframework.http HttpMethod GET.

Click Source Link

Usage

From source file:io.github.cdelmas.spike.springboot.hello.SampleController.java

@RequestMapping("/")
@ResponseBody//from  www. ja  v  a2  s  .  c o m
String home(@RequestHeader("Authorization") String authToken) {

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Accept", "application/json");
    headers.add("Authorization", authToken);
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(null, headers);

    RestTemplate rest = new RestTemplate();
    ResponseEntity<Car[]> responseEntity = rest.exchange("https://localhost:8443/cars", HttpMethod.GET,
            requestEntity, Car[].class);
    List<Car> cars = asList(responseEntity.getBody());

    return "Hello World! " + cars.stream().map(Car::getName).collect(toList());
}

From source file:org.trustedanalytics.cloud.uaa.UaaClient.java

@Override
public SearchResults<ScimUser> getUsers() {
    ResponseEntity<SearchResults<ScimUser>> result = uaaRestTemplate.exchange(uaaBaseUrl + "/Users",
            HttpMethod.GET, null, new ParameterizedTypeReference<SearchResults<ScimUser>>() {
            });//from  ww  w. jav a2s .com

    return result.getBody();
}

From source file:fi.helsinki.opintoni.integration.coursepage.CoursePageRestClient.java

@Cacheable(CacheConstants.COURSE_PAGE_ONE_OFF_EVENTS)
public List<CoursePageEvent> getEvents(String courseImplementationId) {
    ResponseEntity<List<CoursePageEvent>> responseEntity = restTemplate.exchange(
            "{baseUrl}/events?course_implementation_id={courseImplementationId}", HttpMethod.GET, null,
            new ParameterizedTypeReference<List<CoursePageEvent>>() {
            }, baseUrl, courseImplementationId);

    return Optional.ofNullable(responseEntity.getBody()).orElse(newArrayList());
}

From source file:learning.candystore.controller.CandyActionServerSideTest.java

@Test
@Ignore//from   w w  w  . j  a va 2s  .  co  m
public void getAddress() {
    request.setMethod(HttpMethod.GET.name());
    request.setRequestURI("/student/{id}");
    HashMap<String, String> pathVariablesMap = new HashMap<>(1);
    pathVariablesMap.put("id", "1");
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariablesMap);
    Class<?>[] parameterTypes = new Class<?>[] { Integer.class };
    ModelAndView mv = null;
    try {
        mv = handlerAdapter.handle(request, response,
                new HandlerMethod(candyAction, "retrieve", parameterTypes));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.CheckingIfAppExistsStep.java

public boolean check(String appName, String spaceGuid) throws EnginePublicationException {

    LOGGER.info("Checking if app " + appName + " already exists in CloudFoundry");
    ResponseEntity<String> response = cfRestTemplate.exchange(cfAppInSpaceUrl, HttpMethod.GET,
            HttpCommunication.simpleJsonRequest(), String.class, spaceGuid, appName);

    Integer appsNumber;// w  ww  . j a va2s .c  o m
    try {
        appsNumber = JsonDataFetcher.getIntValue(response.getBody(), APPS_NUMBER_JSON_PATH);
        LOGGER.debug("Number of found apps: " + appsNumber);
        return appsNumber != 0;
    } catch (IOException e) {
        throw new EnginePublicationException("Unable to check if CloudFoundry app already exists: ", e);
    }
}

From source file:org.cloudfoundry.identity.uaa.login.UaaApprovalsService.java

@Override
public Map<String, List<DescribedApproval>> getCurrentApprovalsByClientId() {
    Map<String, List<DescribedApproval>> result = new HashMap<>();
    ResponseEntity<Set<DescribedApproval>> approvalsResponse = restTemplate.exchange(approvalsUrl,
            HttpMethod.GET, null, new ParameterizedTypeReference<Set<DescribedApproval>>() {
            });//from   w  ww .  ja va2s.  c  o m
    Set<DescribedApproval> approvals = approvalsResponse.getBody();

    for (DescribedApproval approval : approvals) {
        List<DescribedApproval> clientApprovals = result.get(approval.getClientId());
        if (clientApprovals == null) {
            clientApprovals = new ArrayList<>();
            result.put(approval.getClientId(), clientApprovals);
        }

        String scope = approval.getScope();
        if (!scope.contains(".")) {
            approval.setDescription("Access your data with scope '" + scope + "'");
            clientApprovals.add(approval);
        } else {
            String resource = scope.substring(0, scope.lastIndexOf("."));
            if ("uaa".equals(resource)) {
                // special case: don't need to prompt for internal uaa
                // scopes
                continue;
            }
            String access = scope.substring(scope.lastIndexOf(".") + 1);
            approval.setDescription("Access your '" + resource + "' resources with scope '" + access + "'");
            clientApprovals.add(approval);
        }
    }
    for (List<DescribedApproval> approvalList : result.values()) {
        Collections.sort(approvalList, new Comparator<DescribedApproval>() {
            @Override
            public int compare(DescribedApproval o1, DescribedApproval o2) {
                return o1.getScope().compareTo(o2.getScope());
            }
        });
    }
    return result;
}

From source file:org.androidannotations.test15.rest.HttpMethodServiceTest.java

@Test
public void useGetHttpMethod() {
    HttpMethodsService_ service = new HttpMethodsService_(null);

    RestTemplate restTemplate = mock(RestTemplate.class);
    service.setRestTemplate(restTemplate);

    service.get();//from   w w w. j a  v a 2 s  . c  o m

    verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.GET),
            Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any());
}

From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataService.java

/**
 * Return one object from Reference data service.
 *
 * @param id UUID of requesting object./*  w  ww  .j  a v  a2 s  .c om*/
 * @return Requesting reference data object.
 */
public T findOne(UUID id) {
    String url = getServiceUrl() + getUrl() + id;

    try {
        ResponseEntity<T> responseEntity = restTemplate.exchange(buildUri(url), HttpMethod.GET, createEntity(),
                getResultClass());
        return responseEntity.getBody();
    } catch (HttpStatusCodeException ex) {
        // rest template will handle 404 as an exception, instead of returning null
        if (ex.getStatusCode() == HttpStatus.NOT_FOUND) {
            logger.warn("{} with id {} does not exist. ", getResultClass().getSimpleName(), id);
            return null;
        } else {
            throw buildDataRetrievalException(ex);
        }
    }
}

From source file:fi.helsinki.opintoni.integration.unisport.UnisportRestClient.java

@Override
public Optional<UnisportUser> getUnisportUserByPrincipal(String username) {
    UnisportUser unisportUser = null;/*from   ww w. j a  va2  s  .  co  m*/
    try {
        unisportUser = restTemplate
                .exchange("{baseUrl}/api/v1/{locale}/ext/opintoni/authorization?eppn={userName}",
                        HttpMethod.GET, null, new ParameterizedTypeReference<UnisportUser>() {
                        }, baseUrl, new Locale("en"), username)
                .getBody();

    } catch (HttpStatusCodeException e) {
        if (!e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw e;
        }
    }
    return Optional.ofNullable(unisportUser);
}

From source file:fi.helsinki.opintoni.server.CoursePageServer.java

public void expectCourseImplementationRequest(String courseImplementationId) {
    server.expect(requestTo(courseImplementationUrl(courseImplementationId))).andExpect(method(HttpMethod.GET))
            .andRespond(//from ww  w .ja va  2s  .  c  o  m
                    withSuccess(SampleDataFiles.toText("coursepage/courses.json"), MediaType.APPLICATION_JSON));
}