Class ServletUpgradeResponse
- java.lang.Object
-
- org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse
-
- All Implemented Interfaces:
UpgradeResponse
- Direct Known Subclasses:
ServletWebSocketResponse
public class ServletUpgradeResponse extends java.lang.Object implements UpgradeResponse
Servlet Specific UpgradeResponse implementation.
-
-
Constructor Summary
Constructors Constructor Description ServletUpgradeResponse(javax.servlet.http.HttpServletResponse response)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHeader(java.lang.String name, java.lang.String value)
Add a header value to the response.void
complete()
java.lang.String
getAcceptedSubProtocol()
Get the accepted WebSocket protocol.java.util.List<ExtensionConfig>
getExtensions()
Get the list of extensions that should be used for the websocket.java.lang.String
getHeader(java.lang.String name)
Get a header valuejava.util.Set<java.lang.String>
getHeaderNames()
Get the header namesjava.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaders()
Get the headers mapjava.util.List<java.lang.String>
getHeaders(java.lang.String name)
Get the multi-value header valueint
getStatusCode()
Get the HTTP Response Status Codejava.lang.String
getStatusReason()
Get the HTTP Response Status Reasonboolean
isCommitted()
boolean
isExtensionsNegotiated()
boolean
isSubprotocolNegotiated()
boolean
isSuccess()
Test if upgrade response is successful.void
sendError(int statusCode, java.lang.String message)
void
sendForbidden(java.lang.String message)
Issue a forbidden upgrade response.void
setAcceptedSubProtocol(java.lang.String protocol)
Set the accepted WebSocket Protocol.void
setExtensions(java.util.List<ExtensionConfig> configs)
Set the list of extensions that are approved for use with this websocket.void
setHeader(java.lang.String name, java.lang.String value)
Set a headervoid
setStatusCode(int statusCode)
Set the HTTP Response status codevoid
setStatusReason(java.lang.String statusReason)
Set the HTTP Response status reason phrasevoid
setSuccess(boolean success)
Set the success of the upgrade response.java.lang.String
toString()
-
-
-
Method Detail
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)
Description copied from interface:UpgradeResponse
Add a header value to the response.- Specified by:
addHeader
in interfaceUpgradeResponse
- Parameters:
name
- the header namevalue
- the header value
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)
Description copied from interface:UpgradeResponse
Set a headerOverrides previous value of header (if set)
- Specified by:
setHeader
in interfaceUpgradeResponse
- Parameters:
name
- the header namevalue
- the header value
-
complete
public void complete()
-
getAcceptedSubProtocol
public java.lang.String getAcceptedSubProtocol()
Description copied from interface:UpgradeResponse
Get the accepted WebSocket protocol.- Specified by:
getAcceptedSubProtocol
in interfaceUpgradeResponse
- Returns:
- the accepted WebSocket protocol.
-
getExtensions
public java.util.List<ExtensionConfig> getExtensions()
Description copied from interface:UpgradeResponse
Get the list of extensions that should be used for the websocket.- Specified by:
getExtensions
in interfaceUpgradeResponse
- Returns:
- the list of negotiated extensions to use.
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from interface:UpgradeResponse
Get a header value- Specified by:
getHeader
in interfaceUpgradeResponse
- Parameters:
name
- the header name- Returns:
- the value (null if header doesn't exist)
-
getHeaderNames
public java.util.Set<java.lang.String> getHeaderNames()
Description copied from interface:UpgradeResponse
Get the header names- Specified by:
getHeaderNames
in interfaceUpgradeResponse
- Returns:
- the set of header names
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Description copied from interface:UpgradeResponse
Get the headers map- Specified by:
getHeaders
in interfaceUpgradeResponse
- Returns:
- the map of headers
-
getHeaders
public java.util.List<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:UpgradeResponse
Get the multi-value header value- Specified by:
getHeaders
in interfaceUpgradeResponse
- Parameters:
name
- the header name- Returns:
- the list of values (null if header doesn't exist)
-
getStatusCode
public int getStatusCode()
Description copied from interface:UpgradeResponse
Get the HTTP Response Status Code- Specified by:
getStatusCode
in interfaceUpgradeResponse
- Returns:
- the status code
-
getStatusReason
public java.lang.String getStatusReason()
Description copied from interface:UpgradeResponse
Get the HTTP Response Status Reason- Specified by:
getStatusReason
in interfaceUpgradeResponse
- Returns:
- the HTTP Response status reason
-
isCommitted
public boolean isCommitted()
-
isExtensionsNegotiated
public boolean isExtensionsNegotiated()
-
isSubprotocolNegotiated
public boolean isSubprotocolNegotiated()
-
isSuccess
public boolean isSuccess()
Description copied from interface:UpgradeResponse
Test if upgrade response is successful.Merely notes if the response was sent as a WebSocket Upgrade, or was failed (resulting in no upgrade handshake)
- Specified by:
isSuccess
in interfaceUpgradeResponse
- Returns:
- true if upgrade response was generated, false if no upgrade response was generated
-
sendError
public void sendError(int statusCode, java.lang.String message) throws java.io.IOException
- Throws:
java.io.IOException
-
sendForbidden
public void sendForbidden(java.lang.String message) throws java.io.IOException
Description copied from interface:UpgradeResponse
Issue a forbidden upgrade response.This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden access.
Use this when the origin or authentication is invalid.
- Specified by:
sendForbidden
in interfaceUpgradeResponse
- Parameters:
message
- the short 1 line detail message about the forbidden response- Throws:
java.io.IOException
- if unable to send the forbidden
-
setAcceptedSubProtocol
public void setAcceptedSubProtocol(java.lang.String protocol)
Description copied from interface:UpgradeResponse
Set the accepted WebSocket Protocol.- Specified by:
setAcceptedSubProtocol
in interfaceUpgradeResponse
- Parameters:
protocol
- the protocol to list as accepted
-
setExtensions
public void setExtensions(java.util.List<ExtensionConfig> configs)
Description copied from interface:UpgradeResponse
Set the list of extensions that are approved for use with this websocket.Notes:
- Per the spec you cannot add extensions that have not been seen in the
UpgradeRequest
, just remove entries you don't want to use - If this is unused, or a null is passed, then the list negotiation will follow default behavior and use the complete list of extensions that are available in this WebSocket server implementation.
- Specified by:
setExtensions
in interfaceUpgradeResponse
- Parameters:
configs
- the list of extensions to use.
- Per the spec you cannot add extensions that have not been seen in the
-
setStatusCode
public void setStatusCode(int statusCode)
Description copied from interface:UpgradeResponse
Set the HTTP Response status code- Specified by:
setStatusCode
in interfaceUpgradeResponse
- Parameters:
statusCode
- the status code
-
setStatusReason
public void setStatusReason(java.lang.String statusReason)
Description copied from interface:UpgradeResponse
Set the HTTP Response status reason phraseNote, not all implementation of UpgradeResponse can support this feature
- Specified by:
setStatusReason
in interfaceUpgradeResponse
- Parameters:
statusReason
- the status reason phrase
-
setSuccess
public void setSuccess(boolean success)
Description copied from interface:UpgradeResponse
Set the success of the upgrade response.- Specified by:
setSuccess
in interfaceUpgradeResponse
- Parameters:
success
- true to indicate a response to the upgrade handshake was sent, false to indicate no upgrade response was sent
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-