当前位置: 首页>>代码示例>>Java>>正文


Java Header类代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.util.Header的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Header类属于org.glassfish.grizzly.http.util包,在下文中一共展示了Header类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postNewTodoItem

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void postNewTodoItem() throws UnsupportedEncodingException, AuthenticationException {
   final String newTodoItem = fixture("fixtures/todoItem_new.json");
   final TodoItem expectedTodoItem = new TodoItem(1, "make new todo items", true);
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.createItem(eq(oacc), any(TodoItem.class)))
         .thenReturn(expectedTodoItem);

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .post(Entity.entity(newTodoItem, MediaType.APPLICATION_JSON));

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
   assertThat(response.readEntity(TodoItem.class)).isEqualTo(expectedTodoItem);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:20,代码来源:TodoItemResourceTest.java

示例2: postNewTodoItemThatFailsValidation

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void postNewTodoItemThatFailsValidation() throws AuthenticationException, UnsupportedEncodingException {
   final String blankTodoItem = fixture("fixtures/todoItem_blank.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.createItem(eq(oacc), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Either title or completed (or both) is required"));

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .post(Entity.entity(blankTodoItem, MediaType.APPLICATION_JSON));

   assertThat(response.getStatus()).isEqualTo(422);   // 422 Unprocessable Entity
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:19,代码来源:TodoItemResourceTest.java

示例3: getTodoItems

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void getTodoItems() throws AuthenticationException, UnsupportedEncodingException {
   final List<TodoItem> expectedTodoItems
         = Collections.singletonList(new TodoItem(1, "list all items", true));

   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.findByAuthenticatedUser(eq(oacc)))
         .thenReturn(expectedTodoItems);

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .get();

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:20,代码来源:TodoItemResourceTest.java

示例4: patchTodoItem

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void patchTodoItem() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   final TodoItem expectedTodoItem = new TodoItem(1, "update titles", false);
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenReturn(expectedTodoItem);

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
   assertThat(response.readEntity(TodoItem.class)).isEqualTo(expectedTodoItem);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:23,代码来源:TodoItemResourceTest.java

示例5: patchTodoItemWithoutAuthorization

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void patchTodoItemWithoutAuthorization() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new NotAuthorizedException("not authorized"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());   // 403 Forbidden
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:21,代码来源:TodoItemResourceTest.java

示例6: patchTodoItemThatDoesNotExist

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void patchTodoItemThatDoesNotExist() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Resource " + todoItemId + " not found!"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());   // 404 Not Found
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:22,代码来源:TodoItemResourceTest.java

示例7: patchTodoItemThatFailsValidation

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void patchTodoItemThatFailsValidation() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String blankTodoItem = fixture("fixtures/todoItem_blank.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Either title or completed (or both) is required."));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(blankTodoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(422);   // 422 Unprocessable Entity
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:22,代码来源:TodoItemResourceTest.java

示例8: putShareAssociationOnTodoItem

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void putShareAssociationOnTodoItem() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String targetEmail = "[email protected]";
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .queryParam("share_with", targetEmail)
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .put(Entity.json(""));

   assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());   // 204 No Content
   assertThat(response.readEntity(Object.class)).isNull();
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:19,代码来源:TodoItemResourceTest.java

示例9: putShareAssociationOnTodoItemWithoutAuthorization

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void putShareAssociationOnTodoItemWithoutAuthorization() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String targetEmail = "[email protected]";
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   doThrow(new NotAuthorizedException("not authorized"))
         .when(todoItemService).shareItem(eq(oacc), eq(todoItemId), eq(targetEmail));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .queryParam("share_with", targetEmail)
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .put(Entity.json(""));

   assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());   // 403 Forbidden
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:21,代码来源:TodoItemResourceTest.java

示例10: putShareAssociationOnTodoItemOrUserThatDoesNotExist

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Test
public void putShareAssociationOnTodoItemOrUserThatDoesNotExist() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String targetEmail = "[email protected]";
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   doThrow(new IllegalArgumentException("Resource " + todoItemId + " not found!"))
         .when(todoItemService).shareItem(eq(oacc), eq(todoItemId), eq(targetEmail));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .queryParam("share_with", targetEmail)
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .put(Entity.json(""));

   assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());   // 404 Not Found
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:21,代码来源:TodoItemResourceTest.java

示例11: service

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
@Override
public void service(Request request, Response response)
throws Exception {
    final String query = request.getQueryString();
    String path = request.getPathInfo();
    if (path == null) path = "/";

    log.info("Checking path \"%s\" against %d redirects", path, redirects.size());
    for (Redirect redirect: redirects) {
        final String location = redirect.apply(path, query);
        if (location != null) {
            response.setStatus(redirect.status);
            response.setHeader(Header.Location, location);
            response.finish();
            return;
        }
    }

    response.setStatus(NOT_FOUND_404);
    response.finish();
}
 
开发者ID:usrz,项目名称:java-libs-httpd,代码行数:22,代码来源:RedirectHandler.java

示例12: sendStream

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
private void sendStream(Request request, Response response, ResourceLocation resource) {

		printRequestHeader(request);
		// check header for range request:

		final long totalLength = resource.length();
		
		// Parse request header
		boolean compress = isStreamCompressionEnabled() && isGzipSupported(request);
		
		HttpByteRange range = getRequestRange(request, totalLength);
		long requestLenght = range.to - range.from;

		try {
			response.addHeader(Header.AcceptRanges, "bytes");
			response.setHeader(Header.ContentRange, range.toByteRange(totalLength));
			response.setHeader(Header.ContentLength, requestLenght+"");
			response.addHeader(Header.ContentType, resource.getMimeType());

			sendStream(response, resource, range, compress);

			response.sendAcknowledgement();
		} catch (IOException e) {
            logger.error(e);
		}
	}
 
开发者ID:Vidada-Project,项目名称:vidada-desktop,代码行数:27,代码来源:SeekableHttpHandler.java

示例13: getRequestRange

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
private HttpByteRange getRequestRange(Request request, long totalLength){
	HttpByteRange range = null;
	String requestRange = request.getHeader(Header.Range);
	if(requestRange != null){ 
		range = HttpByteRange.parse(requestRange);
		// Ensure that we send to an index > 0
		if(range.to == 0){
			range.to = totalLength;
		}

		// Ensure range is in valid bounds
		range.from = Math.max(0, range.from); 			// Smallest value is zero
		range.from = Math.min(totalLength, range.from);	// Biggest value is resource.length
		range.to = Math.max(0, range.to);				// Smallest value is zero
		range.to = Math.min(totalLength, range.to);		// Biggest value is resource.length
	}else{
		range = new HttpByteRange(0, totalLength);
	}

       logger.debug("requested range: " + requestRange);
       logger.debug("interpreted range: " + range);
	
	return range;
}
 
开发者ID:Vidada-Project,项目名称:vidada-desktop,代码行数:25,代码来源:SeekableHttpHandler.java

示例14: isGzipSupported

import org.glassfish.grizzly.http.util.Header; //导入依赖的package包/类
private boolean isGzipSupported(Request request){
	boolean supportsGzip = false;
	Iterable<String> acceptedEncoding = request.getHeaders(Header.AcceptEncoding);
	for (String encoding : acceptedEncoding) {
		if(encoding.contains("gzip")){
			supportsGzip = true;
			break;
		}
	}
	return supportsGzip;
}
 
开发者ID:Vidada-Project,项目名称:vidada-desktop,代码行数:12,代码来源:SeekableHttpHandler.java


注:本文中的org.glassfish.grizzly.http.util.Header类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。