當前位置: 首頁>>代碼示例>>Java>>正文


Java Headers類代碼示例

本文整理匯總了Java中io.undertow.util.Headers的典型用法代碼示例。如果您正苦於以下問題:Java Headers類的具體用法?Java Headers怎麽用?Java Headers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Headers類屬於io.undertow.util包,在下文中一共展示了Headers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processRequest

import io.undertow.util.Headers; //導入依賴的package包/類
private void processRequest(final HttpServerExchange exchange) throws IOException {
	final ChannelInputStream cis = new ChannelInputStream(exchange.getRequestChannel());
	exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");

	final long beginningTime = System.currentTimeMillis();
	final String body = IOUtils.toString(cis, StandardCharsets.UTF_8);
	final AbstractResponse response = process(body, exchange.getSourceAddress());
	sendResponse(exchange, response, beginningTime);
}
 
開發者ID:AidosKuneen,項目名稱:aidos-node,代碼行數:10,代碼來源:API.java

示例2: handleRequest

import io.undertow.util.Headers; //導入依賴的package包/類
public static void handleRequest(HttpServerExchange exchange, final ServletRequestContext servletRequestContext, final Throwable exception) throws IOException {
    HttpServletRequestImpl req = servletRequestContext.getOriginalRequest();
    StringBuilder sb = new StringBuilder();
    //todo: make this good
    sb.append("<html><head><title>ERROR</title>");
    sb.append(ERROR_CSS);
    sb.append("</head><body><div class=\"header\"><div class=\"error-div\"></div><div class=\"error-text-div\">Error processing request</div></div>");
    writeLabel(sb, "Context Path", req.getContextPath());
    writeLabel(sb, "Servlet Path", req.getServletPath());
    writeLabel(sb, "Path Info", req.getPathInfo());
    writeLabel(sb, "Query String", req.getQueryString());
    sb.append("<b>Stack Trace</b><br/>");
    sb.append(escapeBodyText(exception.toString()));
    sb.append("<br/>");
    for(StackTraceElement element : exception.getStackTrace()) {
        sb.append(escapeBodyText(element.toString()));
        sb.append("<br/>");
    }
    sb.append("</body></html>");
    exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8");
    exchange.getResponseSender().send(sb.toString());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:ServletDebugPageHandler.java

示例3: loadBalancerHttpToHttps

import io.undertow.util.Headers; //導入依賴的package包/類
public static HttpHandler loadBalancerHttpToHttps(HttpHandler next) {
    return (HttpServerExchange exchange) -> {
        HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
        String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
        if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
            log.debug("non https switching to https {}", currentUrl.host());
            HttpUrl newUrl = currentUrl.newBuilder()
               .scheme("https")
               .port(443)
               .build();
            exchange.setStatusCode(301);
            exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
            exchange.endExchange();
            return;
        }

        next.handleRequest(exchange);
    };
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:20,代碼來源:CustomHandlers.java

示例4: handleRequest

import io.undertow.util.Headers; //導入依賴的package包/類
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (isConfidential(exchange) || !confidentialityRequired(exchange)) {
        next.handleRequest(exchange);
    } else {
        try {
            URI redirectUri = getRedirectURI(exchange);

            exchange.setResponseCode(StatusCodes.FOUND);
            exchange.getResponseHeaders().put(Headers.LOCATION, redirectUri.toString());
        } catch (Exception e) {
            UndertowLogger.REQUEST_LOGGER.exceptionProcessingRequest(e);
            exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
        }
        exchange.endExchange();
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AbstractConfidentialityHandler.java

示例5: sendRedirect

import io.undertow.util.Headers; //導入依賴的package包/類
@Override
public void sendRedirect(final String location) throws IOException {
    if (responseStarted()) {
        throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
    }
    resetBuffer();
    setStatus(StatusCodes.FOUND);
    String realPath;
    if (location.contains("://")) {//absolute url
        exchange.getResponseHeaders().put(Headers.LOCATION, location);
    } else {
        if (location.startsWith("/")) {
            realPath = location;
        } else {
            String current = exchange.getRelativePath();
            int lastSlash = current.lastIndexOf("/");
            if (lastSlash != -1) {
                current = current.substring(0, lastSlash + 1);
            }
            realPath = CanonicalPathUtils.canonicalize(servletContext.getContextPath() + current + location);
        }
        String loc = exchange.getRequestScheme() + "://" + exchange.getHostAndPort() + realPath;
        exchange.getResponseHeaders().put(Headers.LOCATION, loc);
    }
    responseDone();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:HttpServletResponseImpl.java

示例6: displayStackTraces

import io.undertow.util.Headers; //導入依賴的package包/類
public boolean displayStackTraces() {
    ServletStackTraces mode = deployment.getDeploymentInfo().getServletStackTraces();
    if (mode == ServletStackTraces.NONE) {
        return false;
    } else if (mode == ServletStackTraces.ALL) {
        return true;
    } else {
        InetSocketAddress localAddress = getExchange().getSourceAddress();
        if(localAddress == null) {
            return false;
        }
        InetAddress address = localAddress.getAddress();
        if(address == null) {
            return false;
        }
        if(!address.isLoopbackAddress()) {
            return false;
        }
        return !getExchange().getRequestHeaders().contains(Headers.X_FORWARDED_FOR);
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:ServletRequestContext.java

示例7: prepareResponseChannel

import io.undertow.util.Headers; //導入依賴的package包/類
private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) {
    String encoding = response.getResponseHeaders().getLast(TRANSFER_ENCODING);
    boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding));
    String length = response.getResponseHeaders().getFirst(CONTENT_LENGTH);
    if (exchange.getRequest().getMethod().equals(Methods.HEAD)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else if (chunked) {
        connection.getSourceChannel().setConduit(new ChunkedStreamSourceConduit(connection.getSourceChannel().getConduit(), pushBackStreamSourceConduit, bufferPool, responseFinishedListener, exchange));
    } else if (length != null) {
        try {
            long contentLength = Long.parseLong(length);
            connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener));
        } catch (NumberFormatException e) {
            handleError(new IOException(e));
            throw e;
        }
    } else if (response.getProtocol().equals(Protocols.HTTP_1_1)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else {
        state |= CLOSE_REQ;
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:HttpClientConnection.java

示例8: redirector

import io.undertow.util.Headers; //導入依賴的package包/類
public static HttpHandler redirector(HttpHandler next) {
    return (HttpServerExchange exchange) -> {
        HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
        String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
        String host = currentUrl.host();
        boolean redirect = false;

        Builder newUrlBuilder = currentUrl.newBuilder();

        if (host.equals("stubbornjava.com")) {
            host = "www." + host;
            newUrlBuilder.host(host);
            redirect = true;
            logger.debug("Host {} does not start with www redirecting to {}", currentUrl.host(), host);
        }

        if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
            logger.debug("non https switching to https", currentUrl.host(), host);
            newUrlBuilder.scheme("https")
                         .port(443);
            redirect = true;
        }

        if (redirect) {
            HttpUrl newUrl = newUrlBuilder.build();
            exchange.setStatusCode(301);
            exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
            exchange.endExchange();
            return;
        }
        next.handleRequest(exchange);
    };
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:34,代碼來源:PageRoutes.java

示例9: handleFixedLength

import io.undertow.util.Headers; //導入依賴的package包/類
private static StreamSinkConduit handleFixedLength(HttpServerExchange exchange, boolean headRequest, StreamSinkConduit channel, HeaderMap responseHeaders, String contentLengthHeader, HttpServerConnection connection) {
    try {
        final long contentLength = parsePositiveLong(contentLengthHeader);
        if (headRequest) {
            return channel;
        }
        // fixed-length response
        ServerFixedLengthStreamSinkConduit fixed = connection.getFixedLengthStreamSinkConduit();
        fixed.reset(contentLength, exchange);
        return fixed;
    } catch (NumberFormatException e) {
        //we just fix it for them
        responseHeaders.remove(Headers.CONTENT_LENGTH);
    }
    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:HttpTransferEncoding.java

示例10: handleExplicitTransferEncoding

import io.undertow.util.Headers; //導入依賴的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

示例11: requiresContinueResponse

import io.undertow.util.Headers; //導入依賴的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

示例12: sendContinueResponseBlocking

import io.undertow.util.Headers; //導入依賴的package包/類
/**
 * Sends a continue response using blocking IO
 *
 * @param exchange The exchange
 */
public static void sendContinueResponseBlocking(final HttpServerExchange exchange) throws IOException {
    if (!exchange.isResponseChannelAvailable()) {
        throw UndertowMessages.MESSAGES.cannotSendContinueResponse();
    }
    if(exchange.getAttachment(ALREADY_SENT) != null) {
        return;
    }
    HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange);
    exchange.putAttachment(ALREADY_SENT, true);
    newExchange.setResponseCode(StatusCodes.CONTINUE);
    newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
    newExchange.startBlocking();
    newExchange.getOutputStream().close();
    newExchange.getInputStream().close();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:HttpContinue.java

示例13: create

import io.undertow.util.Headers; //導入依賴的package包/類
@Override
public FormDataParser create(final HttpServerExchange exchange)  {
    String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
    if (forceCreation || (mimeType != null && mimeType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED))) {

        String charset = defaultEncoding;
        String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
        if (contentType != null) {
            String cs = Headers.extractQuotedValueFromHeader(contentType, "charset");
            if (cs != null) {
                charset = cs;
            }
        }
        return new FormEncodedDataParser(charset, exchange);
    }
    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:FormEncodedDataDefinition.java

示例14: sendRequestedBlobs

import io.undertow.util.Headers; //導入依賴的package包/類
/**
 * Serve static resource for the directory listing
 *
 * @param exchange The exchange
 * @return true if resources were served
 */
public static boolean sendRequestedBlobs(HttpServerExchange exchange) {
    ByteBuffer buffer = null;
    String type = null;
    if ("css".equals(exchange.getQueryString())) {
        buffer = Blobs.FILE_CSS_BUFFER.duplicate();
        type = "text/css";
    } else if ("js".equals(exchange.getQueryString())) {
        buffer = Blobs.FILE_JS_BUFFER.duplicate();
        type = "application/javascript";
    }

    if (buffer != null) {
        exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(buffer.limit()));
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, type);
        if (Methods.HEAD.equals(exchange.getRequestMethod())) {
            exchange.endExchange();
            return true;
        }
        exchange.getResponseSender().send(buffer);

        return true;
    }

    return false;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:DirectoryUtils.java

示例15: handleRequest

import io.undertow.util.Headers; //導入依賴的package包/類
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    final String hostHeader = exchange.getRequestHeaders().getFirst(Headers.HOST);
    if (hostHeader != null) {
        String host;
        if (hostHeader.contains(":")) { //header can be in host:port format
            host = hostHeader.substring(0, hostHeader.lastIndexOf(":"));
        } else {
            host = hostHeader;
        }
        final HttpHandler handler = hosts.get(host);
        if (handler != null) {
            handler.handleRequest(exchange);
            return;
        }
    }
    defaultHandler.handleRequest(exchange);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:NameVirtualHostHandler.java


注:本文中的io.undertow.util.Headers類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。