Example usage for org.springframework.http HttpHeaders CONNECTION

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

Introduction

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

Prototype

String CONNECTION

To view the source code for org.springframework.http HttpHeaders CONNECTION.

Click Source Link

Document

The HTTP Connection header field name.

Usage

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractPipedStreamRestSynchronizerImpl.java

private void addKeepAliveConnectionHeader(ClientHttpRequest clientHttpRequest) {
    log.debug("Set the Connection Header to keep-alive");
    HttpHeaders headers = clientHttpRequest.getHeaders();
    headers.add(HttpHeaders.CONNECTION, "keep-alive");
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getInputStream_OK(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception {
    mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.GET))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andRespond(withSuccess(
                    owncloudFileResource.getTestFileContent(), owncloudFileResource.getMediaType()));
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getInputStream_NOK_FileNotFound(OwncloudTestFileResourceImpl owncloudFileResource)
        throws Exception {
    mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.GET))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive"))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getOutputStream_OK(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception {
    mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive"))
            .andExpect(content().contentType(owncloudFileResource.getMediaType()))
            .andExpect(content().string(owncloudFileResource.getTestFileContent())).andRespond(withSuccess());
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getOutputStream_NOK_Unauthorized(OwncloudTestFileResourceImpl owncloudFileResource)
        throws Exception {
    mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive"))
            .andExpect(content().contentType(owncloudFileResource.getMediaType()))
            .andExpect(content().bytes(new byte[] { 1 })).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getOutputStream_OK_CreateNewFile(URI href, MediaType mediaType, String testFileContent)
        throws Exception {
    Mockito.when(sardine.list(getResourcePath(href), 0))
            .thenThrow(new SardineException("No File", HttpStatus.NOT_FOUND.value(), null));
    mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType))
            .andExpect(content().string(testFileContent)).andRespond(withSuccess());
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getOutputStream_OK_OverwriteFile(URI href, MediaType mediaType, String testFileContent)
        throws Exception {
    List<DavResource> davResources = Lists.newArrayList(createDavResourceFrom(OwncloudTestFileResourceImpl
            .fileBuilder()/* w ww  .j ava 2  s. c o m*/
            .owncloudResource(OwncloudTestResourceImpl.builder().href(href).mediaType(mediaType).build())
            .testFileContent(testFileContent).build(), Locale.GERMAN));
    Mockito.when(sardine.list(getResourcePath(href))).thenReturn(davResources);
    mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType))
            .andExpect(content().string(testFileContent)).andRespond(withSuccess());
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getOutputStram_NOK_FileTooBig(URI href, MediaType mediaType, String testFileContent)
        throws Exception {
    Mockito.when(sardine.list(getResourcePath(href), 0))
            .thenThrow(new SardineException("No File", HttpStatus.NOT_FOUND.value(), null));
    mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType))
            .andExpect(content().string(testFileContent))
            .andRespond(withStatus(HttpStatus.INSUFFICIENT_STORAGE));
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java

@Override
protected void prepare_getQuota_OneFile(URI uri, MediaType mediaType, String testFileContent,
        OwncloudQuota expectedFirst, OwncloudQuota expectedSecond) throws Exception {
    mockServer.expect(requestToWithPrefix(uri)).andExpect(method(HttpMethod.PUT))
            .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader()))
            .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType))
            .andExpect(content().string(testFileContent)).andRespond(withSuccess());

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    Mockito.when(userQueryService.getQuota(authentication.getName())).then(new Answer<OwncloudQuota>() {
        private int count = 0;

        @Override/*w  w w  .  ja  va 2 s.  c om*/
        public OwncloudQuota answer(InvocationOnMock invocation) throws Throwable {
            if (count++ == 0) {
                return OwncloudRestQuotaImpl.builder().username(expectedFirst.getUsername())
                        .free(expectedFirst.getFree()).relative(expectedFirst.getRelative())
                        .total(expectedFirst.getTotal()).used(expectedFirst.getUsed()).build();
            }
            return OwncloudRestQuotaImpl.builder().username(expectedSecond.getUsername())
                    .free(expectedSecond.getFree()).relative(expectedSecond.getRelative())
                    .total(expectedSecond.getTotal()).used(expectedSecond.getUsed()).build();
        }
    });
}