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:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java

private HttpHeaders getAppBasicAuthHttpHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", testClient.getBasicAuthHeaderValue("app", "appclientsecret"));
    return headers;
}

From source file:eu.freme.common.rest.RestHelper.java

/**
 * Create a ResponseEntity for a REST API method. It accepts a Jena Model
 * and an RDFSerialization format. It converts the model to a string in the
 * desired serialization format and sets the right Content-Type header.
 *
 * @param rdf the jena rdf model// w w  w  . j av a 2  s.  co  m
 * @param rdfFormat the serialization output format
 * @return the created success response entity
 */
public ResponseEntity<String> createSuccessResponse(Model rdf, String rdfFormat) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", rdfFormat);
    String rdfString;
    try {
        rdfString = rdfConversionService.serializeRDF(rdf, rdfFormat);
    } catch (Exception e) {
        throw new InternalServerErrorException();
    }
    return new ResponseEntity<>(rdfString, responseHeaders, HttpStatus.OK);
}

From source file:eu.freme.common.rest.RestHelper.java

/**
 * @deprecated use {@link #createSuccessResponse(Model, String)} instead
  *//*from w w w  .  ja  v a  2  s. c om*/
@Deprecated
public ResponseEntity<String> createSuccessResponse(Model rdf, RDFConstants.RDFSerialization rdfFormat) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", rdfFormat.contentType());
    String rdfString;
    try {
        rdfString = rdfConversionService.serializeRDF(rdf, rdfFormat.contentType());
    } catch (Exception e) {
        throw new InternalServerErrorException();
    }
    return new ResponseEntity<>(rdfString, responseHeaders, HttpStatus.OK);
}

From source file:io.syndesis.runtime.action.DynamicActionDefinitionITCase.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/" + CREATE_OR_UPDATE_ACTION_ID, null,
            ActionDefinition.class, tokenRule.validToken(), headers, HttpStatus.OK);

    final ActionDefinition firstEnrichment = new ActionDefinition.Builder()//
            .inputDataShape(new DataShape.Builder().kind("json-schema").build())
            .outputDataShape(new DataShape.Builder().kind("java")
                    .type("org.apache.camel.component.salesforce.api.dto.CreateSObjectResult").build())
            .withActionDefinitionStep("Select Salesforce object", "Select Salesforce object type to create",
                    b -> b.putProperty("sObjectName", suggestedSalesforceObjectNames))
            .withActionDefinitionStep("Select Identifier property",
                    "Select Salesforce property that will hold the uniquely identifying value of this object",
                    b -> b.putProperty("sObjectIdName", _DEFAULT_SALESFORCE_IDENTIFIER))
            .build();// www . ja v a  2s  . c  o m
    assertThat(firstResponse.getBody()).isEqualTo(firstEnrichment);

    final ResponseEntity<ActionDefinition> secondResponse = http(HttpMethod.POST,
            "/api/v1/connections/" + connectionId + "/actions/" + CREATE_OR_UPDATE_ACTION_ID,
            Collections.singletonMap("sObjectName", "Contact"), ActionDefinition.class, tokenRule.validToken(),
            headers, HttpStatus.OK);

    final ActionDefinition secondEnrichment = new ActionDefinition.Builder()//
            .outputDataShape(new DataShape.Builder().kind("java")
                    .type("org.apache.camel.component.salesforce.api.dto.CreateSObjectResult").build())
            .withActionDefinitionStep("Select Salesforce object", "Select Salesforce object type to create",
                    b -> b.putProperty("sObjectName", contactSalesforceObjectName))
            .withActionDefinitionStep("Select Identifier property",
                    "Select Salesforce property that will hold the uniquely identifying value of this object",
                    b -> b.putProperty("sObjectIdName", suggestedSalesforceIdNames))
            .build();
    final ActionDefinition secondResponseBody = secondResponse.getBody();
    assertThat(secondResponseBody).isEqualToIgnoringGivenFields(secondEnrichment, "inputDataShape");
    assertThat(secondResponseBody.getInputDataShape()).hasValueSatisfying(input -> {
        assertThat(input.getKind()).isEqualTo("json-schema");
        assertThat(input.getType()).isEqualTo("Contact");
        assertThat(input.getSpecification()).isNotEmpty();
    });
}

From source file:hu.fnf.devel.wishbox.ui.MainPage.java

