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:net.oneandone.stool.overview.ProcessesController.java

@RequestMapping(value = "{id}/log", method = RequestMethod.GET)
@ResponseBody//from www  .j a  va2s.  c  o m
public ResponseEntity log(@PathVariable(value = "id") String id,
        @RequestParam(defaultValue = "0") Integer index) throws IOException, InterruptedException {
    Node logfile;
    StringBuilder output;
    MultiValueMap<String, String> headers;
    output = new StringBuilder();
    List<String> strings;
    ListIterator<String> iterator;

    headers = new HttpHeaders();

    try {
        logfile = logFile(id);
    } catch (ResourceNotFoundException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    strings = logfile.readLines();
    iterator = strings.listIterator(index);
    while (iterator.hasNext()) {
        output.append(iterator.next()).append("<br />");
    }
    headers.set("X-index", "" + strings.size());
    return new ResponseEntity<>(output.toString(), headers, HttpStatus.OK);
}

From source file:com.mentat.rest.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<>(headers, HttpStatus.CREATED);
}

From source file:org.openlmis.notification.web.BaseWebIntegrationTest.java

private String fetchToken() {
    RestTemplate restTemplate = new RestTemplate();

    String plainCreds = clientId + ":" + clientSecret;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<>(headers);

    Map<String, Object> params = new HashMap<>();
    params.put("grant_type", "password");

    ResponseEntity<?> response = restTemplate.exchange(buildUri(authorizationUrl, params), HttpMethod.POST,
            request, Object.class);

    return ((Map<String, String>) response.getBody()).get("access_token");
}

From source file:com.jvoid.core.controller.HomeController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody String loginToJvoid(
        @RequestParam(required = false, value = "params") JSONObject jsonParams) {
    System.out.println("Login:jsonParams=>" + jsonParams.toString());

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(ServerUris.CUSTOMER_SERVER_URI + URIConstants.GET_CUSTOMER_BY_EMAIL)
            .queryParam("params", jsonParams);
    HttpEntity<?> entity = new HttpEntity<>(headers);
    HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity,
            String.class);
    return returnString.getBody();
}

From source file:org.apigw.util.OAuthTestHelper.java

public String getAuthorizationCode(String clientId, String redirectUri, String scope) {
    String cookie = loginAndGetConfirmationPage(clientId, redirectUri, scope);
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.set("Cookie", cookie);
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("user_oauth_approval", "true");
    ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers,
            formData);/*  ww  w.  java  2s  . co  m*/
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    // Get the authorization code using the same session
    return getAuthorizationCode(result);
}

From source file:miage.ecom.web.admin.controller.ProductImage.java

@RequestMapping(value = "/product/{id}/image", method = RequestMethod.POST)
public ResponseEntity<String> create(@PathVariable("id") int productId,
        @RequestParam("image") MultipartFile image) {

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-type", "text/html");

    String success = null;//  w  w w .ja va2  s.  co m
    String msg = null;
    String imageUrl = "";

    Product product = productFacade.find(productId);

    if (product == null) {
        success = "false";
        msg = "Ce produit n'existe pas / plus";
    }

    if (image.isEmpty()) {
        success = "false";
        msg = "Impossible de sauvegarder l'image";
    }

    if (!image.getContentType().contains("image")) {
        success = "false";
        msg = "Format de fichier non valide";
    }

    if (success == null) {
        try {
            URL thumbUrl = imageManager.uploadThumb(image.getInputStream(), 200);

            if (thumbUrl != null) {

                imageUrl = thumbUrl.toString();
                product.setImage(imageUrl);

                productFacade.edit(product);

                success = "true";

            } else {
                success = "false";
                msg = "Impossible de gnrer l'image";
            }
        } catch (Exception ex) {
            success = "false";
            msg = "Impossible de gnrer l'image : " + ex.getMessage();
        }
    }

    return new ResponseEntity<String>(
            "{success:" + success + ",msg:\"" + msg + "\",image:\"" + imageUrl + "\"}", responseHeaders,
            HttpStatus.OK);
}

From source file:com.bennavetta.appsite.webapi.SettingsController.java

@RequestMapping(method = POST, value = "/{name}")
public ResponseEntity<String> putSetting(@PathVariable String name, @RequestBody String value) {
    settings.set(name, value);// w  w  w. j  a  v a 2s  . c om
    log.trace("Setting {} = {}", name, value);
    HttpHeaders headers = new HttpHeaders();
    URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/settings/{name}").build()
            .expand(name).toUri();
    headers.setLocation(location);
    return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}

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

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "application/json")
public ResponseEntity<Location> delete(@PathVariable("id") Long id) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.findOne(id), headers, HttpStatus.OK);
}

