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.janrain.backplane.server.metrics.MetricsController.java

@RequestMapping(value = "/dump", method = RequestMethod.POST)
public ResponseEntity<String> dump(@RequestBody MetricRequest metricRequest)
        throws SimpleDBException, BackplaneServerException, AuthException {

    bpConfig.checkMetricAuth(metricRequest.getUser(), metricRequest.getSecret());

    try {//  ww w .  j  a  v  a2s.com
        return new ResponseEntity<String>(retrieveAllMetrics(), new HttpHeaders() {
            {
                add("Content-Type", "application/json");
            }
        }, HttpStatus.OK);
    } catch (Exception e) {
        logger.error(e);
        throw new BackplaneServerException(e.getMessage());
    }
}

From source file:io.pivotalservices.wiretaprouteservice.CatchAllController.java

private static RequestEntity<?> getOutgoingRequest(RequestEntity<?> incoming) {
    HttpHeaders headers = new HttpHeaders();
    headers.putAll(incoming.getHeaders());
    URI uri = headers.remove(FORWARDED_URL).stream().findFirst().map(URI::create)
            .orElseThrow(() -> new IllegalStateException(String.format("No %s header present", FORWARDED_URL)));
    return new RequestEntity<>(incoming.getBody(), headers, incoming.getMethod(), uri);
}

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

@Before
public void init() {
    ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource();
    params = new LinkedMultiValueMap<String, String>();
    params.set("client_id", resource.getClientId());
    params.set("redirect_uri", resource.getRedirectUri(new DefaultAccessTokenRequest()));
    params.set("response_type", "token");
    headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
}

From source file:com.counter.counter.api.MainController.java

@RequestMapping(value = "/search", method = { RequestMethod.POST })
public ResponseEntity<String> searchText(@RequestParam List<String> searchText)
        throws JsonProcessingException, JSONException {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("Content-Type", "application/json;charset=utf-8");

    String rVal = "";
    //System.out.println("searchText-> " + searchText.size());
    List<String> tempList = new ArrayList();
    Map<String, Integer> map;
    JSONObject jsonMap = new JSONObject();
    for (String st : searchText) {
        Integer occurence = 0;/*from  w  w w.  jav a2 s.c  o m*/
        map = new HashMap();
        for (int i = sourceText.indexOf(st); i >= 0; i = sourceText.indexOf(st, i + 1))
            occurence++;
        map.put(st, occurence);
        jsonMap.put(st, occurence);
        String json = new ObjectMapper().writeValueAsString(map);
        System.out.println(json);
        tempList.add(json);
    }

    StringBuilder sb = new StringBuilder();
    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonMap);

    System.out.println(jsonArray.toString());
    for (String s : tempList) {
        sb.append(s);
        sb.append(",");
    }
    sb.deleteCharAt(sb.lastIndexOf(","));

    //String json = new ObjectMapper().writeValueAsString(map);
    //System.out.println(json);
    return new ResponseEntity<>("[" + sb.toString() + "]", httpHeaders, HttpStatus.OK);
}

From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationTests.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>Hello"));
}

From source file:com.moxian.ng.api.user.SignupController.java

@RequestMapping(value = { "/signup" }, method = RequestMethod.POST)
@ResponseBody/*from  ww w .j av  a  2  s.  com*/
public ResponseEntity<Void> signup(@RequestBody @Valid SignupForm form, BindingResult errors,
        HttpServletRequest req) {
    if (log.isDebugEnabled()) {
        log.debug("signup data@" + form);
    }

    if (errors.hasErrors()) {
        throw new InvalidRequestException(errors);
    }

    UserDetails saved = userService.registerUser(form);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ServletUriComponentsBuilder.fromContextPath(req)
            .path(Constants.URI_API_PUBLIC + Constants.URI_USERS + "/{id}").buildAndExpand(saved.getId())
            .toUri());

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

From source file:fi.hsl.parkandride.front.FacilityController.java

@RequestMapping(method = POST, value = FACILITIES, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Facility> createFacility(@RequestBody Facility facility, User currentUser,
        UriComponentsBuilder builder) {//  ww w.  ja va 2 s  . co  m
    log.info("createFacility");
    Facility newFacility = facilityService.createFacility(facility, currentUser);
    log.info("createFacility({})", newFacility.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(FACILITY).buildAndExpand(newFacility.id).toUri());
    return new ResponseEntity<>(newFacility, headers, CREATED);
}

From source file:net.orpiske.tcs.service.rest.controller.DomainCommandsController.java

@RequestMapping(value = "/{domain}", method = RequestMethod.POST)
@ResponseBody//  w  w  w .j ava  2 s.  c om
public ResponseEntity<Domain> createCspTagCloud(@RequestBody final Domain domain,
        UriComponentsBuilder builder) {

    if (logger.isDebugEnabled()) {
        logger.debug("CSP command controller handling a create CSP request for " + domain);
    }

    DomainCreateEvent tagCloudEvent = tagCloudService.createDomain(new RequestCreateDomainEvent(domain));

    Domain domainObj = tagCloudEvent.getDomain();

    HttpHeaders httpHeaders = new HttpHeaders();

    httpHeaders.setLocation(builder.path("/domain/{domain}").buildAndExpand(domainObj.getDomain()).toUri());

    return new ResponseEntity<Domain>(domainObj, httpHeaders, HttpStatus.OK);
}

From source file:com.xyxy.platform.examples.showcase.demos.hystrix.web.HystrixExceptionHandler.java

/**
 * ?Hystrix Runtime, :/*w  w  w.  ja v  a2  s.co  m*/
 * Command(500).
 * Hystrix??(503).
 */
@ExceptionHandler(value = { HystrixRuntimeException.class })
public final ResponseEntity<?> handleException(HystrixRuntimeException e, WebRequest request) {
    HttpStatus status = HttpStatus.SERVICE_UNAVAILABLE;
    String message = e.getMessage();

    FailureType type = e.getFailureType();

    // ?
    if (type.equals(FailureType.COMMAND_EXCEPTION)) {
        status = HttpStatus.INTERNAL_SERVER_ERROR;
        message = Exceptions.getErrorMessageWithNestedException(e);
    }

    logger.error(message, e);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8));
    return handleExceptionInternal(e, message, headers, status, request);
}

From source file:io.sevenluck.chat.controller.ChatChannelController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity<?> handleException(EntityNotFoundException e) {
    logger.error("validate:", e.getMessage());
    return new ResponseEntity<>(ExceptionDTO.newNotFoundInstance(e.getMessage()), new HttpHeaders(),
            HttpStatus.NOT_FOUND);//from   w w  w.jav  a 2s.  c  o  m
}