本文整理汇总了Java中io.undertow.server.HttpServerExchange.getAttachment方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.getAttachment方法的具体用法?Java HttpServerExchange.getAttachment怎么用?Java HttpServerExchange.getAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.getAttachment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (context != null) {
ServletRequest req = context.getServletRequest();
if (req instanceof HttpServletRequest) {
HttpSession session = ((HttpServletRequest) req).getSession(false);
if (session != null) {
Object result = session.getAttribute(attributeName);
if (result != null) {
return result.toString();
}
}
}
}
return null;
}
示例2: 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;
}
示例3: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletRequest request = servletRequestContext.getServletRequest();
ServletResponse response = servletRequestContext.getServletResponse();
DispatcherType dispatcher = servletRequestContext.getDispatcherType();
Boolean supported = asyncSupported.get(dispatcher);
if(supported != null && ! supported) {
exchange.putAttachment(AsyncContextImpl.ASYNC_SUPPORTED, false );
}
final List<ManagedFilter> filters = this.filters.get(dispatcher);
if(filters == null) {
next.handleRequest(exchange);
} else {
final FilterChainImpl filterChain = new FilterChainImpl(exchange, filters, next, allowNonStandardWrappers);
filterChain.doFilter(request, response);
}
}
示例4: 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();
}
}
示例5: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final String path = exchange.getRelativePath();
SecurityPathMatch securityMatch = securityPathMatches.getSecurityInfo(path, exchange.getRequestMethod().toString());
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
List<SingleConstraintMatch> list = servletRequestContext.getRequiredConstrains();
if (list == null) {
servletRequestContext.setRequiredConstrains(list = new ArrayList<>());
}
list.add(securityMatch.getMergedConstraint());
TransportGuaranteeType type = servletRequestContext.getTransportGuarenteeType();
if (type == null || type.ordinal() < securityMatch.getTransportGuaranteeType().ordinal()) {
servletRequestContext.setTransportGuarenteeType(securityMatch.getTransportGuaranteeType());
}
next.handleRequest(exchange);
}
示例6: handleExplicitTransferEncoding
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private static StreamSinkConduit handleExplicitTransferEncoding(HttpServerExchange exchange, StreamSinkConduit channel, ConduitListener<StreamSinkConduit> finishListener, HeaderMap responseHeaders, String transferEncodingHeader, boolean headRequest) {
HttpString transferEncoding = new HttpString(transferEncodingHeader);
if (transferEncoding.equals(Headers.CHUNKED)) {
if (headRequest) {
return channel;
}
Boolean preChunked = exchange.getAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE);
if(preChunked != null && preChunked) {
return new PreChunkedStreamSinkConduit(channel, finishListener, exchange);
} else {
return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
}
} else {
if (headRequest) {
return channel;
}
log.trace("Cancelling persistence because response is identity with no content length");
// make it not persistent - very unfortunate for the next request handler really...
exchange.setPersistent(false);
responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
return new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
}
}
示例7: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
// get the request parameters as a Map<String, Object>
@SuppressWarnings("unchecked")
Map<String, Object> requestParameters = (Map<String, Object>)exchange.getAttachment(GraphqlUtil.GRAPHQL_PARAMS);
if(logger.isDebugEnabled()) logger.debug("requestParameters: " + requestParameters);
GraphQL graphQL = GraphQL.newGraphQL(schema).build();
String query = (String)requestParameters.get("query");
if(query == null) {
Status status = new Status(STATUS_GRAPHQL_MISSING_QUERY);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
return;
}
@SuppressWarnings("unchecked")
Map<String, Object> variables = (Map<String, Object>)requestParameters.get("variables");
if(variables == null) {
variables = new HashMap<>();
}
String operationName = (String)requestParameters.get("operationName");
ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(query).operationName(operationName).context(exchange).root(exchange).variables(variables).build();
ExecutionResult executionResult = graphQL.execute(executionInput);
Map<String, Object> result = new HashMap<>();
if (executionResult.getErrors().size() > 0) {
result.put("errors", executionResult.getErrors());
logger.error("Errors: {}", executionResult.getErrors());
} else {
result.put("data", executionResult.getData());
}
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
}
示例8: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) {
@SuppressWarnings("unchecked")
Map<String, Object> requestParameters = (Map<String, Object>)exchange.getAttachment(GraphqlUtil.GRAPHQL_PARAMS);
if(logger.isDebugEnabled()) logger.debug("requestParameters: " + requestParameters);
String graphiql = RenderGraphiQL.render(requestParameters, null);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8");
exchange.getResponseSender().send(graphiql);
}
示例9: getRollbackTime
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private int getRollbackTime(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue rollback = data.getFirst("rollback_time");
String rollback_int = "0";
if (rollback != null) {
rollback_int = rollback.getValue();
}
return Integer.parseInt(rollback_int);
}
示例10: authenticate
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
AuthenticatedSessionManager sessionManager = exchange.getAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY);
if (sessionManager != null) {
return runCached(exchange, securityContext, sessionManager);
} else {
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
}
示例11: resolve
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public boolean resolve(final HttpServerExchange value) {
final String relativePath = value.getRelativePath();
PathMatcher.PathMatch<Boolean> result = pathMatcher.match(relativePath);
boolean matches = result.getValue() == Boolean.TRUE;
if(matches) {
Map<String, Object> context = value.getAttachment(PREDICATE_CONTEXT);
if(context != null) {
context.put("remaining", result.getRemaining());
}
}
return matches;
}
示例12: writeAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
Map<String, Object> context = exchange.getAttachment(Predicate.PREDICATE_CONTEXT);
if (context != null) {
context.put(name, newValue);
}
}
示例13: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletInfo servletInfo = context.getCurrentServlet().getManagedServlet().getServletInfo();
MetricsHandler handler = servletHandlers.get(servletInfo.getName());
if(handler != null) {
handler.handleRequest(exchange);
} else {
next.handleRequest(exchange);
}
}
示例14: readAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (context != null) {
ServletRequest req = context.getServletRequest();
if (req instanceof HttpServletRequest) {
HttpSession session = ((HttpServletRequest) req).getSession(false);
if (session != null) {
return session.getId();
}
}
}
return null;
}
示例15: 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);
}