Example usage for org.springframework.http HttpHeaders add

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

Introduction

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

Prototype

@Override
public void add(String headerName, @Nullable String headerValue) 

Source Link

Document

Add the given, single header value under the given name.

Usage

From source file:com.sonymobile.backlogtool.JSONController.java

@RequestMapping(value = "/readepic-story/{areaName}", method = RequestMethod.GET)
@Transactional/*from   www .  java 2  s  .c  o m*/
public @ResponseBody ResponseEntity<String> printJsonEpics(@PathVariable String areaName,
        @RequestParam String order) throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "text/html; charset=utf-8");
    List<Epic> epics = null;

    Session session = sessionFactory.openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();

        if (order.equals("prio")) {
            String queryString1 = "from Epic where area.name like ? and archived=false order by prio";
            Query query1 = session.createQuery(queryString1);
            query1.setParameter(0, areaName);

            String queryString2 = "from Epic where area.name like ? and archived=true order by dateArchived desc";
            Query query2 = session.createQuery(queryString2);
            query2.setParameter(0, areaName);

            epics = Util.castList(Epic.class, query1.list());
            epics.addAll(Util.castList(Epic.class, query2.list()));
        } else {

            String queryString = "from Epic where area.name like ? order by " + order;
            Query query = session.createQuery(queryString);
            query.setParameter(0, areaName);
            epics = Util.castList(Epic.class, query.list());
        }

        for (Epic epic : epics) {
            Hibernate.initialize(epic.getChildren());
        }

        mapper.getSerializationConfig().addMixInAnnotations(Story.class, ChildrenExcluder.class);
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return new ResponseEntity<String>(mapper.writeValueAsString(epics), responseHeaders, HttpStatus.CREATED);

}

From source file:com.sonymobile.backlogtool.JSONController.java

@RequestMapping(value = "/readtheme-epic/{areaName}", method = RequestMethod.GET)
@Transactional/*from  ww  w. ja  va 2  s  .c o m*/
public @ResponseBody ResponseEntity<String> printJsonThemes(@PathVariable String areaName,
        @RequestParam String order) throws JsonGenerationException, JsonMappingException, IOException {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "text/html; charset=utf-8");
    List<Theme> themes = null;
    ObjectMapper mapper = new ObjectMapper();

    Session session = sessionFactory.openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();

        if (order.equals("prio")) {
            String queryString1 = "from Theme where area.name like ? and archived=false order by prio";
            Query query1 = session.createQuery(queryString1);
            query1.setParameter(0, areaName);

            String queryString2 = "from Theme where area.name like ? and archived=true order by dateArchived desc";
            Query query2 = session.createQuery(queryString2);
            query2.setParameter(0, areaName);

            themes = Util.castList(Theme.class, query1.list());
            themes.addAll(Util.castList(Theme.class, query2.list()));
        } else {
            String queryString = "from Theme where area.name like ? order by " + order;
            Query query = session.createQuery(queryString);
            query.setParameter(0, areaName);
            themes = Util.castList(Theme.class, query.list());
        }

        for (Theme theme : themes) {
            Hibernate.initialize(theme.getChildren());
        }
        mapper.getSerializationConfig().addMixInAnnotations(Epic.class, ChildrenExcluder.class);
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return new ResponseEntity<String>(mapper.writeValueAsString(themes), responseHeaders, HttpStatus.CREATED);
}

From source file:com.vmware.bdd.cli.rest.RestClient.java

private HttpHeaders buildHeaders(boolean withCookie) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> acceptedTypes = new ArrayList<MediaType>();
    acceptedTypes.add(MediaType.APPLICATION_JSON);
    acceptedTypes.add(MediaType.TEXT_HTML);
    headers.setAccept(acceptedTypes);/*from  w  w  w  .  j a  va 2s  .  com*/

    if (withCookie) {
        String cookieInfo = readCookieInfo();
        headers.add("Cookie", cookieInfo == null ? "" : cookieInfo);
    }
    return headers;
}

From source file:de.appsolve.padelcampus.external.cloudflare.CloudFlareApiRequestInterceptor.java

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Auth-Key", cloudFlareApiKey);
    headers.add("X-Auth-Email", cloudFlareApiEmail);
    headers.add("Content-Type", ContentType.APPLICATION_JSON.toString());
    return execution.execute(request, body);
}

From source file:de.codecentric.boot.admin.server.web.client.InstanceWebClientTest.java

private HttpHeaders createHeaders(String k, String v) {
    HttpHeaders headers = new HttpHeaders();
    headers.add(k, v);
    return headers;
}

From source file:de.hybris.eventtracking.ws.controllers.rest.EventsController.java

protected HttpHeaders withCorsHeaders(final HttpHeaders headers) {
    headers.add(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER,
            Config.getString(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER_VALUE_CONF_PROPERTY,
                    ACCESS_CONTROL_ALLOW_ORIGIN_HEADER_DEFAULT_VALUE));
    return headers;
}

From source file:de.tobiasbruns.content.storage.ContentController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(code = HttpStatus.CREATED)
public HttpEntity<?> createJsonContent(HttpServletRequest req,
        @RequestBody Content<Map<String, Object>> content, UriComponentsBuilder uriBuilder) {
    setContentTypeIfEmpty(content, "application/json");
    String newPath = service.createContent(getPath(req), content);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Location", uriBuilder.path(newPath).toUriString());
    return new HttpEntity<>(headers);
}

From source file:de.tobiasbruns.content.storage.ContentController.java

@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data")
@ResponseStatus(code = HttpStatus.CREATED)
public HttpEntity<?> createBinaryContent(HttpServletRequest req, @RequestParam("file") MultipartFile file,
        UriComponentsBuilder uriBuilder) {
    String path = service.createContent(getPath(req), buildContent(file));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Location", uriBuilder.path(path).toUriString());
    return new HttpEntity<>(headers);
}

From source file:eionet.webq.service.CDREnvelopeServiceImpl.java

@Override
public HttpHeaders getAuthorizationHeader(UserFile file) {
    HttpHeaders authorization = new HttpHeaders();
    if (file.isAuthorized()) {
        String authorizationInfo = file.getAuthorization();
        if (StringUtils.isNotEmpty(authorizationInfo)) {
            authorization.add("Authorization", authorizationInfo);
            LOGGER.info("Use basic auth for file: " + file.getId());
        }/*from   w w w  .  j ava2s .  co m*/
        String cookiesInfo = file.getCookies();
        if (StringUtils.isNotEmpty(cookiesInfo)) {
            Cookie[] cookies = cookiesConverter.convertStringToCookies(cookiesInfo);
            for (Cookie cookie : cookies) {
                authorization.add("Cookie", cookie.getName() + "=" + cookie.getValue());
                LOGGER.info("User cookie auth for file: " + file.getId());
            }
        }
    }
    return authorization;
}

From source file:eionet.webq.web.controller.WebQProxyDelegation.java

/**
 * Create HttpHeader with basic authentication info.
 *
 * @param knownHost KnownHost object//  w ww .  j av  a  2s  .co  m
 * @return HttpHeader with authorization attribute
 */

private HttpHeaders getHttpHeaderWithBasicAuthentication(KnownHost knownHost) {
    HttpHeaders authorization = new HttpHeaders();
    try {
        authorization
                .add("Authorization",
                        "Basic " + Base64
                                .encodeBase64String(
                                        (knownHost.getKey() + ":" + knownHost.getTicket()).getBytes("utf-8"))
                                .trim());
    } catch (UnsupportedEncodingException e) {
        LOGGER.warn("UnsupportedEncodingException: utf-8");
    }
    return authorization;
}