本文整理汇总了Java中io.undertow.server.HttpServerExchange.endExchange方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.endExchange方法的具体用法?Java HttpServerExchange.endExchange怎么用?Java HttpServerExchange.endExchange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.endExchange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: cancel
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
void cancel(final HttpServerExchange exchange) {
final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
if (connectionAttachment != null) {
ClientConnection clientConnection = connectionAttachment.getConnection();
UndertowLogger.REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
IoUtils.safeClose(clientConnection);
} else {
UndertowLogger.REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
}
if (exchange.isResponseStarted()) {
IoUtils.safeClose(exchange.getConnection());
} else {
exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
exchange.endExchange();
}
}
示例3: 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 {
exchange.endExchange();
}
}
示例4: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Map<String, Object> examples = new HashMap<>();
if(examples.size() > 0) {
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send((String)examples.get("application/json"));
} else {
exchange.endExchange();
}
}
示例5: 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);
}
}
示例6: deleteUser
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public static void deleteUser(HttpServerExchange exchange) {
String email = userRequests.email(exchange);
// If you care about it you can handle it.
if (false == userDao.delete(email)) {
ApiHandlers.notFound(exchange, String.format("User {} not found.", email));
return;
}
exchange.setStatusCode(StatusCodes.NO_CONTENT);
exchange.endExchange();
}
示例7: couldNotResolveBackend
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void couldNotResolveBackend(HttpServerExchange exchange) {
if (exchange.isResponseStarted()) {
IoUtils.safeClose(exchange.getConnection());
} else {
exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
exchange.endExchange();
}
}
示例8: runFormAuth
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange exchange, final SecurityContext securityContext) {
final FormDataParser parser = formParserFactory.createParser(exchange);
if (parser == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as no form parser is present");
// TODO - May need a better error signaling mechanism here to prevent repeated attempts.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
try {
final FormData data = parser.parseBlocking();
final FormData.FormValue jUsername = data.getFirst("j_username");
final FormData.FormValue jPassword = data.getFirst("j_password");
if (jUsername == null || jPassword == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as username or password was not present in the posted result");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
final String userName = jUsername.getValue();
final String password = jPassword.getValue();
AuthenticationMechanismOutcome outcome = null;
PasswordCredential credential = new PasswordCredential(password.toCharArray());
try {
IdentityManager identityManager = securityContext.getIdentityManager();
Account account = identityManager.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, name, true);
outcome = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
}
} finally {
if (outcome == AuthenticationMechanismOutcome.AUTHENTICATED) {
handleRedirectBack(exchange);
exchange.endExchange();
}
return outcome != null ? outcome : AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
InetSocketAddress peer = exchange.getSourceAddress();
if (isAllowed(peer.getAddress())) {
next.handleRequest(exchange);
} else {
exchange.setResponseCode(denyResponseCode);
exchange.endExchange();
}
}
示例10: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (disallowedMethods.contains(exchange.getRequestMethod())) {
exchange.setResponseCode(StatusCodes.METHOD_NOT_ALLOWED);
exchange.endExchange();
} else {
next.handleRequest(exchange);
}
}
示例11: report
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void report(HttpServerExchange exchange) {
User user = exchange.getAttachment(AuthReader.USER);
if (user == null) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue xq = data.getFirst("x");
FormData.FormValue yq = data.getFirst("y");
FormData.FormValue idq = data.getFirst("id");
FormData.FormValue msgq = data.getFirst("message");
if (xq == null || yq == null || idq == null || msgq == null) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
int x = Integer.parseInt(xq.getValue());
int y = Integer.parseInt(yq.getValue());
int id = Integer.parseInt(idq.getValue());
if (x < 0 || x >= App.getWidth() || y < 0 || y >= App.getHeight()) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
DBPixelPlacement pxl = App.getDatabase().getPixelByID(id);
if (pxl.x != x || pxl.y != y) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
App.getDatabase().addReport(user.getId(), id, x, y, msgq.getValue());
exchange.setStatusCode(200);
}
示例12: temporary
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
default void temporary(HttpServerExchange exchange, String location) {
exchange.setStatusCode(StatusCodes.FOUND);
exchange.getResponseHeaders().put(Headers.LOCATION, location);
exchange.endExchange();
}
示例13: respond
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private void respond(HttpServerExchange exchange, int code, Object obj) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
exchange.setStatusCode(code);
exchange.getResponseSender().send(App.getGson().toJson(obj));
exchange.endExchange();
}
示例14: onException
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
cache.dereference();
exchange.endExchange();
}
示例15: referer
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
default void referer(HttpServerExchange exchange) {
exchange.setStatusCode(StatusCodes.FOUND);
exchange.getResponseHeaders().put(Headers.LOCATION, exchange.getRequestHeaders().get(Headers.REFERER, 0));
exchange.endExchange();
}