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.develcom.reafolder.ClienteBajaArchivo.java

public void buscarArchivo() throws FileNotFoundException, IOException {

    CodDecodArchivos cda = new CodDecodArchivos();
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    Bufer bufer = new Bufer();
    byte[] buffer = null;
    ResponseEntity<byte[]> response;

    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    headers.setAccept(Arrays.asList(MediaType.ALL));
    HttpEntity<String> entity = new HttpEntity<>(headers);

    response = restTemplate.exchange(/*  w w w. j av  a  2s .  co m*/
            "http://localhost:8080/ServicioDW4J/expediente/buscarFisicoDocumento/21593", HttpMethod.GET, entity,
            byte[].class);

    if (response.getStatusCode().equals(HttpStatus.OK)) {
        buffer = response.getBody();
        FileOutputStream output = new FileOutputStream(new File("c:/documentos/archivo.cod"));
        IOUtils.write(response.getBody(), output);
        cda.decodificar("c:/documentos/archivo.cod", "c:/documentos/archivo.pdf");
    }

}

From source file:com.example.okta.ResourceServer.java

@Override
protected void authorizeRequests(final HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers(HttpMethod.GET, securedRoute).hasAnyAuthority(accessScope).anyRequest()
            .authenticated();/*from  w w w .  j  av  a  2  s  . c  o  m*/
}

From source file:com.companyname.plat.commons.client.HttpRestfulClient.java

public Object getObject(Map<String, String> params, Class clz) {
    RestTemplate restTemplate = new RestTemplate();

    try {/*w  ww .  jav a2  s. co  m*/
        ResponseEntity<Object> entity = restTemplate.exchange(getEndPoint(), HttpMethod.GET,
                getHttpRequest(params), clz);

        setResponseStatus(entity.getStatusCode().toString());
        return entity.getBody();
    } catch (HttpClientErrorException ex) {
        if (HttpStatus.UNAUTHORIZED == ex.getStatusCode()) {
            System.out
                    .println("Unauthorized call to " + this.getEndPoint() + "\nWrong login and/or password (\""
                            + this.getUserName() + "\" / \"" + this.getPassword() + "\")");

            System.out.println("Cause: \n" + ex.getMessage());
        }
    }

    return null;
}

From source file:com.onyxscheduler.domain.HttpJobTest.java

@Test
public void shouldGetSameJobWhenBuildingJobBackFromGeneratedJobDetailWithNoDefaultMethod() {
    HttpJob job = new HttpJob();
    job.setUrl(URL);/* w  w  w.j  a v  a  2  s.  c o  m*/
    job.setMethod(HttpMethod.GET);
    verifyGettingSameJobWhenBuildingJobBackFromGeneratedJobDetail(job);
}

From source file:com.capside.enterpriseseminar.DemoAPIIT.java

@Test
public void testGetStatisticsWithDTO() {
    final String localTeamName = "R. Madrid";
    final String visitorTeamName = "Barcelona";
    ResponseEntity<ApiCtrl.StatisticsDTO> response = restTemplate.exchange(
            "/games/stats/{firstTeam:.*}-vs-{secondTeam:.*}", HttpMethod.GET, null, ApiCtrl.StatisticsDTO.class,
            localTeamName, visitorTeamName);

    assertEquals("Invocation was a success.", HttpStatus.OK, response.getStatusCode());
    assertEquals("Local team", localTeamName, response.getBody().getStatistics().getFirstTeam());
    assertEquals("Visitor team", visitorTeamName, response.getBody().getStatistics().getSecondTeam());
}

From source file:fragment.web.StaticPagesControllerTest.java

@Test
public void testLandingRouting() throws Exception {
    logger.debug("Testing routing....");
    DispatcherTestServlet servlet = this.getServletInstance();
    Method expected = locateMethod(controller.getClass(), "handle", new Class[] { HttpServletRequest.class });

    String[] valid = new String[] { "/errors/notfound", "/errors/error", "/errors/something" };
    for (String uri : valid) {
        Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, uri));
        Assert.assertEquals(expected, handler);
    }/*from   ww  w .j  a  v a 2 s  . c  o  m*/
}

From source file:org.moserp.inventory.rest.BaseWebInventoryTest.java

protected void checkInventory(RestUri product, RestUri facility, int quantity) {
    String restUri = facility + "/inventoryItems?productId=" + getProductIdFromUri(product.getUri());
    ParameterizedTypeReference<Resources<InventoryItem>> responseType = new ParameterizedTypeReference<Resources<InventoryItem>>() {
    };// w  w w  .j ava 2  s. com
    Resources<InventoryItem> inventories = restTemplate.exchange(restUri, HttpMethod.GET, null, responseType)
            .getBody();
    InventoryItem inventory = inventories.getContent().iterator().next();
    assertNotNull("environment", inventory);
    //        assertNotNull("Inventory facility", environment.getFacility());
    //        assertNotNull("Inventory productInstance", environment.getProductInstance());
    assertEquals("Inventory quantity", quantity, inventory.getQuantityOnHand().intValue());
}

From source file:org.n52.restfulwpsproxy.wps.ProcessesClient.java

public ProcessOfferingsDocument getProcessDescription(String processId) {
    HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers);
    return restTemplate.exchange(new RequestUrlBuilder(DESCRIBE_PROCESS).identifier(processId).build(),
            HttpMethod.GET, requestEntity, ProcessOfferingsDocument.class).getBody();
}

From source file:org.zalando.github.spring.UsersTemplateTest.java

@Test
public void getEmails() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/user/emails")).andExpect(method(HttpMethod.GET))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withSuccess(new ClassPathResource("listEmails.json", getClass()),
                    MediaType.APPLICATION_JSON));

    List<Email> emailList = usersTemplate.listEmails();

    Assertions.assertThat(emailList).isNotNull();
    Assertions.assertThat(emailList.size()).isEqualTo(1);
}

From source file:org.n52.restfulwpsproxy.wps.CapabilitiesClient.java

public CapabilitiesDocument get() {
    HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers);

    ResponseEntity<CapabilitiesDocument> capabilities = restTemplate.exchange(
            new RequestUrlBuilder(REQUEST_GET_CAPABILITIES).build(), HttpMethod.GET, requestEntity,
            CapabilitiesDocument.class);

    return capabilities.getBody();
}