当前位置: 首页>>代码示例>>Java>>正文


Java HttpServerExchange.getAttachment方法代码示例

本文整理汇总了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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletSessionAttribute.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:HttpContinue.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:FilterHandler.java

示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ProxyHandler.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ServletSecurityConstraintHandler.java

示例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));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HttpTransferEncoding.java

示例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));
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:33,代码来源:GraphqlPostHandler.java

示例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);
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:10,代码来源:GraphqlGetHandler.java

示例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);
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:10,代码来源:WebHandler.java

示例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;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CachedAuthenticatedSessionMechanism.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:PathPrefixPredicate.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:PredicateContextAttribute.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:MetricsChainHandler.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ServletSessionIdAttribute.java

示例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);
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:39,代码来源:WebHandler.java


注:本文中的io.undertow.server.HttpServerExchange.getAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。