From source file:net.paslavsky.springrest.HttpHeadersHelper.java

public HttpHeaders getHttpHeaders(Map<String, Integer> headerParameters, Object[] arguments) {
    HttpHeaders headers = new HttpHeaders();
    for (String headerName : headerParameters.keySet()) {
        Object headerValue = arguments[headerParameters.get(headerName)];
        if (headerValue != null) {
            if (ACCEPT.equalsIgnoreCase(headerName)) {
                headers.setAccept(toList(headerValue, MediaType.class));
            } else if (ACCEPT_CHARSET.equalsIgnoreCase(headerName)) {
                headers.setAcceptCharset(toList(headerValue, Charset.class));
            } else if (ALLOW.equalsIgnoreCase(headerName)) {
                headers.setAllow(toSet(headerValue, HttpMethod.class));
            } else if (CONNECTION.equalsIgnoreCase(headerName)) {
                headers.setConnection(toList(headerValue, String.class));
            } else if (CONTENT_DISPOSITION.equalsIgnoreCase(headerName)) {
                setContentDisposition(headers, headerName, headerValue);
            } else if (CONTENT_LENGTH.equalsIgnoreCase(headerName)) {
                headers.setContentLength(toLong(headerValue));
            } else if (CONTENT_TYPE.equalsIgnoreCase(headerName)) {
                headers.setContentType(toMediaType(headerValue));
            } else if (DATE.equalsIgnoreCase(headerName)) {
                headers.setDate(toLong(headerValue));
            } else if (ETAG.equalsIgnoreCase(headerName)) {
                headers.setETag(toString(headerValue));
            } else if (EXPIRES.equalsIgnoreCase(headerName)) {
                headers.setExpires(toLong(headerValue));
            } else if (IF_MODIFIED_SINCE.equalsIgnoreCase(headerName)) {
                headers.setIfModifiedSince(toLong(headerValue));
            } else if (IF_NONE_MATCH.equalsIgnoreCase(headerName)) {
                headers.setIfNoneMatch(toList(headerValue, String.class));
            } else if (LAST_MODIFIED.equalsIgnoreCase(headerName)) {
                headers.setLastModified(toLong(headerValue));
            } else if (LOCATION.equalsIgnoreCase(headerName)) {
                headers.setLocation(toURI(headerValue));
            } else if (ORIGIN.equalsIgnoreCase(headerName)) {
                headers.setOrigin(toString(headerValue));
            } else if (PRAGMA.equalsIgnoreCase(headerName)) {
                headers.setPragma(toString(headerValue));
            } else if (UPGRADE.equalsIgnoreCase(headerName)) {
                headers.setUpgrade(toString(headerValue));
            } else if (headerValue instanceof String) {
                headers.set(headerName, (String) headerValue);
            } else if (headerValue instanceof String[]) {
                headers.put(headerName, Arrays.asList((String[]) headerValue));
            } else if (instanceOf(headerValue, String.class)) {
                headers.put(headerName, toList(headerValue, String.class));
            } else {
                headers.set(headerName, conversionService.convert(headerValue, String.class));
            }//from  w  ww  . ja  v  a 2s  .c  o m
        }
    }
    return headers;
}

From source file:com.github.ffremont.microservices.springboot.manager.nexus.NexusClientApiTest.java

@Test
public void testGetData() {
    String g = "gg", a = "aa", v = "1.0.0", c = "cc", p = "jar";

    // init mock/*w  ww.  j  a v  a2  s . c o  m*/
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.parseMediaType(MediaType.APPLICATION_JSON.toString())));
    HttpEntity<NexusDataResult> entity = new HttpEntity<>(headers);
    NexusDataResult nexusResult = new NexusDataResult();
    nexusResult.setData(new NexusData());
    ResponseEntity responseEntity = new ResponseEntity(nexusResult, HttpStatus.OK);
    when(this.nexusRestTemplate
            .exchange(prop.getBaseurl() + "/service/local/artifact/maven/resolve?r=snapshots&g=" + g + "&a=" + a
                    + "&v=" + v + "&p=" + p + "&c=" + c, HttpMethod.GET, entity, NexusDataResult.class))
                            .thenReturn(responseEntity);

    NexusData r = nexus.getData(g, a, p, c, v);

    assertNotNull(r);
}