本文整理汇总了Java中io.undertow.server.HttpServerExchange.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.getConnection方法的具体用法?Java HttpServerExchange.getConnection怎么用?Java HttpServerExchange.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.getConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requiresContinueResponse
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
* Returns true if this exchange requires the server to send a 100 (Continue) response.
*
* @param exchange The exchange
* @return <code>true</code> if the server needs to send a continue response
*/
public static boolean requiresContinueResponse(final HttpServerExchange exchange) {
if (!exchange.isHttp11() || exchange.isResponseStarted() || exchange.getAttachment(ALREADY_SENT) != null) {
return false;
}
if (exchange.getConnection() instanceof HttpServerConnection) {
if (((HttpServerConnection) exchange.getConnection()).getExtraBytes() != null) {
//we have already received some of the request body
//so according to the RFC we do not need to send the Continue
return false;
}
}
List<String> expect = exchange.getRequestHeaders().get(Headers.EXPECT);
if (expect != null) {
for (String header : expect) {
if (header.equalsIgnoreCase(CONTINUE)) {
return true;
}
}
}
return false;
}
示例2: authenticate
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange,
final SecurityContext securityContext) {
ServerConnection connection = exchange.getConnection();
NegotiationContext negContext = connection.getAttachment(NegotiationContext.ATTACHMENT_KEY);
if (negContext != null) {
exchange.putAttachment(NegotiationContext.ATTACHMENT_KEY, negContext);
if (negContext.isEstablished()) {
IdentityManager identityManager = securityContext.getIdentityManager();
final Account account = identityManager.verify(new GSSContextCredential(negContext.getGssContext()));
if (account != null) {
securityContext.authenticationComplete(account, name, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
List<String> authHeaders = exchange.getRequestHeaders().get(AUTHORIZATION);
if (authHeaders != null) {
for (String current : authHeaders) {
if (current.startsWith(NEGOTIATE_PREFIX)) {
String base64Challenge = current.substring(NEGOTIATE_PREFIX.length());
try {
ByteBuffer challenge = FlexBase64.decode(base64Challenge);
return runGSSAPI(exchange, challenge, securityContext);
} catch (IOException e) {
}
// By this point we had a header we should have been able to verify but for some reason
// it was not correctly structured.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
// No suitable header was found so authentication was not even attempted.
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例3: exchangeComplete
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void exchangeComplete(final HttpServerExchange exchange) {
//if we ever fail to read then we flush the pipeline buffer
//this relies on us always doing an eager read when starting a request,
//rather than waiting to be notified of data being available
final HttpServerConnection connection = (HttpServerConnection) exchange.getConnection();
if (connection.getExtraBytes() == null || exchange.isUpgrade()) {
performFlush(exchange, connection);
} else {
connection.getReadListener().exchangeComplete(exchange);
}
}
示例4: handleFirstRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void handleFirstRequest(final HttpServerExchange exchange, final ServletChain servletChain, final ServletRequestContext servletRequestContext, final ServletRequest request, final ServletResponse response) throws Exception {
ThreadSetupAction.Handle handle = setupAction.setup(exchange);
try {
servletRequestContext.setRunningInsideHandler(true);
try {
listeners.requestInitialized(request);
next.handleRequest(exchange);
//
if(servletRequestContext.getErrorCode() > 0) {
servletRequestContext.getOriginalResponse().doErrorDispatch(servletRequestContext.getErrorCode(), servletRequestContext.getErrorMessage());
}
} catch (Throwable t) {
//by default this will just log the exception
boolean handled = exceptionHandler.handleThrowable(exchange, request, response, t);
if(handled) {
exchange.endExchange();
} else if (request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC) {
exchange.unDispatch();
servletRequestContext.getOriginalRequest().getAsyncContextInternal().handleError(t);
} else {
if (!exchange.isResponseStarted()) {
response.reset(); //reset the response
exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.getResponseHeaders().clear();
String location = servletContext.getDeployment().getErrorPages().getErrorLocation(t);
if (location == null) {
location = servletContext.getDeployment().getErrorPages().getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
}
if (location != null) {
RequestDispatcherImpl dispatcher = new RequestDispatcherImpl(location, servletContext);
try {
dispatcher.error(servletRequestContext, request, response, servletChain.getManagedServlet().getServletInfo().getName(), t);
} catch (Exception e) {
UndertowLogger.REQUEST_LOGGER.exceptionGeneratingErrorPage(e, location);
}
} else {
if (servletRequestContext.displayStackTraces()) {
ServletDebugPageHandler.handleRequest(exchange, servletRequestContext, t);
} else {
servletRequestContext.getOriginalResponse().doErrorDispatch(StatusCodes.INTERNAL_SERVER_ERROR, StatusCodes.INTERNAL_SERVER_ERROR_STRING);
}
}
}
}
} finally {
servletRequestContext.setRunningInsideHandler(false);
listeners.requestDestroyed(request);
}
//if it is not dispatched and is not a mock request
if (!exchange.isDispatched() && !(exchange.getConnection() instanceof MockServerConnection)) {
servletRequestContext.getOriginalResponse().responseDone();
servletRequestContext.getOriginalRequest().clearAttributes();
}
if(!exchange.isDispatched()) {
AsyncContextImpl ctx = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
if(ctx != null) {
ctx.complete();
}
}
} finally {
handle.tearDown();
}
}
示例5: setupRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public static void setupRequest(final HttpServerExchange exchange) {
final HeaderMap requestHeaders = exchange.getRequestHeaders();
final String connectionHeader = requestHeaders.getFirst(Headers.CONNECTION);
final String transferEncodingHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
final String contentLengthHeader = requestHeaders.getFirst(Headers.CONTENT_LENGTH);
final HttpServerConnection connection = (HttpServerConnection) exchange.getConnection();
//if we are already using the pipelineing buffer add it to the exchange
PipeliningBufferingStreamSinkConduit pipeliningBuffer = connection.getPipelineBuffer();
if (pipeliningBuffer != null) {
pipeliningBuffer.setupPipelineBuffer(exchange);
}
ConduitStreamSourceChannel sourceChannel = connection.getChannel().getSourceChannel();
sourceChannel.setConduit(connection.getReadDataStreamSourceConduit());
boolean persistentConnection = persistentConnection(exchange, connectionHeader);
if (transferEncodingHeader == null && contentLengthHeader == null) {
if (persistentConnection
&& connection.getExtraBytes() != null
&& pipeliningBuffer == null
&& connection.getUndertowOptions().get(UndertowOptions.BUFFER_PIPELINED_DATA, false)) {
pipeliningBuffer = new PipeliningBufferingStreamSinkConduit(connection.getOriginalSinkConduit(), connection.getBufferPool());
connection.setPipelineBuffer(pipeliningBuffer);
pipeliningBuffer.setupPipelineBuffer(exchange);
}
// no content - immediately start the next request, returning an empty stream for this one
Connectors.terminateRequest(exchange);
} else {
persistentConnection = handleRequestEncoding(exchange, transferEncodingHeader, contentLengthHeader, connection, pipeliningBuffer, persistentConnection);
}
exchange.setPersistent(persistentConnection);
if (!exchange.isRequestComplete() || connection.getExtraBytes() != null) {
//if there is more data we suspend reads
sourceChannel.setReadListener(null);
sourceChannel.suspendReads();
}
}
示例6: createSinkConduit
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
static StreamSinkConduit createSinkConduit(final HttpServerExchange exchange) {
DateUtils.addDateHeaderIfRequired(exchange);
boolean headRequest = exchange.getRequestMethod().equals(Methods.HEAD);
HttpServerConnection serverConnection = (HttpServerConnection) exchange.getConnection();
HttpResponseConduit responseConduit = serverConnection.getResponseConduit();
responseConduit.reset(exchange);
StreamSinkConduit channel = responseConduit;
if (headRequest) {
//if this is a head request we add a head channel underneath the content encoding channel
//this will just discard the data
//we still go through with the rest of the logic, to make sure all headers are set correctly
channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
} else if(!Connectors.isEntityBodyAllowed(exchange)) {
//we are not allowed to send an entity body for some requests
exchange.getResponseHeaders().remove(Headers.CONTENT_LENGTH);
exchange.getResponseHeaders().remove(Headers.TRANSFER_ENCODING);
channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
}
final HeaderMap responseHeaders = exchange.getResponseHeaders();
// test to see if we're still persistent
String connection = responseHeaders.getFirst(Headers.CONNECTION);
if (!exchange.isPersistent()) {
responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
} else if (exchange.isPersistent() && connection != null) {
if (HttpString.tryFromString(connection).equals(Headers.CLOSE)) {
exchange.setPersistent(false);
}
} else if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true)) {
responseHeaders.put(Headers.CONNECTION, Headers.KEEP_ALIVE.toString());
}
//according to the HTTP RFC we should ignore content length if a transfer coding is specified
final String transferEncodingHeader = responseHeaders.getLast(Headers.TRANSFER_ENCODING);
if(transferEncodingHeader == null) {
final String contentLengthHeader = responseHeaders.getFirst(Headers.CONTENT_LENGTH);
if (contentLengthHeader != null) {
StreamSinkConduit res = handleFixedLength(exchange, headRequest, channel, responseHeaders, contentLengthHeader, serverConnection);
if (res != null) {
return res;
}
}
}
return handleResponseConduit(exchange, headRequest, channel, responseHeaders, terminateResponseListener(exchange), transferEncodingHeader);
}