本文整理汇总了Java中io.undertow.server.HttpServerExchange.getResponseCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.getResponseCode方法的具体用法?Java HttpServerExchange.getResponseCode怎么用?Java HttpServerExchange.getResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.getResponseCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
* Only allow the request through if successfully authenticated or if authentication is not required.
*
* @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
*/
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if(exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
SecurityContext context = exchange.getSecurityContext();
if (context.authenticate()) {
if(!exchange.isComplete()) {
next.handleRequest(exchange);
}
} else {
if(exchange.getResponseCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
src.getOriginalResponse().sendError(exchange.getResponseCode());
} else {
exchange.endExchange();
}
}
}
示例2: wrap
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) {
if (exchange.getResponseHeaders().contains(Headers.CONTENT_ENCODING)) {
//already encoded
return factory.create();
}
//if this is a zero length response we don't want to encode
if (exchange.getResponseContentLength() != 0
&& exchange.getResponseCode() != StatusCodes.NO_CONTENT
&& exchange.getResponseCode() != StatusCodes.NOT_MODIFIED) {
EncodingMapping encoding = getEncoding();
if (encoding != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_ENCODING, encoding.getName());
if (exchange.getRequestMethod().equals(Methods.HEAD)) {
//we don't create an actual encoder for HEAD requests, but we set the header
return factory.create();
} else {
return encoding.getEncoding().getResponseWrapper().wrap(factory, exchange);
}
}
}
return factory.create();
}
示例3: CachedHttpRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public CachedHttpRequest(final HttpServerExchange exchange) {
this.path = exchange.getRequestPath();
this.etag = ETagUtils.getETag(exchange);
this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION);
this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE);
this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE);
String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED);
if (lmString == null) {
this.lastModified = null;
} else {
this.lastModified = DateUtils.parseDate(lmString);
}
//the content encoding can be decided dynamically, based on the current state of the request
//as the decision to compress generally depends on size and mime type
final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY);
if(encoding != null) {
this.contentEncoding = encoding.getCurrentContentEncoding();
} else {
this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING);
}
this.responseCode = exchange.getResponseCode();
}
示例4: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
PluginWrapperClient.doAuthorize(exchange);
if(exchange.getResponseCode()==403){
exchange.endExchange();
}
else{
next.handleRequest(exchange);
}
}
示例5: logMessage
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void logMessage(String pattern, HttpServerExchange exchange) {
JDBCLogAttribute jdbcLogAttribute = new JDBCLogAttribute();
if (pattern.equals("combined")) {
jdbcLogAttribute.pattern = pattern;
}
jdbcLogAttribute.remoteHost = ((InetSocketAddress) exchange.getConnection().getPeerAddress()).getAddress().getHostAddress();
SecurityContext sc = exchange.getSecurityContext();
if (sc == null || !sc.isAuthenticated()) {
jdbcLogAttribute.user = null;
} else {
jdbcLogAttribute.user = sc.getAuthenticatedAccount().getPrincipal().getName();
}
jdbcLogAttribute.query = exchange.getQueryString();
jdbcLogAttribute.bytes = exchange.getResponseContentLength();
if (jdbcLogAttribute.bytes < 0)
jdbcLogAttribute.bytes = 0;
jdbcLogAttribute.status = exchange.getResponseCode();
if (jdbcLogAttribute.pattern.equals("combined")) {
jdbcLogAttribute.virtualHost = exchange.getRequestHeaders().getFirst(Headers.HOST);
jdbcLogAttribute.method = exchange.getRequestMethod().toString();
jdbcLogAttribute.referer = exchange.getRequestHeaders().getFirst(Headers.REFERER);
jdbcLogAttribute.userAgent = exchange.getRequestHeaders().getFirst(Headers.USER_AGENT);
}
this.pendingMessages.add(jdbcLogAttribute);
int state = stateUpdater.get(this);
if (state == 0) {
if (stateUpdater.compareAndSet(this, 0, 1)) {
logWriteExecutor.execute(this);
}
}
}