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