org.glassfish.jersey.server.spi.ContainerResponseWriter Java Examples

The following examples show how to use org.glassfish.jersey.server.spi.ContainerResponseWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JRestlessHandlerContainer.java    From jrestless with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link ContainerRequest} for the given input.
 *
 * @param request
 * @param containerResponseWriter
 * @param securityContext
 * @return
 */
@Nonnull
protected ContainerRequest createContainerRequest(@Nonnull RequestT request,
		@Nonnull ContainerResponseWriter containerResponseWriter, @Nonnull SecurityContext securityContext) {
	requireNonNull(request, "request may not be null");
	URI baseUri = request.getBaseUri();
	URI requestUri = requireNonNull(request.getRequestUri(), "request.getRequestUri() may not be null");
	String httpMethod = requireNonNull(request.getHttpMethod(), "request.getHttpMethod() may not be null");
	InputStream entityStream = requireNonNull(request.getEntityStream(),
			"request.getEntityStream() may not be null");
	Map<String, List<String>> headers = requireNonNull(request.getHeaders(),
			"request.getHeaderParams() may not be null");
	requireNonNull(containerResponseWriter, "containerResponseWriter may not be null");
	requireNonNull(securityContext, "securityContext may not be null");

	ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, httpMethod, securityContext,
			new MapPropertiesDelegate());
	requestContext.setEntityStream(entityStream);
	requestContext.getHeaders().putAll(headers);
	requestContext.setWriter(containerResponseWriter);

	return requestContext;
}
 
Example #2
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@Test
public void createContainerRequest_RequestAndContainerResponseWriterAndSecurityContextGiven_ShouldCreateContainerRequestUsingValues() {
	URI baseUri = URI.create("/");
	URI requestUri = URI.create("/entity");
	String httpMethod = "POST";
	ByteArrayInputStream entityStream = new ByteArrayInputStream(new byte[0]);
	MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
	headers.add("hk0", "hv0_0");
	headers.add("hk0", "hv0_1");
	headers.add("hk1", "hv1_0");
	JRestlessContainerRequest request = createRequest(baseUri, requestUri, httpMethod, entityStream, headers);

	ContainerResponseWriter containerResponseWriter = mock(ContainerResponseWriter.class);
	SecurityContext securityContext = mock(SecurityContext.class);

	ContainerRequest containerRequest = container.createContainerRequest(request, containerResponseWriter, securityContext);

	assertEquals(baseUri, containerRequest.getBaseUri());
	assertEquals(requestUri, containerRequest.getRequestUri());
	assertEquals(httpMethod, containerRequest.getMethod());
	assertSame(entityStream, containerRequest.getEntityStream());
	assertEquals(headers, containerRequest.getHeaders());
	assertSame(containerResponseWriter, containerRequest.getResponseWriter());
	assertSame(securityContext, containerRequest.getSecurityContext());
}
 
Example #3
Source File: UndertowResponseWriter.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean suspend(long timeOut, TimeUnit timeUnit, final ContainerResponseWriter.TimeoutHandler timeoutHandler) {
    suspendTimeoutHandler = () -> timeoutHandler.onTimeout(this);
    if (timeOut <= 0) {
        return true;
    }
    suspendTimeoutFuture = container.getScheduledExecutorService().schedule(suspendTimeoutHandler, timeOut, timeUnit);
    return true;
}
 
Example #4
Source File: MockContainerResponseWriter.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean suspend(long timeOut, TimeUnit timeUnit, final ContainerResponseWriter.TimeoutHandler timeoutHandler) {
    suspendTimeoutHandler = () -> timeoutHandler.onTimeout(this);
    if (timeOut <= 0) {
        return true;
    }
    suspendTimeoutFuture = getScheduledExecutorService().schedule(suspendTimeoutHandler, timeOut, timeUnit);
    return true;
}
 
Example #5
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoRequestGiven_ShouldThrowNpe() {
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(null, mock(ContainerResponseWriter.class), mock(SecurityContext.class)));
}
 
Example #6
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoSecurityContext_ShouldThrowNpe() {
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(createAnyRequest(), mock(ContainerResponseWriter.class), null));
}
 
Example #7
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
public void createContainerRequest_NoRequestBaseUriGiven_ShouldPass() {
	JRestlessContainerRequest request = createAnyRequest();
	when(request.getBaseUri()).thenReturn(null);
	container.createContainerRequest(request, mock(ContainerResponseWriter.class), mock(SecurityContext.class));
}
 
Example #8
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoRequestRequestUriGiven_ShouldThrowNpe() {
	JRestlessContainerRequest request = createAnyRequest();
	when(request.getRequestUri()).thenReturn(null);
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(request, mock(ContainerResponseWriter.class), mock(SecurityContext.class)));
}
 
Example #9
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoRequestHttpMethodGiven_ShouldThrowNpe() {
	JRestlessContainerRequest request = createAnyRequest();
	when(request.getHttpMethod()).thenReturn(null);
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(request, mock(ContainerResponseWriter.class), mock(SecurityContext.class)));
}
 
Example #10
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoRequestEntityStreamGiven_ShouldThrowNpe() {
	JRestlessContainerRequest request = createAnyRequest();
	when(request.getEntityStream()).thenReturn(null);
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(request, mock(ContainerResponseWriter.class), mock(SecurityContext.class)));
}
 
Example #11
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void createContainerRequest_NoRequestHeadersGiven_ShouldThrowNpe() {
	JRestlessContainerRequest request = createAnyRequest();
	when(request.getHeaders()).thenReturn(null);
	assertThrows(NullPointerException.class, () -> container.createContainerRequest(request, mock(ContainerResponseWriter.class), mock(SecurityContext.class)));
}
 
Example #12
Source File: Requests.java    From ameba with MIT License 2 votes vote down vote up
/**
 * <p>setWriter.</p>
 *
 * @param responseWriter a {@link org.glassfish.jersey.server.spi.ContainerResponseWriter} object.
 */
public static void setWriter(ContainerResponseWriter responseWriter) {
    getRequest().setWriter(responseWriter);
}
 
Example #13
Source File: Requests.java    From ameba with MIT License 2 votes vote down vote up
/**
 * <p>getResponseWriter.</p>
 *
 * @return a {@link org.glassfish.jersey.server.spi.ContainerResponseWriter} object.
 */
public static ContainerResponseWriter getResponseWriter() {
    return getRequest().getResponseWriter();
}