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:com.ge.predix.uaa.token.lib.FastTokenServiceTest.java

public FastTokenServiceTest() throws Exception {

    this.body.put(Claims.CLIENT_ID, "remote");
    this.body.put(Claims.USER_NAME, "olds");
    this.body.put(Claims.EMAIL, "olds@vmware.com");
    this.body.put(Claims.ISS, TOKEN_ISSUER_ID);
    this.body.put(Claims.USER_ID, "HDGFJSHGDF");

    ParameterizedTypeReference<Map<String, Object>> typeRef = new ParameterizedTypeReference<Map<String, Object>>() {
        // Nothing to add.
    };//from www  .  ja  v a 2 s  .c o m

    RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
    Mockito.when(restTemplate.exchange(TOKEN_KEY_URL, HttpMethod.GET, null, typeRef))
            .thenReturn(TestTokenUtil.mockTokenKeyResponseEntity());
    this.services.setRestTemplate(restTemplate);

    List<String> trustedIssuers = new ArrayList<>();
    trustedIssuers.add(TOKEN_ISSUER_ID);
    this.services.setTrustedIssuers(trustedIssuers);
}

From source file:com.interop.webapp.WebAppTests.java

@Test
public void testLoginPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong content:\n" + entity.getBody(), entity.getBody().contains("_csrf"));
}

From source file:org.zalando.twintip.spring.SchemaResourcePropertiesNullValueTest.java

@Test
public void apiDefaultBaseUrl() throws Exception {
    mvc.perform(request(HttpMethod.GET, "/api"))
            .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
            .andExpect(jsonPath("$.host", is("petstore.swagger.io")))
            .andExpect(jsonPath("$.schemes", hasSize(1)));
}

From source file:demo.service.impl.DefaultServiceLocationService.java

