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


Java ContainerRequest.setWriter方法代码示例

本文整理汇总了Java中org.glassfish.jersey.server.ContainerRequest.setWriter方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest.setWriter方法的具体用法?Java ContainerRequest.setWriter怎么用?Java ContainerRequest.setWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.jersey.server.ContainerRequest的用法示例。


在下文中一共展示了ContainerRequest.setWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createContainerRequest

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:31,代码来源:JRestlessHandlerContainer.java

示例2: handleRequest

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
@Override
protected void handleRequest(ContainerRequest containerRequest, JerseyResponseWriter jerseyResponseWriter, Context lambdaContext) {
    containerRequest.setWriter(jerseyResponseWriter);

    applicationHandler.handle(containerRequest);
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:7,代码来源:JerseyLambdaContainerHandler.java

示例3: apply

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p/>
 * Transforms client-side request to server-side and invokes it on provided
 * application ({@link ApplicationHandler} instance).
 *
 * @param clientRequest
 *            client side request to be invoked.
 */
@Override
public ClientResponse apply(final ClientRequest clientRequest) {
	final PropertiesDelegate propertiesDelegate = new MapPropertiesDelegate();

	final ContainerRequest containerRequest = new ContainerRequest(this.baseUri, clientRequest.getUri(),
			clientRequest.getMethod(), null, propertiesDelegate);

	containerRequest.getHeaders().putAll(clientRequest.getStringHeaders());

	final ByteArrayOutputStream clientOutput = new ByteArrayOutputStream();
	if (clientRequest.getEntity() != null) {
		clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
			@Override
			public OutputStream getOutputStream(final int contentLength) throws IOException {
				final MultivaluedMap<String, Object> clientHeaders = clientRequest.getHeaders();
				if (contentLength != -1 && !clientHeaders.containsKey(HttpHeaders.CONTENT_LENGTH)) {
					containerRequest.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH,
							String.valueOf(contentLength));
				}
				return clientOutput;
			}
		});
		clientRequest.enableBuffering();

		try {
			clientRequest.writeEntity();
		} catch (final IOException e) {
			final String msg = "Error while writing entity to the output stream.";
			CdiAwareInMemoryConnector.LOGGER.log(Level.SEVERE, msg, e);
			throw new ProcessingException(msg, e);
		}
	}

	containerRequest.setEntityStream(new ByteArrayInputStream(clientOutput.toByteArray()));

	final boolean followRedirects = ClientProperties.getValue(clientRequest.getConfiguration().getProperties(),
			ClientProperties.FOLLOW_REDIRECTS, true);

	final InMemoryResponseWriter inMemoryResponseWriter = new InMemoryResponseWriter();
	containerRequest.setWriter(inMemoryResponseWriter);
	containerRequest.setSecurityContext(new SecurityContext() {

		@Override
		public String getAuthenticationScheme() {
			return null;
		}

		@Override
		public Principal getUserPrincipal() {
			return null;
		}

		@Override
		public boolean isSecure() {
			return false;
		}

		@Override
		public boolean isUserInRole(final String role) {
			return false;
		}

	});
	this.appHandler.handle(containerRequest);

	return tryFollowRedirects(followRedirects,
			CdiAwareInMemoryConnector.createClientResponse(clientRequest, inMemoryResponseWriter),
			new ClientRequest(clientRequest));

}
 
开发者ID:gtcGroup,项目名称:jped-parent-project,代码行数:80,代码来源:CdiAwareInMemoryConnector.java


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