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:edu.wisc.cypress.dao.benstmt.RestBenefitStatementDao.java

@Cacheable(cacheName = "benefitStatement", exceptionCacheName = "cypressUnknownExceptionCache")
@Override/*from  ww  w. j a va2s. c om*/
public BenefitStatements getBenefitStatements(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);

    final XmlBenefitStatements xmlBenefitStatements = this.restOperations.getForObject(this.statementsUrl,
            XmlBenefitStatements.class, httpHeaders, emplid);

    return this.mapBenefitStatements(xmlBenefitStatements);
}

From source file:com.nebhale.letsmakeadeal.web.GamesController.java

@RequestMapping(method = RequestMethod.POST, value = "")
ResponseEntity<Void> createGame() {
    Game game = this.gameRepository.create();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri());

    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:org.cloudfoundry.identity.api.web.CloudfoundryApiIntegrationTests.java

@Test
public void testClientAccessesProtectedResource() throws Exception {
    OAuth2AccessToken accessToken = context.getAccessToken();
    // add an approval for the scope requested
    HttpHeaders approvalHeaders = new HttpHeaders();
    approvalHeaders.set("Authorization", "bearer " + accessToken.getValue());
    Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000);
    Date expiresAt = new Date(System.currentTimeMillis() + 60000);
    ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT,
            new HttpEntity<Approval[]>((new Approval[] {
                    new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "openid", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo) }),
                    approvalHeaders),//from  www  .j  a  va 2 s .c o  m
            Approval[].class);
    assertEquals(HttpStatus.OK, approvals.getStatusCode());

    // System.err.println(accessToken);
    // The client doesn't know how to use an OAuth bearer token
    CloudFoundryClient client = new CloudFoundryClient("Bearer " + accessToken.getValue(),
            testAccounts.getCloudControllerUrl());
    CloudInfo info = client.getCloudInfo();
    assertNotNull("Wrong cloud info: " + info.getDescription(), info.getUser());
}

From source file:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t03_exists() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.GET, null,
            String.class);

    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
}

From source file:com.compomics.colims.core.service.impl.UniProtServiceImpl.java

@Override
public Map<String, String> getUniProtByAccession(String accession) throws RestClientException, IOException {
    Map<String, String> uniProt = new HashMap<>();

    try {/*from  w  w  w. j a  v a2 s.  c o m*/
        // Set XML content type explicitly to force response in XML (If not spring gets response in JSON)
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
        HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

        ResponseEntity<String> response = restTemplate.exchange(UNIPROT_BASE_URL + "/" + accession + ".xml",
                HttpMethod.GET, entity, String.class);
        String responseBody = response.getBody();

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(responseBody));

        Document document = (Document) builder.parse(is);
        document.getDocumentElement().normalize();
        NodeList recommendedName = document.getElementsByTagName("recommendedName");

        Node node = recommendedName.item(0);
        Element element = (Element) node;
        if (element.getElementsByTagName("fullName").item(0).getTextContent() != null
                && !element.getElementsByTagName("fullName").item(0).getTextContent().equals("")) {
            uniProt.put("description", element.getElementsByTagName("fullName").item(0).getTextContent());
        }

        NodeList organism = document.getElementsByTagName("organism");
        node = organism.item(0);
        element = (Element) node;
        if (element.getElementsByTagName("name").item(0).getTextContent() != null
                && !element.getElementsByTagName("name").item(0).getTextContent().equals("")) {
            uniProt.put("species", element.getElementsByTagName("name").item(0).getTextContent());
        }

        NodeList dbReference = document.getElementsByTagName("dbReference");
        node = dbReference.item(0);
        element = (Element) node;
        if (element.getAttribute("id") != null && !element.getAttribute("id").equals("")) {
            uniProt.put("taxid", element.getAttribute("id"));
        }

    } catch (HttpClientErrorException ex) {
        LOGGER.error(ex.getMessage(), ex);
        //ignore the exception if the namespace doesn't correspond to an ontology
        if (!ex.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw ex;
        }
    } catch (ParserConfigurationException | SAXException ex) {
        java.util.logging.Logger.getLogger(UniProtServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return uniProt;
}

From source file:com.weibo.http.client.WeiboHttpClient.java

/**
 * post/* ww w.ja va 2 s. c  o  m*/
 * @param url
 * @param request
 * @param responseType
 * @param mediaType
 * @return
 */
public <T> T post(String url, Object request, Class<T> responseType, MediaType mediaType) {
    T result = null;
    try {
        log.info("post : " + url + "?" + request.toString());
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(mediaType);
        HttpEntity<? extends Object> httpEntity = new HttpEntity<Object>(request, headers);
        result = weiboRestTemplate.postForObject(url, httpEntity, responseType);
        log.info("result : " + result.toString());
    } catch (HttpStatusCodeException e) {
        ErrorCode errorCode = errorCodeHandler.handle(e);
        log.info("error : " + errorCode.toString());
    }
    return result;
}

From source file:org.ng200.openolympus.controller.api.TaskDescriptionSourcecodeController.java

@RequestMapping(value = "/api/taskSourcecode", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<String> getTaskSourcecode(@RequestParam(value = "id") final Task task)
        throws IOException {
    Assertions.resourceExists(task);//  w ww.  j av a 2 s . c  om
    final String descriptionPath = MessageFormat.format(TaskUploader.TASK_DESCRIPTION_PATH_TEMPLATE,
            StorageSpace.STORAGE_PREFIX, task.getTaskLocation());
    final File descriptionFile = new File(descriptionPath);
    HttpHeaders responseHeaders = new HttpHeaders();
    Charset charset = Charset.forName("UTF-8");
    responseHeaders.setContentType(new MediaType("text", "plain", charset));
    return new ResponseEntity<String>(new String(FileAccess.readAllBytes(descriptionFile), charset),
            responseHeaders, HttpStatus.OK);
}

From source file:com.t163.http.client.T163HttpClient.java

/**
 * post//from   w w  w  . j  a va 2s  .  c o  m
 * @param url
 * @param request
 * @param responseType
 * @param mediaType
 * @return
 */
public <T> T post(String url, Object request, Class<T> responseType, MediaType mediaType) {
    T result = null;
    try {
        log.info("post : " + url + "?" + request.toString());
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(mediaType);
        HttpEntity<? extends Object> httpEntity = new HttpEntity<Object>(request, headers);
        result = t163RestTemplate.postForObject(url, httpEntity, responseType);
        log.info("result : " + result.toString());
    } catch (HttpStatusCodeException e) {
        T163ErrorCode t163ErrorCode = t163ErrorCodeHandler.handle(e);
        log.info("error : " + t163ErrorCode.toString());
    }
    return result;
}

From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java

/**
 * tests a happy-day flow of the Resource Owner Password Credentials grant type. (formerly native application
 * profile)./* w w w  .j a  va 2  s. co m*/
 */
@Test
public void testHappyDay() throws Exception {

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "password");
    formData.add("username", resource.getUsername());
    formData.add("password", resource.getPassword());
    formData.add("scope", "cloud_controller.read");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization",
            testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret()));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> response = serverRunning.postForString("/oauth/token", formData, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("no-store", response.getHeaders().getFirst("Cache-Control"));
}

From source file:com.example.notes.TagsController.java

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody TagInput tagInput) {
    Tag tag = new Tag();
    tag.setName(tagInput.getName());/*from   w w  w.ja  va2s.  c  o  m*/

    this.repository.save(tag);

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri());

    return httpHeaders;
}