private Container getItemContiner() {
    IndexedContainer container = new IndexedContainer();
    container.addContainerProperty("First", String.class, "1st");
    container.addContainerProperty("Second", String.class, "2nd");
    //        WebClient client = WebClient.create("http://195.228.45.136:8181/cxf/test");
    //        client = client.accept("application/json")
    //                .type("application/json")
    //                .path("/say/list");
    //        TestResp testResp = client.get(TestResp.class);

    if (getSession().getAttribute("state") == null) {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        getSession().setAttribute("user", user);

        URI uri = null;/*  www .ja v a 2  s .c  o m*/
        try {
            uri = new URI(("http://jenna.fnf.hu/gateway/persistence/user/" + user.getUserId()));
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        String plainCreds = "API_KEY:API_PASS";

        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<String>(headers);

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, request, String.class);

        JsonFactory factory = new JsonFactory();

        ObjectMapper m = new ObjectMapper(factory);
        JsonNode rootNode = null;
        try {
            rootNode = m.readTree(response.getBody());
        } catch (IOException e) {
            e.printStackTrace();
        }

        Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
        while (fieldsIterator.hasNext()) {

            Map.Entry<String, JsonNode> field = fieldsIterator.next();
            if (!field.getKey().startsWith("_")) {
                getSession().setAttribute(field.getKey(), field.getValue().asText());
            } else {

            }
            System.out.println("Key: " + field.getKey() + ":\t" + field.getValue());
        }
        getSession().setAttribute("state", "loaded");
    }
    com.vaadin.data.Item item = container.addItem(((User) getSession().getAttribute("user")).getNickname());
    item.getItemProperty("First").setValue(getSession().getAttribute("firstName").toString());
    item.getItemProperty("Second").setValue(getSession().getAttribute("lastName").toString());

    return container;
}

From source file:github.priyatam.springrest.resource.PolicyResource.java

@RequestMapping(method = RequestMethod.HEAD, value = "/policy/{policyNum}")
@ResponseBody/*  w  w w  .  j av a  2s  .  co  m*/
public ResponseEntity<Policy> head(HttpServletRequest request, @PathVariable String policyNum) {
    logger.debug("Requested head for: " + policyNum);
    // / String url = ServletUriComponentsBuilder.fromRequest(request).build().toString();
    try {
        String tag = eTagHelper.get(vhost + URLS.POLICY.expand(policyNum));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Etag", tag);
        return new ResponseEntity<Policy>(null, headers, HttpStatus.NO_CONTENT);
    } catch (InvalidTagException e) {
        return new ResponseEntity<Policy>(HttpStatus.NOT_FOUND);
    }
}

From source file:github.priyatam.springrest.resource.PolicyResource.java

@RequestMapping(method = RequestMethod.POST, value = "/policy")
@ResponseBody/*  w ww  . j  a v  a  2s .c  o  m*/
public ResponseEntity<Policy> save(final @RequestBody Policy policy) {

    // Input Sanitization / Validations
    ErrorCode code = ruleHelper.validatePolicy(policy);
    if (code != null) {
        throw new PolicyInvalidException(code);
    }

    logger.debug("Generating a Future Url ...");
    String futureKey = resourceHelper.generateFutureKey();
    String futureLocation = resourceHelper.createFutureLocation("/policy", futureKey);

    // build header
    HttpHeaders headers = new HttpHeaders();
    headers.add("Location", futureLocation);

    // async
    policyWorker.createPolicy(futureKey, policy);

    return new ResponseEntity<Policy>(null, headers, HttpStatus.ACCEPTED);
}

From source file:eu.dime.dnsregister.controllers.RecordsController.java

@RequestMapping(headers = "Accept=application/json")
@ResponseBody//from  ww  w. j a v  a  2  s .  co m
public ResponseEntity<String> listJson() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<Records> result = Records.findAllRecordses();
    return new ResponseEntity<String>(Records.toJsonArray(result), headers, HttpStatus.OK);
}

From source file:com.cloudera.nav.sdk.client.NavApiCient.java

/**
 * Form headers for sending API calls to the Navigator server
 *
 * @return HttpHeaders headers for authorizing the plugin
 *//*  ww w.  j  av a2 s.c  om*/
private HttpHeaders getAuthHeaders() {
    // basic authentication with base64 encoding
    String plainCreds = String.format("%s:%s", config.getUsername(), config.getPassword());
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    return headers;
}

From source file:eu.dime.dnsregister.controllers.RecordsController.java

@RequestMapping(value = "/jsonArray", method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> createFromJsonArray(@RequestBody String json) {
    for (Records records : Records.fromJsonArrayToRecordses(json)) {
        records.persist();/*from w w  w .j  a va2s .com*/
    }
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}