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


Java ContainerRequest.setEntityStream方法代码示例

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


在下文中一共展示了ContainerRequest.setEntityStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getBody

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
private static CharSequence getBody(ContainerRequest request) {
	String body = null;
	try {
		body = IOUtils.toString(request.getEntityStream());
		// reading the stream consumes it, need to re-create it for the real thing
		request.setEntityStream(new StringInputStream(body)); 
	} catch (IOException e) {
		LOG.warn("Couldn't ready body.", e);
	}
	return body;
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:12,代码来源:LoggingApplicationEventListener.java

示例3: createContainerRequest

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
private ContainerRequest createContainerRequest(URI baseUri, URI requestUri, String method, String content, Map<String, String> headers,
                                                SecurityContext securityContext, PropertiesDelegate propertiesDelegate) {
    URI uri = URI.create(baseUri.getPath() + "/");
    ContainerRequest containerRequest = new ContainerRequest(uri, requestUri, method, securityContext, propertiesDelegate);
    containerRequest.setEntityStream(new ByteArrayInputStream(content.getBytes()));
    for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
        containerRequest.getHeaders().add(headerEntry.getKey(), headerEntry.getValue());
    }
    return containerRequest;
}
 
开发者ID:minnal,项目名称:minnal,代码行数:11,代码来源:BaseResourceTest.java

示例4: createContainerRequest

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
/**
	 * Creates the container request from the http request
	 *  
	 * @param httpRequest
	 * @return
	 */
	protected ContainerRequest createContainerRequest(MessageContext context) {
		Application<ApplicationConfiguration> application = context.getApplication();
		FullHttpRequest httpRequest = context.getRequest();
		URI baseUri = URI.create(context.getBaseUri().resolve(application.getPath()) + "/");
		URI requestUri = HttpUtil.createURI(httpRequest.getUri());
		ContainerRequest containerRequest = new ContainerRequest(baseUri, requestUri, httpRequest.getMethod().name(), null, new MapPropertiesDelegate());
//		containerRequest.setProperty(REQUEST_PROPERTY_REMOTE_ADDR, context.getRequest().channel().remoteAddress());
		containerRequest.setEntityStream(new ByteBufInputStream(httpRequest.content()));
		
        for (Map.Entry<String, String> headerEntry : httpRequest.headers()) {
        	containerRequest.getHeaders().add(headerEntry.getKey(), headerEntry.getValue());
        }
        return containerRequest;
	}
 
开发者ID:minnal,项目名称:minnal,代码行数:21,代码来源:Router.java

示例5: readRequest

import org.glassfish.jersey.server.ContainerRequest; //导入方法依赖的package包/类
/**
 * Reads an request object generated by an AWS_PROXY integration in API Gateway and transforms it into a Jersey
 * <code>ContainerRequest</code> object.
 *
 * @param request The incoming request object
 * @param securityContext A jax-rs SecurityContext object (@see com.amazonaws.serverless.proxy.SecurityContextWriter)
 * @param lambdaContext The AWS Lambda context for the request
 * @param config The container config object, this is passed in by the LambdaContainerHandler
 * @return A populated ContainerRequest object
 * @throws InvalidRequestEventException When the method fails to parse the incoming request
 */
@Override
public ContainerRequest readRequest(AwsProxyRequest request, SecurityContext securityContext, Context lambdaContext, ContainerConfig config)
        throws InvalidRequestEventException {
    currentRequest = request;
    currentLambdaContext = lambdaContext;

    request.setPath(stripBasePath(request.getPath(), config));

    URI basePathUri;
    URI requestPathUri;
    String basePath = "/";

    try {
        basePathUri = new URI(basePath);
    } catch (URISyntaxException e) {
        log.error("Could not read base path URI", e);
        throw new InvalidRequestEventException("Error while generating base path URI: " + basePath, e);
    }


    UriBuilder uriBuilder = UriBuilder.fromPath(request.getPath());

    if (request.getQueryStringParameters() != null) {
        for (String paramKey : request.getQueryStringParameters().keySet()) {
            uriBuilder = uriBuilder.queryParam(paramKey, request.getQueryStringParameters().get(paramKey));
        }
    }

    requestPathUri = uriBuilder.build();

    PropertiesDelegate apiGatewayProperties = new MapPropertiesDelegate();
    apiGatewayProperties.setProperty(API_GATEWAY_CONTEXT_PROPERTY, request.getRequestContext());
    apiGatewayProperties.setProperty(API_GATEWAY_STAGE_VARS_PROPERTY, request.getStageVariables());
    apiGatewayProperties.setProperty(LAMBDA_CONTEXT_PROPERTY, lambdaContext);

    ContainerRequest requestContext = new ContainerRequest(basePathUri, requestPathUri, request.getHttpMethod(), securityContext, apiGatewayProperties);

    if (request.getBody() != null) {
        if (request.isBase64Encoded()) {
            requestContext.setEntityStream(new ByteArrayInputStream(Base64.getDecoder().decode(request.getBody())));
        } else {
            requestContext.setEntityStream(new ByteArrayInputStream(request.getBody().getBytes()));
        }
    }

    if (request.getHeaders() != null) {
        for (final String headerName : request.getHeaders().keySet()) {
            requestContext.headers(headerName, request.getHeaders().get(headerName));
        }
    }

    return requestContext;
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:65,代码来源:JerseyAwsProxyRequestReader.java

示例6: 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.setEntityStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。