Example usage for org.springframework.http HttpHeaders CONTENT_TYPE

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

Introduction

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

Prototype

String CONTENT_TYPE

To view the source code for org.springframework.http HttpHeaders CONTENT_TYPE.

Click Source Link

Document

The HTTP Content-Type header field name.

Usage

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);/*from w w w.  j a  v  a2s . co  m*/
    return headers;
}

From source file:com.devicehive.application.filter.ContentTypeFilter.java

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    if (!containerRequestContext.getHeaders().containsKey(HttpHeaders.CONTENT_TYPE)) {
        containerRequestContext.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    }/*from  w ww . ja v  a 2  s. c o m*/
}

From source file:com.angelmmg90.consumerservicespotify.configuration.SpringWebConfig.java

@Bean
public static RestTemplate getTemplate() throws IOException {
    if (template == null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT),
                new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD));

        Header[] h = new Header[3];
        h[0] = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");
        h[1] = new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + ACCESS_TOKEN);

        List<Header> headers = new ArrayList<>(Arrays.asList(h));

        HttpClientBuilder clientBuilder = HttpClientBuilder.create();

        clientBuilder.useSystemProperties();
        clientBuilder.setProxy(new HttpHost(PROXY_HOST, PROXY_PORT));
        clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        clientBuilder.setDefaultHeaders(headers).build();
        String SAMPLE_URL = "https://api.spotify.com/v1/users/yourUserName/playlists/7HHFd1tNiIFIwYwva5MTNv";

        HttpUriRequest request = RequestBuilder.get().setUri(SAMPLE_URL).build();

        clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());

        CloseableHttpClient client = clientBuilder.build();
        client.execute(request);/*  www  . ja  va  2  s . c o m*/

        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setHttpClient(client);

        template = new RestTemplate();
        template.setRequestFactory(factory);
    }

    return template;
}

From source file:eu.freme.eservices.publishing.ServiceRestController.java

@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST)
public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file,
        @RequestParam("metadata") String jMetadata)
        throws IOException, InvalidZipException, EPubCreationException, MissingMetadataException {
    Gson gson = new Gson();
    Metadata metadata = gson.fromJson(jMetadata, Metadata.class);
    MultiValueMap<String, String> headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "Application/epub+zip");
    String filename = file.getName();
    headers.add(HttpHeaders.CONTENT_DISPOSITION, "Attachment; filename=" + filename.split("\\.")[0] + ".epub");
    try (InputStream in = file.getInputStream()) {
        return new ResponseEntity<>(epubAPI.createEPUB(metadata, in), headers, HttpStatus.OK);
    }//from ww  w .  j  a  v a 2s. c  o m
}

From source file:eu.freme.eservices.epublishing.ServiceRestController.java

@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST)
public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file,
        @RequestParam("metadata") String jMetadata)
        throws IOException, InvalidZipException, EPubCreationException, MissingMetadataException {
    Gson gson = new Gson();
    Metadata metadata = gson.fromJson(jMetadata, Metadata.class);
    MultiValueMap<String, String> headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "Application/epub+zip");
    try (InputStream in = file.getInputStream()) {
        return new ResponseEntity<>(epubAPI.createEPUB(metadata, in), headers, HttpStatus.OK);
    }/*from   ww  w.ja  v  a  2s .c o  m*/
}

From source file:demo.service.RemoteVehicleDetailsServiceWireMockTest.java

@Test
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() throws Exception {
    this.wireMock.stubFor(get(urlEqualTo("/vehicle/" + VIN + "/details")).willReturn(
            aResponse().withStatus(200).withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                    .withBody(getClassPathResource("vehicledetails.json"))));
    VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN));
    assertThat(details.getMake()).isEqualTo("Honda");
    assertThat(details.getModel()).isEqualTo("Civic");
}

From source file:com.intuit.karate.demo.controller.UploadController.java

@GetMapping("/{id:.+}")
public ResponseEntity<Resource> download(@PathVariable String id) throws Exception {
    String filePath = FILES_BASE + id;
    File file = new File(filePath);
    File meta = new File(filePath + "_meta.txt");
    String name = FileUtils.readFileToString(meta, "utf-8");
    return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + name + "\"")
            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE)
            .body(new FileSystemResource(file));
}

From source file:io.github.restdocsext.jersey.JerseyRequestConverter.java

/**
 * Create an {@code OperationRequestPart} from a Jersey {@code FormDataBodyPart}.
 *
 * @param part the Jersey part.//from   www  . j  av  a2  s. c o m
 * @return the converted operation request part.
 */
// can't test this on it's own as the part is not a body part entity
private static OperationRequestPart createOperationRequestPart(FormDataBodyPart part) {
    final HttpHeaders partHeaders = extractHeaders(part.getHeaders());
    final List<String> contentTypeHeader = partHeaders.get(HttpHeaders.CONTENT_TYPE);
    if (part.getMediaType() != null && contentTypeHeader == null) {
        partHeaders.setContentType(
                org.springframework.http.MediaType.parseMediaType(part.getMediaType().toString()));
    }

    final String filename = StringUtils.hasText(part.getContentDisposition().getFileName())
            ? part.getContentDisposition().getFileName()
            : null;
    return new OperationRequestPartFactory().create(part.getName(), filename, part.getEntityAs(byte[].class),
            partHeaders);
}

From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebRequestMappingMetadata.java

private Optional<String> consumes() {
    String[] produces = Optional.ofNullable(mapping).map(m -> m.consumes()).filter(p -> p.length <= 1)
            .orElseThrow(() -> new IllegalArgumentException(
                    "[consumes] parameter (of @RequestMapping annotation) " + "must have only single value."));

    return (produces.length == 0) ? Optional.empty()
            : Optional.ofNullable(produces[0]).filter(p -> !p.isEmpty())
                    .map(p -> HttpHeaders.CONTENT_TYPE + "=" + p);
}

From source file:io.syndesis.runtime.action.DynamicActionSqlStoredITCase.java

@Test
public void shouldOfferDynamicActionPropertySuggestions() {

    final HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

    final ResponseEntity<ActionDefinition> firstResponse = http(HttpMethod.POST,
            "/api/v1/connections/" + connectionId + "/actions/io.syndesis:sql-stored-connector:latest", null,
            ActionDefinition.class, tokenRule.validToken(), headers, HttpStatus.OK);

    ConfigurationProperty procedureNames = firstResponse.getBody().getPropertyDefinitionSteps().iterator()
            .next().getProperties().get("procedureName");
    assertThat(procedureNames.getEnum().size() == 2);
    assertThat(procedureNames.getEnum().iterator().next().getLabel().startsWith("DEMO_ADD"));

    final ResponseEntity<ActionDefinition> secondResponse = http(HttpMethod.POST,
            "/api/v1/connections/" + connectionId + "/actions/io.syndesis:sql-stored-connector:latest",
            Collections.singletonMap("procedureName", "DEMO_ADD"), ActionDefinition.class,
            tokenRule.validToken(), headers, HttpStatus.OK);

    final Map<String, ConfigurationProperty> secondRequestProperties = secondResponse.getBody()
            .getPropertyDefinitionSteps().get(0).getProperties();
    assertThat(secondRequestProperties.get("template").getDefaultValue())
            .isEqualTo("DEMO_ADD(INTEGER ${body[A]}, INTEGER ${body[B]}, INTEGER ${body[C]})");
}