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:br.edu.unifesspa.lcc.indexer.teste.java

public static void main(String[] args) {
    int assunto = 215;
    RestTemplate rt = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer d724997c-ba1d-42aa-8ed3-40a8a590558e");
    HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
    try {//from  ww w.j  a  va  2s  .  c om
        System.out.println("Comeando a inserir os Inputs do assunto: " + assunto);
        ResponseEntity<domain.Input_presenteDTO[]> input = rt.exchange(
                "http://xingu.lcc.unifesspa.edu.br:8080/api/input_presentes/getInputPresenteByAssantoId/"
                        + assunto,
                HttpMethod.GET, entity, Input_presenteDTO[].class);
        System.out.println("Fez o download do assunto: " + assunto);
        System.out.println("Tamano input: " + input.getBody().length + "  Assunto: " + assunto);
    } catch (Exception e) {

    }
}

From source file:com.apress.prospringintegration.web.MultipartHttpClient.java

public static void main(String[] args) {
    RestTemplate template = new RestTemplate();
    String uri = "http://localhost:8080/http-adapter-1.0.0/inboundMultipartAdapter.html";
    Resource picture = new ClassPathResource("com/apress/prospringintegration/web/test.png");
    MultiValueMap map = new LinkedMultiValueMap();
    map.add("name", "John Smith");
    map.add("picture", picture);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity request = new HttpEntity(map, headers);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, null);
    System.out.println("Status: " + httpResponse.getStatusCode().name());
}

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.App.java

public static int main(String[] args) {

    infoLogger.info("\n\nREST Sample Client\n\n");

    HttpHeaders httpHeaders = new HttpHeaders();
    String auth = REST_USERNAME + ":" + REST_PASSWORD;
    byte[] encodedAuthorisation = Base64.encode(auth.getBytes());
    httpHeaders.add("Authorization", "Basic " + new String(encodedAuthorisation));

    CustomerRestController.setHttpHeaders(httpHeaders);
    MachineRestController.setHttpHeaders(httpHeaders);

    try {//from  ww w .ja  va  2 s  . c o  m
        switch (System.getProperty(ACTION, "")) {
        case "list":
            listEntities();
            break;
        case "details":
            getDetails();
            break;
        case "create":
            createEntity();
            break;
        case "edit":
            editEntity();
            break;
        case "delete":
            deleteEntity();
            break;
        default:
            infoLogger.info("Please, see the usage guide for this client in the README file.");
        }
    } catch (Exception e) {
        errorLogger.error("Houston, we have a problem.", e);
        infoLogger.info("\n\n");
        infoLogger.info("Ooops.");
        return 1;
    }

    infoLogger.info("\n\n");
    infoLogger.info("The operation was successful.");
    return 0;
}

From source file:web.rufer.swisscom.sms.api.factory.HeaderFactory.java

public static HttpHeaders createHeaders(String apiKey) {
    HttpHeaders headers = new HttpHeaders();
    headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
    headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
    headers.set(CLIENT_ID, apiKey);/* w w w.  j  a  va2s .c  om*/
    return headers;
}

From source file:org.lightadmin.core.web.util.ResponseUtils.java

public static HttpHeaders octetStreamResponseHeader(MediaType mediaType, long length, String eTag) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentLength(length);
    responseHeaders.setContentType(mediaType);
    responseHeaders.setCacheControl("max-age");
    if (isNotBlank(eTag)) {
        responseHeaders.setETag(eTag);// w  w  w  . j  a va 2s  .c  o  m
    }
    responseHeaders.set("Content-Disposition", "inline; filename=\"file.jpg\"");
    return responseHeaders;
}

From source file:com.javafxpert.wikibrowser.util.WikiBrowserUtils.java

/**
 * TODO: Move this to a util class/*from   w w  w  .ja  v  a  2 s .  c  om*/
 * @param username
 * @param password
 * @return
 */
public static HttpHeaders createHeaders(final String username, final String password) {
    HttpHeaders headers = new HttpHeaders() {
        {
            String auth = username + ":" + password;
            byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
            String authHeader = "Basic " + new String(encodedAuth);
            set("Authorization", authHeader);
        }
    };
    headers.add("Content-Type", "application/xml");
    headers.add("Accept", "application/xml");

    return headers;
}

From source file:com.carlomicieli.jtrains.infrastructure.web.Responses.java

public static <E extends Exception> ResponseEntity<VndErrors> error(E error, HttpStatus httpStatus,
        String logref) {//from   ww  w. j  a v a2s.  c  o  m
    final HttpHeaders httpHeaders = new HttpHeaders();
    return new ResponseEntity<>(new VndErrors(logref, error.getMessage()), httpHeaders, httpStatus);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunication.java

public static HttpEntity<String> postRequest(String body) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", JSON_ACCEPT_HEADER_VALUE);
    headers.add(CONTENT_TYPE_HEADER_NAME, "application/x-www-form-urlencoded");

    return new HttpEntity<>(body, headers);
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String publishOntology(String fileClassPath, String format, String dataset) {

    RestTemplate restTemplate = new RestTemplate();
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    final String uri = "http://localhost:8090/api/v1/ontology/publish";
    //final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/publish";

    map.add("file", new ClassPathResource(fileClassPath));
    map.add("format", format);
    map.add("dataset", dataset);
    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
            map, headers);//from ww w .j a  v  a  2 s  .  c  o m

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;

}

From source file:com.hatta.consumer.App.java

private static HttpHeaders getHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    return headers;
}