本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}