Example usage for org.springframework.http HttpHeaders HttpHeaders

List of usage examples for org.springframework.http HttpHeaders HttpHeaders

Introduction

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

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

From source file:com.codekul.simpleboot.controller.ControllerRestServices.java

@RequestMapping(value = "/login", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> loginUser(@RequestBody User user) {

    ResponseEntity<Map<String, Object>> entity = null;
    Map<String, Object> mapBody = new HashMap<>();
    HttpHeaders headers = new HttpHeaders();

    try {/* www .  j  ava2  s .  c o m*/

        serviceUser.login(user);

        mapBody.clear();
        mapBody.put("status", "success");
        mapBody.put("msg", "Logged Successfully ..");

        entity = new ResponseEntity<>(mapBody, headers, HttpStatus.OK);

    } catch (Exception ex) {
        Logger.getLogger(ControllerRestServices.class.getName()).log(Level.SEVERE, null, ex);

        mapBody.clear();
        mapBody.put("status", "fail");
        mapBody.put("msg", "Bad Crediantials ...");

        entity = new ResponseEntity<>(mapBody, headers, HttpStatus.BAD_REQUEST);
    }

    return entity;
}

From source file:edu.infsci2560.AboutIT.java

@Test
public void testAboutPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = this.restTemplate.exchange("/about.html", HttpMethod.GET,
            new HttpEntity<>(headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}

From source file:com.biz.report.controller.ReportController.java

@ResponseBody
@RequestMapping(value = "report/{year}/get", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<ReportDataSet> readFTypes(@PathVariable("year") String year, @RequestBody Map data) {
    logger.info(year);//from  ww  w. j a v  a2  s  .com
    logger.info(data);
    Assert.notNull(data, "Data is null.");
    Assert.notNull(year, "Year is null.");
    String types = data.get("types").toString();
    String months = data.get("months").toString();
    ReportDataSet reportDataSet = reportService.getReports(types, months, year);
    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<ReportDataSet>(reportDataSet, headers, HttpStatus.OK);
}

From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java

public String getOAuthAccessToken(String username, String password, String grantType, String scope) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", getBasicAuthHeaderValue(username, password));

    MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
    postParameters.add("grant_type", grantType);
    postParameters.add("client_id", username);
    postParameters.add("scope", scope);

    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            postParameters, headers);// w  ww.ja  va 2 s  .  c  om

    ResponseEntity<Map> exchange = restTemplate.exchange(baseUrl + "/oauth/token", HttpMethod.POST,
            requestEntity, Map.class);

    return exchange.getBody().get("access_token").toString();
}

From source file:com.borabora.ui.secure.SampleSecureApplicationTests.java

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

From source file:edu.infsci2560.services.LocationsService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Location> create(@RequestBody Location locations) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(locations), headers, HttpStatus.OK);
}

From source file:edu.infsci2560.LoginIT.java

@Test
public void testLoginPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET,
            new HttpEntity<>(headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("_csrf");
}

From source file:com.cisco.cta.taxii.adapter.RequestFactoryTest.java

@Before
public void setUp() throws Exception {
    pollEndpoint = new URL("http://somehost/service");
    headers = new HttpHeaders();
    headersAppender = new HttpHeadersAppender();
    initMocks();/* w ww.j  ava  2s .  c  o  m*/
    requestFactory = new RequestFactory(pollEndpoint, httpRequestFactory, headersAppender, bodyWriter);
    feed = new TaxiiStatus.Feed();
    feed.setName("my-collection");
}

From source file:controllers.ImageController.java

@RequestMapping("/")
public ResponseEntity<byte[]> getImage(@RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "id", required = false) String id) throws IOException {
    File file = new File("/usr/local/seller/preview/" + id + "/" + name);
    if (!file.exists()) {
        return null;
    }//from w ww .j a v  a2s  . com
    InputStream in = new FileInputStream(file);
    //new File("/usr/local/seller/preview/"+id+"/"+name).;
    //servletContext.getResourceAsStream("/usr/local/seller/preview/"+id+"/"+name);

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
}

From source file:org.intermine.app.net.request.BaseRequest.java

public HttpHeaders getHeaders() {
    HttpHeaders headers = new HttpHeaders();

    headers.setAcceptEncoding(new ContentCodingType(CONTENT_ENCODING));
    headers.setContentEncoding(new ContentCodingType(CONTENT_ENCODING));
    return headers;
}