本文整理汇总了Java中io.undertow.util.HeaderMap.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderMap.getFirst方法的具体用法?Java HeaderMap.getFirst怎么用?Java HeaderMap.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.util.HeaderMap
的用法示例。
在下文中一共展示了HeaderMap.getFirst方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beginPart
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public void beginPart(final HeaderMap headers) {
this.currentFileSize = 0;
this.headers = headers;
final String disposition = headers.getFirst(Headers.CONTENT_DISPOSITION);
if (disposition != null) {
if (disposition.startsWith("form-data")) {
currentName = Headers.extractQuotedValueFromHeader(disposition, "name");
fileName = Headers.extractQuotedValueFromHeader(disposition, "filename");
if (fileName != null) {
try {
file = File.createTempFile("undertow", "upload", tempFileLocation);
createdFiles.add(file);
fileChannel = exchange.getConnection().getWorker().getXnio().openFile(file, FileAccess.READ_WRITE);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}
示例2: handleRequest
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if(exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
if(logger.isTraceEnabled()) {
logger.trace("Attach CORS headers");
}
HeaderMap httpHeaders = exchange.getResponseHeaders();
HeaderMap requestHeaders = exchange.getRequestHeaders();
String methods = requestHeaders.getFirst("Access-Control-Request-Method");
if(methods != null) {
httpHeaders.addFirst(new HttpString("Access-Control-Allow-Methods"), methods);
}
String headers = requestHeaders.getFirst("Access-Control-Request-Headers");
if(headers != null) {
httpHeaders.addFirst(new HttpString("Access-Control-Allow-Headers"), headers);
}
httpHeaders.addFirst(new HttpString("Access-Control-Allow-Credentials"), "true");
}
示例3: extractCharset
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private String extractCharset(HeaderMap headers) {
String contentType = headers.getFirst(Headers.CONTENT_TYPE);
if (contentType == null) {
return null;
}
String value = Headers.extractQuotedValueFromHeader(contentType, "charset");
if(value != null) {
return value;
}
return ISO_8859_1;
}
示例4: parse
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
public void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog) throws Throwable {
HeaderMap headers = exchange.getRequestHeaders();
for (HeaderValues header : headers) {
logger.debug("[request:header] {}={}", header.getHeaderName(), header.toArray());
}
String remoteAddress = exchange.getSourceAddress().getAddress().getHostAddress();
logger.debug("[request] remoteAddress={}", remoteAddress);
request.clientIP = clientIPParser.parse(remoteAddress, headers.getFirst(Headers.X_FORWARDED_FOR));
actionLog.context("clientIP", request.clientIP);
String requestScheme = exchange.getRequestScheme();
logger.debug("[request] requestScheme={}", requestScheme);
String xForwardedProto = headers.getFirst(Headers.X_FORWARDED_PROTO);
request.scheme = xForwardedProto != null ? xForwardedProto : requestScheme;
int requestPort = requestPort(exchange.getRequestHeaders().getFirst(Headers.HOST), request.scheme, exchange);
request.port = port(requestPort, headers.getFirst(Headers.X_FORWARDED_PORT));
request.requestURL = requestURL(request, exchange);
actionLog.context("requestURL", request.requestURL);
logger.debug("[request] path={}", request.path());
String userAgent = headers.getFirst(Headers.USER_AGENT);
if (userAgent != null) actionLog.context("userAgent", userAgent);
request.method = httpMethod(exchange.getRequestMethod().toString());
actionLog.context("method", request.method()); // for public site, there will be sniff requests from various sources. as it throws exception with unsupported method, so to log method at last, we can see details (headers) in trace for those illegal requests
parseQueryParams(request, exchange.getQueryParameters());
if (request.method == HTTPMethod.POST || request.method == HTTPMethod.PUT || request.method == HTTPMethod.PATCH) {
String contentType = headers.getFirst(Headers.CONTENT_TYPE);
request.contentType = contentType == null ? null : ContentType.parse(contentType);
parseBody(request, exchange);
}
}
示例5: constructUrl
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
/**
* Based on the current request represented by the HttpExchange construct a complete URL for the supplied path.
*
* @param exchange - The current HttpExchange
* @param path - The path to include in the constructed URL
* @return The constructed URL
*/
public static String constructUrl(final HttpServerExchange exchange, final String path) {
final HeaderMap headers = exchange.getRequestHeaders();
String host = headers.getFirst(HOST);
String protocol = exchange.getConnection().getSslSessionInfo() != null ? "https" : "http";
return protocol + "://" + host + path;
}
示例6: verifyHandshake
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private static void verifyHandshake(ClientResponse response, String secretKey) throws IOException {
HeaderMap headers = response.getResponseHeaders();
String acceptValue = headers.getFirst(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT);
if (acceptValue == null) {
throw new IOException(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT + " header not found");
}
String expectedResponse = HandshakeUtil.createExpectedResponse(secretKey);
if(!acceptValue.equals(expectedResponse)) {
throw new IOException(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT + " value of " + acceptValue + " did not match expected " + expectedResponse);
}
}
示例7: reservationCheck
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
protected boolean reservationCheck(HttpServerExchange exchange) {
HeaderMap requestHeaders = exchange.getRequestHeaders();
String origin = requestHeaders.getFirst(CorsHeaders.ORIGIN);
if (cors.getAllowedOrigins().contains("*") || cors.getAllowedOrigins().contains(origin)) {
HeaderMap responseHeaders = exchange.getResponseHeaders();
responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_ORIGIN), origin);
String value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
if (value != null) {
responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_HEADERS), value);
}
value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS);
if (value != null) {
responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS), value);
}
value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_REQUEST_METHOD);
if (value != null) {
responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_METHODS), value);
}
}
String uri = exchange.getRequestURI();
if (uri.indexOf(path + "/") != 0) {
exchange.setStatusCode(404);
return false;
}
final String subscriptionId = uri.substring(path.length() + 1);
if (subscriptionId.isEmpty()) {
exchange.setStatusCode(404);
return false;
}
EventReservationsHandler.Reservation reservation = eventReservationsHandler.existsReservation(subscriptionId);
if (reservation == null) {
exchange.setStatusCode(404);
return false;
}
return true;
}
示例8: getHeader
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public String getHeader(final String name) {
HeaderMap headers = exchange.getRequestHeaders();
return headers.getFirst(name);
}
示例9: setupRequest
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
public static void setupRequest(final HttpServerExchange exchange) {
final HeaderMap requestHeaders = exchange.getRequestHeaders();
final String connectionHeader = requestHeaders.getFirst(Headers.CONNECTION);
final String transferEncodingHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
final String contentLengthHeader = requestHeaders.getFirst(Headers.CONTENT_LENGTH);
final HttpServerConnection connection = (HttpServerConnection) exchange.getConnection();
//if we are already using the pipelineing buffer add it to the exchange
PipeliningBufferingStreamSinkConduit pipeliningBuffer = connection.getPipelineBuffer();
if (pipeliningBuffer != null) {
pipeliningBuffer.setupPipelineBuffer(exchange);
}
ConduitStreamSourceChannel sourceChannel = connection.getChannel().getSourceChannel();
sourceChannel.setConduit(connection.getReadDataStreamSourceConduit());
boolean persistentConnection = persistentConnection(exchange, connectionHeader);
if (transferEncodingHeader == null && contentLengthHeader == null) {
if (persistentConnection
&& connection.getExtraBytes() != null
&& pipeliningBuffer == null
&& connection.getUndertowOptions().get(UndertowOptions.BUFFER_PIPELINED_DATA, false)) {
pipeliningBuffer = new PipeliningBufferingStreamSinkConduit(connection.getOriginalSinkConduit(), connection.getBufferPool());
connection.setPipelineBuffer(pipeliningBuffer);
pipeliningBuffer.setupPipelineBuffer(exchange);
}
// no content - immediately start the next request, returning an empty stream for this one
Connectors.terminateRequest(exchange);
} else {
persistentConnection = handleRequestEncoding(exchange, transferEncodingHeader, contentLengthHeader, connection, pipeliningBuffer, persistentConnection);
}
exchange.setPersistent(persistentConnection);
if (!exchange.isRequestComplete() || connection.getExtraBytes() != null) {
//if there is more data we suspend reads
sourceChannel.setReadListener(null);
sourceChannel.suspendReads();
}
}
示例10: createSinkConduit
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
static StreamSinkConduit createSinkConduit(final HttpServerExchange exchange) {
DateUtils.addDateHeaderIfRequired(exchange);
boolean headRequest = exchange.getRequestMethod().equals(Methods.HEAD);
HttpServerConnection serverConnection = (HttpServerConnection) exchange.getConnection();
HttpResponseConduit responseConduit = serverConnection.getResponseConduit();
responseConduit.reset(exchange);
StreamSinkConduit channel = responseConduit;
if (headRequest) {
//if this is a head request we add a head channel underneath the content encoding channel
//this will just discard the data
//we still go through with the rest of the logic, to make sure all headers are set correctly
channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
} else if(!Connectors.isEntityBodyAllowed(exchange)) {
//we are not allowed to send an entity body for some requests
exchange.getResponseHeaders().remove(Headers.CONTENT_LENGTH);
exchange.getResponseHeaders().remove(Headers.TRANSFER_ENCODING);
channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
}
final HeaderMap responseHeaders = exchange.getResponseHeaders();
// test to see if we're still persistent
String connection = responseHeaders.getFirst(Headers.CONNECTION);
if (!exchange.isPersistent()) {
responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
} else if (exchange.isPersistent() && connection != null) {
if (HttpString.tryFromString(connection).equals(Headers.CLOSE)) {
exchange.setPersistent(false);
}
} else if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true)) {
responseHeaders.put(Headers.CONNECTION, Headers.KEEP_ALIVE.toString());
}
//according to the HTTP RFC we should ignore content length if a transfer coding is specified
final String transferEncodingHeader = responseHeaders.getLast(Headers.TRANSFER_ENCODING);
if(transferEncodingHeader == null) {
final String contentLengthHeader = responseHeaders.getFirst(Headers.CONTENT_LENGTH);
if (contentLengthHeader != null) {
StreamSinkConduit res = handleFixedLength(exchange, headRequest, channel, responseHeaders, contentLengthHeader, serverConnection);
if (res != null) {
return res;
}
}
}
return handleResponseConduit(exchange, headRequest, channel, responseHeaders, terminateResponseListener(exchange), transferEncodingHeader);
}
示例11: handleRequest
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
logManager.begin("=== http transaction begin ===");
RequestImpl request = new RequestImpl(exchange, requestBeanMapper);
try {
webContext.initialize(request); // initialize webContext at beginning, the customerErrorHandler in errorHandler may use it if any exception
ActionLog actionLog = logManager.currentActionLog();
requestParser.parse(request, exchange, actionLog);
request.session = sessionManager.load(request);
HeaderMap headers = exchange.getRequestHeaders();
String client = headers.getFirst(HTTPServerHandler.HEADER_CLIENT);
if (client != null) actionLog.context("client", client);
actionLog.refId(headers.getFirst(HTTPServerHandler.HEADER_REF_ID));
ControllerHolder controller = route.get(request.path(), request.method(), request.pathParams, actionLog);
actionLog.action(controller.action);
actionLog.context("controller", controller.controllerInfo);
logger.debug("controllerClass={}", controller.controller.getClass().getCanonicalName());
// trigger trace after action is determined due to trace log use action as part of path, is there better way?
if ("true".equals(headers.getFirst(HEADER_TRACE))) {
actionLog.trace = true;
}
Response response = new InvocationImpl(controller, interceptors, request, webContext).proceed();
sessionManager.save(request, response);
responseHandler.render((ResponseImpl) response, exchange);
} catch (Throwable e) {
logManager.logError(e);
errorHandler.handleError(e, exchange, request);
} finally {
webContext.cleanup();
logManager.end("=== http transaction end ===");
}
}