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:edu.wisc.cypress.dao.advrpt.RestAdvisorReportDao.java

@Cacheable(cacheName = "advisorReports", exceptionCacheName = "cypressUnknownExceptionCache")
@Override//from w w  w .  ja v a2 s .  c o  m
public AdvisorReports getAdvisorReports(String pvi) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("PVI", pvi);

    final XmlAdvisorReports xmlAdvisorReports = this.restOperations.getForObject(this.statementsUrl,
            XmlAdvisorReports.class, httpHeaders, pvi);

    return this.mapAdvisorReports(xmlAdvisorReports);
}

From source file:edu.wisc.cypress.dao.sabstmt.RestSabbaticalStatementDao.java

@Cacheable(cacheName = "sabbaticalReports", exceptionCacheName = "cypressUnknownExceptionCache")
@Override/*w w w  .  j  a  v  a2 s . c  o m*/
public SabbaticalReports getSabbaticalReports(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    final XmlSabbaticalReports xmlSabbaticalReports = this.restOperations.getForObject(this.statementsUrl,
            XmlSabbaticalReports.class, httpHeaders, emplid);
    return mapSabbaticalReports(xmlSabbaticalReports);
}

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

@RequestMapping(method = POST, value = USERS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<User> createUser(@RequestBody NewUser newUser, User actor, UriComponentsBuilder builder) {
    log.info("createUser({}, {}, {})", newUser.role, urlEncode(newUser.username), newUser.operatorId);
    User createdUser = userService.createUser(newUser, actor);
    log.info("createUser({})", createdUser.id);

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

From source file:com.castlemock.web.basis.web.mvc.controller.project.ExportProjectController.java

/**
 * Creates and return a view that provides the required functionality
 * to export a project./*w ww  .  j  a  va 2  s  .c  om*/
 * @param projectType The type of the project that should be exported
 * @param projectId The id of the project that should be exported
 * @return A view that provides the required functionality to export a project
 */
@PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')")
@RequestMapping(value = "{projectType}/project/{projectId}/export", method = RequestMethod.GET)
public ResponseEntity<String> defaultPage(@PathVariable final String projectType,
        @PathVariable final String projectId) {
    final String exportedProject = projectServiceFacade.exportProject(projectType, projectId);

    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.setContentType(MediaType.TEXT_XML);
    respHeaders.setContentDispositionFormData("attachment",
            "project-" + projectType + "-" + projectId + ".xml");

    return new ResponseEntity<String>(exportedProject, respHeaders, HttpStatus.OK);
}

From source file:io.jmnarloch.spring.request.correlation.http.ClientHttpRequestCorrelationInterceptorTest.java

@Test
public void shouldSetHeader() throws IOException {

    // given// w  w w  .  j av  a  2s . c o m
    final String requestId = UUID.randomUUID().toString();
    CorrelationTestUtils.setRequestId(requestId);

    final HttpRequest request = mock(HttpRequest.class);
    final ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
    final byte[] body = new byte[0];

    when(request.getHeaders()).thenReturn(new HttpHeaders());

    // when
    instance.intercept(request, body, execution);

    // then
    assertTrue(request.getHeaders().containsKey(RequestCorrelationConsts.HEADER_NAME));
    assertEquals(requestId, request.getHeaders().getFirst(RequestCorrelationConsts.HEADER_NAME));
    verify(execution).execute(request, body);
}

From source file:org.cloudfoundry.identity.api.web.AppsIntegrationTests.java

/**
 * tests a happy-day flow of the native application profile.
 *///from  w  ww  .  ja  va2  s  . c  om
@Test
public void testHappyDay() throws Exception {

    RestOperations restTemplate = serverRunning.createRestTemplate();
    ResponseEntity<String> response = restTemplate.getForEntity(serverRunning.getUrl("/api/apps"),
            String.class);
    // first make sure the resource is actually protected.
    assertNotSame(HttpStatus.OK, response.getStatusCode());
    HttpHeaders approvalHeaders = new HttpHeaders();
    OAuth2AccessToken accessToken = context.getAccessToken();
    approvalHeaders.set("Authorization", "bearer " + accessToken.getValue());
    Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000);
    Date expiresAt = new Date(System.currentTimeMillis() + 60000);
    ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT,
            new HttpEntity<Approval[]>((new Approval[] {
                    new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "openid", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo) }),
                    approvalHeaders),
            Approval[].class);
    assertEquals(HttpStatus.OK, approvals.getStatusCode());

    ResponseEntity<String> result = serverRunning.getForString("/api/apps");
    assertEquals(HttpStatus.OK, result.getStatusCode());
    String body = result.getBody();
    assertTrue("Wrong response: " + body, body.contains("dsyerapi.cloudfoundry.com"));

}

From source file:NNIOEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    int ioWorkerCount = Runtime.getRuntime().availableProcessors() * 2;
    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(ioWorkerCount);

    try {//from  ww w .j av a2  s  .  c om
        final Netty4ClientHttpRequestFactory netty4ClientHttpRequestFactory = new Netty4ClientHttpRequestFactory(
                eventLoopGroup);
        netty4ClientHttpRequestFactory.setConnectTimeout(2000);
        netty4ClientHttpRequestFactory.setReadTimeout(2000);
        /*
                    SslContext sslContext = SslContextBuilder
        .forClient()
        .sslProvider(SslProvider.JDK)
        .build()
                    ;
        */
        if (requestOptions.getUrl().toLowerCase().startsWith("https://")) {
            SslContext sslContext = new DefaultClientSslContext();
            netty4ClientHttpRequestFactory.setSslContext(sslContext);
        }
        netty4ClientHttpRequestFactory.afterPropertiesSet();

        ResponseEntity<String> stringResponseEntity = null;
        for (int i = 0; i < requestOptions.getCount(); i++) {
            final HttpHeaders headers = new HttpHeaders();
            for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
                headers.put(e.getKey(), Collections.singletonList(e.getValue()));
            }

            final HttpEntity<Void> requestEntity = new HttpEntity<>(headers);

            AsyncRestTemplate template = new AsyncRestTemplate(netty4ClientHttpRequestFactory);
            final ListenableFuture<ResponseEntity<String>> exchange = template.exchange(requestOptions.getUrl(),
                    HttpMethod.GET, requestEntity, String.class);
            stringResponseEntity = exchange.get();
            System.out.println(stringResponseEntity.getBody());
        }
        return stringResponseEntity;
    } finally {
        eventLoopGroup.shutdownGracefully(100, 500, TimeUnit.MILLISECONDS);
    }
}

From source file:de.wirthedv.appname.SpringBootFacesApplicationTests.java

@Test
public void testJsfWelcomePageAccessibleByAdmin() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add(WebSecurityConfiguration.PREAUTH_USER_HEADER, "admin");
    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:\n" + entity.getBody(), entity.getBody().contains("<h1>Home page</h1>"));
}

From source file:org.ng200.openolympus.controller.task.TaskDescriptionSourcecodeController.java

@PreAuthorize(SecurityExpressionConstants.IS_ADMIN)
@RequestMapping(value = "/api/taskSourcecode", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<String> getTaskSourcecode(@RequestParam(value = "id") final Task task)
        throws IOException {
    Assertions.resourceExists(task);//  ww  w  .j  a v a2  s  .c  o m
    final HttpHeaders responseHeaders = new HttpHeaders();
    final Charset charset = Charset.forName("UTF-8");
    responseHeaders.setContentType(new MediaType("text", "plain", charset));
    return new ResponseEntity<String>(this.storageService.getTaskDescriptionSourcecode(task), responseHeaders,
            HttpStatus.OK);
}