- java.lang.Object
-
- javax.xml.ws.spi.http.HttpExchange
-
public abstract class HttpExchange extends Object
This class encapsulates a HTTP request received and a response to be generated in one exchange. It provides methods for examining the request from the client, and for building and sending the response.A
HttpExchange
must be closed to free or reuse underlying resources. The effect of failing to close an exchange is undefined.- Since:
- JAX-WS 2.2
-
-
Field Summary
Fields Modifier and Type Field and Description static String
REQUEST_CIPHER_SUITE
Standard property: cipher suite value when the request is received over HTTPSstatic String
REQUEST_KEY_SIZE
Standard property: bit size of the algorithm when the request is received over HTTPSstatic String
REQUEST_X509CERTIFICATE
Standard property: A SSL certificate, if any, associated with the request
-
Constructor Summary
Constructors Constructor and Description HttpExchange()
-
Method Summary
Methods Modifier and Type Method and Description abstract void
addResponseHeader(String name, String value)
Adds a response header with the given name and value.abstract void
close()
This must be called to end an exchange.abstract Object
getAttribute(String name)
Returns an attribute that is associated with thisHttpExchange
.abstract Set<String>
getAttributeNames()
Gives all the attribute names that are associated with thisHttpExchange
.abstract String
getContextPath()
Returns the context path of all the endpoints in an application.abstract HttpContext
getHttpContext()
Returns aHttpContext
for this exchange.abstract InetSocketAddress
getLocalAddress()
Returns the unresolved local address on which the request was received.abstract String
getPathInfo()
Returns the extra path information that follows the web service path but precedes the query string in the request URI and will start with a "/" character.abstract String
getProtocol()
Returns the protocol string from the request in the form protocol/majorVersion.minorVersion.abstract String
getQueryString()
Returns the query string that is contained in the request URI after the path.abstract InetSocketAddress
getRemoteAddress()
Returns the unresolved address of the remote entity invoking this request.abstract InputStream
getRequestBody()
Returns a stream from which the request body can be read.abstract String
getRequestHeader(String name)
Returns the value of the specified request header.abstract Map<String,List<String>>
getRequestHeaders()
Returns an immutable Map containing the HTTP headers that were included with this request.abstract String
getRequestMethod()
Get the HTTP request methodabstract String
getRequestURI()
Returns the part of the request's URI from the protocol name up to the query string in the first line of the HTTP request.abstract OutputStream
getResponseBody()
Returns a stream to which the response body must be written.abstract Map<String,List<String>>
getResponseHeaders()
Returns a mutable Map into which the HTTP response headers can be stored and which will be transmitted as part of this response.abstract String
getScheme()
Returns the name of the scheme used to make this request, for example: http, or https.abstract Principal
getUserPrincipal()
Returns thePrincipal
that represents the authenticated user for thisHttpExchange
.abstract boolean
isUserInRole(String role)
Indicates whether an authenticated user is included in the specified logical "role".abstract void
setStatus(int status)
Sets the HTTP status code for the response.
-
-
-
Field Detail
-
REQUEST_CIPHER_SUITE
public static final String REQUEST_CIPHER_SUITE
Standard property: cipher suite value when the request is received over HTTPSType: String
- See Also:
- Constant Field Values
-
REQUEST_KEY_SIZE
public static final String REQUEST_KEY_SIZE
Standard property: bit size of the algorithm when the request is received over HTTPSType: Integer
- See Also:
- Constant Field Values
-
REQUEST_X509CERTIFICATE
public static final String REQUEST_X509CERTIFICATE
Standard property: A SSL certificate, if any, associated with the requestType: java.security.cert.X509Certificate[] The order of this array is defined as being in ascending order of trust. The first certificate in the chain is the one set by the client, the next is the one used to authenticate the first, and so on.
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRequestHeaders
public abstract Map<String,List<String>> getRequestHeaders()
Returns an immutable Map containing the HTTP headers that were included with this request. The keys in this Map will be the header names, while the values will be a List of Strings containing each value that was included (either for a header that was listed several times, or one that accepts a comma-delimited list of values on a single line). In either of these cases, the values for the header name will be presented in the order that they were included in the request.The keys in Map are case-insensitive.
- Returns:
- an immutable Map which can be used to access request headers
-
getRequestHeader
public abstract String getRequestHeader(String name)
Returns the value of the specified request header. If the request did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first header in the request. The header name is case-insensitive. This is a convienence method to get a header (instead of using thegetRequestHeaders()
).- Parameters:
name
- the name of the request header- Returns:
- returns the value of the requested header, or null if the request does not have a header of that name
-
getResponseHeaders
public abstract Map<String,List<String>> getResponseHeaders()
Returns a mutable Map into which the HTTP response headers can be stored and which will be transmitted as part of this response. The keys in the Map will be the header names, while the values must be a List of Strings containing each value that should be included multiple times (in the order that they should be included).The keys in Map are case-insensitive.
- Returns:
- a mutable Map which can be used to set response headers.
-
addResponseHeader
public abstract void addResponseHeader(String name, String value)
Adds a response header with the given name and value. This method allows a response header to have multiple values. This is a convenience method to add a response header(instead of using thegetResponseHeaders()
).- Parameters:
name
- the name of the headervalue
- the additional header value. If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)- See Also:
getResponseHeaders()
-
getRequestURI
public abstract String getRequestURI()
Returns the part of the request's URI from the protocol name up to the query string in the first line of the HTTP request. Container doesn't decode this string.- Returns:
- the request URI
-
getContextPath
public abstract String getContextPath()
Returns the context path of all the endpoints in an application. This path is the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. If this method returns "", the request is for default context. The container does not decode this string.Context path is used in computing the endpoint address. See
HttpContext.getPath()
- Returns:
- context path of all the endpoints in an application
- See Also:
HttpContext.getPath()
-
getRequestMethod
public abstract String getRequestMethod()
Get the HTTP request method- Returns:
- the request method
-
getHttpContext
public abstract HttpContext getHttpContext()
Returns aHttpContext
for this exchange. Container matches the request with the associated Endpoint's HttpContext- Returns:
- the HttpContext for this exchange
-
close
public abstract void close() throws IOException
This must be called to end an exchange. Container takes care of closing request and response streams. This must be called so that the container can free or reuse underlying resources.- Throws:
IOException
- if any i/o error
-
getRequestBody
public abstract InputStream getRequestBody() throws IOException
Returns a stream from which the request body can be read. Multiple calls to this method will return the same stream.- Returns:
- the stream from which the request body can be read.
- Throws:
IOException
- if any i/o error during request processing
-
getResponseBody
public abstract OutputStream getResponseBody() throws IOException
Returns a stream to which the response body must be written.setStatus(int)
) must be called prior to calling this method. Multiple calls to this method (for the same exchange) will return the same stream.- Returns:
- the stream to which the response body is written
- Throws:
IOException
- if any i/o error during response processing
-
setStatus
public abstract void setStatus(int status)
Sets the HTTP status code for the response.This method must be called prior to calling
getResponseBody()
.- Parameters:
status
- the response code to send- See Also:
getResponseBody()
-
getRemoteAddress
public abstract InetSocketAddress getRemoteAddress()
Returns the unresolved address of the remote entity invoking this request.- Returns:
- the InetSocketAddress of the caller
-
getLocalAddress
public abstract InetSocketAddress getLocalAddress()
Returns the unresolved local address on which the request was received.- Returns:
- the InetSocketAddress of the local interface
-
getProtocol
public abstract String getProtocol()
Returns the protocol string from the request in the form protocol/majorVersion.minorVersion. For example, "HTTP/1.1"- Returns:
- the protocol string from the request
-
getScheme
public abstract String getScheme()
Returns the name of the scheme used to make this request, for example: http, or https.- Returns:
- name of the scheme used to make this request
-
getPathInfo
public abstract String getPathInfo()
Returns the extra path information that follows the web service path but precedes the query string in the request URI and will start with a "/" character.This can be used for
MessageContext.PATH_INFO
- Returns:
- decoded extra path information of web service. It is the path that comes after the web service path but before the query string in the request URI null if there is no extra path in the request URI
-
getQueryString
public abstract String getQueryString()
Returns the query string that is contained in the request URI after the path.This can be used for
MessageContext.QUERY_STRING
- Returns:
- undecoded query string of request URI, or null if the request URI doesn't have one
-
getAttribute
public abstract Object getAttribute(String name)
Returns an attribute that is associated with thisHttpExchange
. JAX-WS handlers and endpoints may then access the attribute viaMessageContext
.Servlet containers must expose
MessageContext.SERVLET_CONTEXT
,MessageContext.SERVLET_REQUEST
, andMessageContext.SERVLET_RESPONSE
as attributes.If the request has been received by the container using HTTPS, the following information must be exposed as attributes. These attributes are
REQUEST_CIPHER_SUITE
, andREQUEST_KEY_SIZE
. If there is a SSL certificate associated with the request, it must be exposed usingREQUEST_X509CERTIFICATE
- Parameters:
name
- attribute name- Returns:
- the attribute value, or null if the attribute doesn't exist
-
getAttributeNames
public abstract Set<String> getAttributeNames()
Gives all the attribute names that are associated with thisHttpExchange
.- Returns:
- set of all attribute names
- See Also:
getAttribute(String)
-
getUserPrincipal
public abstract Principal getUserPrincipal()
Returns thePrincipal
that represents the authenticated user for thisHttpExchange
.- Returns:
- Principal for an authenticated user, or null if not authenticated
-
isUserInRole
public abstract boolean isUserInRole(String role)
Indicates whether an authenticated user is included in the specified logical "role".- Parameters:
role
- specifies the name of the role- Returns:
- true if the user making this request belongs to a given role
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/xml/ws/spi/http/HttpExchange.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.