/**
 * Enriches the provided {@link CurrentPosition} with the closest service location
 * IF the {@link CurrentPosition} has a {@link VehicleStatus} of:
 *
 * <ul>/*from   w w w.j  av a 2s  .  com*/
 *   <li>{@link VehicleStatus#SERVICE_NOW}</li>
 *   <li>{@link VehicleStatus#SERVICE_SOON}</li>
 *   <li>{@link VehicleStatus#STOP_NOW}</li>
 * <ul>
 *
 * @param currentPosition Will be enriched with the closest service location
 * @throws Exception
 */
@HystrixCommand(commandKey = "serviceLocations", commandProperties = {
        //@HystrixProperty(name = "circuitBreaker.forceOpen", value = "true")
}, fallbackMethod = "handleServiceLocationServiceFailure")
@Override
public void updateServiceLocations(CurrentPosition currentPosition) {

    switch (currentPosition.getVehicleStatus()) {

    case SERVICE_NOW:
    case SERVICE_SOON:
    case STOP_NOW:
        ResponseEntity<Resource<ServiceLocation>> result = this.restTemplate.exchange(
                "http://service-location-service/serviceLocations/search/findFirstByLocationNear?location={lat},{long}",
                HttpMethod.GET, new HttpEntity<Void>((Void) null),
                new ParameterizedTypeReference<Resource<ServiceLocation>>() {
                }, currentPosition.getLocation().getLatitude(), currentPosition.getLocation().getLongitude());
        if (result.getStatusCode() == HttpStatus.OK && result.getBody().getContent() != null) {
            currentPosition.setServiceLocation(result.getBody().getContent());
        }
        break;
    default:
    }

}

From source file:org.projecthdata.social.api.impl.RootTemplate.java

/**
 * Adds the correct accept header for a GET request of an atom feed
 * //w ww . ja va 2  s.  c  o m
 * @param url
 *            - the URL of the feed to request
 * @return
 */
public AtomFeed getForAtomFeed(String url) {
    ResponseEntity<AtomFeed> response = restTemplate.exchange(url, HttpMethod.GET, atomFeedRequestEntity,
            AtomFeed.class);
    AtomFeed feed = null;
    try {
        feed = response.getBody();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return feed;
}

From source file:org.zalando.stups.oauth2.spring.server.TokenInfoResourceServerTokenServicesTest.java

@Test
public void buildRequest() {

    RequestEntity<Void> entity = DefaultTokenInfoRequestExecutor.buildRequestEntity(URI.create(TOKENINFO_URL),
            "0123456789");

    Assertions.assertThat(entity).isNotNull();

    Assertions.assertThat(entity.getMethod()).isEqualTo(HttpMethod.GET);
    Assertions.assertThat(entity.getUrl()).isEqualTo(URI.create(TOKENINFO_URL));

    Assertions.assertThat(entity.getHeaders()).containsKey(HttpHeaders.AUTHORIZATION);
    List<String> authorizationHeader = entity.getHeaders().get(HttpHeaders.AUTHORIZATION);
    Assertions.assertThat(authorizationHeader).containsExactly("Bearer 0123456789");

    Assertions.assertThat(entity.getHeaders()).containsKey(HttpHeaders.ACCEPT);
    Assertions.assertThat(entity.getHeaders().getAccept()).contains(MediaType.APPLICATION_JSON);
}

From source file:com.hypersocket.server.handlers.impl.ContentHandlerImpl.java

@Override
public void handleHttpRequest(HttpServletRequest request, HttpServletResponse response,
        HttpResponseProcessor responseProcessor) throws IOException {

    try {// w ww. j  a  v a2 s.co m
        if (request.getMethod() != HttpMethod.GET.toString()) {
            response.sendError(HttpStatus.SC_METHOD_NOT_ALLOWED);
            return;
        }

        String path = translatePath(sanitizeUri(request.getRequestURI()));
        if (path.startsWith("/"))
            path = path.substring(1);

        if (path == null) {
            response.sendError(HttpStatus.SC_FORBIDDEN);
            return;
        }

        if (log.isDebugEnabled()) {
            log.debug("Resolving " + getResourceName() + " resource in " + basePath + ": "
                    + request.getRequestURI());
        }

        int status = getResourceStatus(path);

        if (status != HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug(
                        "Resource not found in " + basePath + " [" + status + "]: " + request.getRequestURI());
            }
            response.sendError(status);
            return;
        }

        if (log.isDebugEnabled()) {
            log.debug("Resource found in " + basePath + ": " + request.getRequestURI());
        }

        // Cache Validation
        String ifModifiedSince = request.getHeader(HttpHeaders.IF_MODIFIED_SINCE);
        if (ifModifiedSince != null && !ifModifiedSince.equals("")) {
            SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
            try {
                Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);

                // Only compare up to the second because the datetime format we send to the client does
                // not have milliseconds
                long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000;
                long fileLastModifiedSeconds = getLastModified(path) / 1000;
                if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
                    if (log.isDebugEnabled()) {
                        log.debug(path + " has not been modified since "
                                + HypersocketUtils.formatDateTime(ifModifiedSinceDate));
                    }
                    sendNotModified(response);
                    return;
                }
            } catch (Throwable e) {
                response.sendError(HttpStatus.SC_BAD_REQUEST);
                return;
            }
        }

        long fileLength = getResourceLength(path);
        long actualLength = 0;
        InputStream in = getInputStream(path, request);

        if (fileLength <= 131072) {
            int r;
            byte[] buf = new byte[4096];
            while ((r = in.read(buf)) > -1) {
                response.getOutputStream().write(buf, 0, r);
                if (fileLength < 0) {
                    actualLength += r;
                }

            }
            response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(actualLength));

        } else {
            request.setAttribute(CONTENT_INPUTSTREAM, in);
        }

        setContentTypeHeader(response, path);
        setDateAndCacheHeaders(response, path);

        response.setStatus(HttpStatus.SC_OK);
    } catch (RedirectException e) {
        response.sendRedirect(
                server.resolvePath(basePath + (e.getMessage().startsWith("/") ? "" : "/") + e.getMessage()));
    } finally {
        responseProcessor.sendResponse(request, response, false);
    }

}

From source file:edu.wisc.cypress.dao.taxstmt.RestTaxStatementDao.java

@Override
public void getTaxStatement(String emplid, String docId, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId);
}

From source file:fragment.web.TasksControllerTest.java

@Test
public void testRouting() throws Exception {
    logger.debug("Testing routing....");
    DispatcherTestServlet servlet = getServletInstance();
    @SuppressWarnings("unchecked")
    Class<TasksController> controllerClass = (Class<TasksController>) tasksController.getClass();
    Method expected = locateMethod(controllerClass, "getTasks", new Class[] { Tenant.class, String.class,
            String.class, Integer.class, ModelMap.class, HttpServletRequest.class });
    Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "getTask",
            new Class[] { String.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/1/"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "getApprovalTask",
            new Class[] { Locale.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/approval-task/1"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "actOnApprovalTask",
            new Class[] { String.class, String.class, String.class, HttpServletRequest.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/tasks/approval-task"));
    Assert.assertEquals(expected, handler);
}

From source file:eu.cloudwave.wp5.common.rest.BaseRestClientTest.java

@Test
public void testWithoutHeaders() throws UnsupportedEncodingException, IOException {
    mockServer.expect(requestTo(ANY_URL)).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(getResponseStub(), MediaType.APPLICATION_JSON));

    final ResponseEntity<String> responseEntity = restClientMock.get(ANY_URL, String.class);
    assertThat(responseEntity.getBody()).isEqualTo(getResponseStub());
}