All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.undertow.websockets.jsr.handshake.WebSocketHttpExchange Maven / Gradle / Ivy

There is a newer version: 4.0.0.Alpha2
Show newest version
/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2018 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.undertow.websockets.jsr.handshake;

import java.io.Closeable;
import java.security.Principal;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

import io.undertow.util.AttachmentKey;


/**
 * An abstraction for a Http exchange. Undertow uses 3 different types of exchanges:
 * 

* - async * - blocking * - servlet *

* This class provides a way to operate on the underling exchange while providing the * correct semantics regardless of the underlying exchange type. *

* The main use case for this is web sockets. Web sockets should be able to perform * a handshake regardless of the nature of the underlying request, while still respecting * servlet filters, security etc. * * @author Stuart Douglas */ public interface WebSocketHttpExchange extends Closeable { void putAttachment(final AttachmentKey key, T value); T getAttachment(final AttachmentKey key); /** * gets the first request header with the specified name * * @param headerName The header name * @return The header value, or null */ String getRequestHeader(final String headerName); /** * @return An unmodifiable map of request headers */ Map> getRequestHeaders(); /** * get a response header * * @param headerName The header name * @return The header value, or null */ String getResponseHeader(final String headerName); /** * @return An unmodifiable map of response headers */ Map> getResponseHeaders(); /** * Sets the response headers */ void setResponseHeaders(final Map> headers); /** * Set a response header * * @param headerName The header name * @param headerValue The header value */ void setResponseHeader(final String headerName, final String headerValue); /** * Upgrade the underlying channel * * @param listener */ void upgradeChannel(Consumer listener); /** * End the exchange normally. If this is a blocking exchange this may be a noop, and the exchange * will actually end when the call stack returns */ void endExchange(); /** * Forcibly close the exchange. */ void close(); /** * Get the request scheme, usually http or https * * @return The request scheme */ String getRequestScheme(); /** * @return The request URI, including the query string */ String getRequestURI(); /** * @return The query string */ String getQueryString(); /** * Gets the session, if any * * @return The session object, or null */ Object getSession(); Map> getRequestParameters(); Principal getUserPrincipal(); boolean isUserInRole(String role); Executor getExecutor(); }