Class ServletUpgradeResponse
java.lang.Object
org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse
- All Implemented Interfaces:
UpgradeResponse
- Direct Known Subclasses:
ServletWebSocketResponse
Servlet Specific UpgradeResponse implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<ExtensionConfig> private booleanprivate javax.servlet.http.HttpServletResponseprivate intprivate booleanprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a header value to the response.voidcomplete()Get the accepted WebSocket protocol.Get the list of extensions that should be used for the websocket.Get a header valueGet the header namesGet the headers mapgetHeaders(String name) Get the multi-value header valueintGet the HTTP Response Status CodeGet the HTTP Response Status ReasonbooleanbooleanbooleanbooleanTest if upgrade response is successful.voidvoidsendForbidden(String message) Issue a forbidden upgrade response.voidsetAcceptedSubProtocol(String protocol) Set the accepted WebSocket Protocol.voidsetExtensions(List<ExtensionConfig> configs) Set the list of extensions that are approved for use with this websocket.voidSet a headervoidsetStatusCode(int statusCode) Set the HTTP Response status codevoidsetStatusReason(String statusReason) Set the HTTP Response status reason phrasevoidsetSuccess(boolean success) Set the success of the upgrade response.toString()
-
Field Details
-
response
private javax.servlet.http.HttpServletResponse response -
extensionsNegotiated
private boolean extensionsNegotiated -
subprotocolNegotiated
private boolean subprotocolNegotiated -
headers
-
extensions
-
success
private boolean success -
status
private int status
-
-
Constructor Details
-
ServletUpgradeResponse
public ServletUpgradeResponse(javax.servlet.http.HttpServletResponse response)
-
-
Method Details
-
addHeader
Description copied from interface:UpgradeResponseAdd a header value to the response.- Specified by:
addHeaderin interfaceUpgradeResponse- Parameters:
name- the header namevalue- the header value
-
setHeader
Description copied from interface:UpgradeResponseSet a headerOverrides previous value of header (if set)
- Specified by:
setHeaderin interfaceUpgradeResponse- Parameters:
name- the header namevalue- the header value
-
complete
public void complete() -
getAcceptedSubProtocol
Description copied from interface:UpgradeResponseGet the accepted WebSocket protocol.- Specified by:
getAcceptedSubProtocolin interfaceUpgradeResponse- Returns:
- the accepted WebSocket protocol.
-
getExtensions
Description copied from interface:UpgradeResponseGet the list of extensions that should be used for the websocket.- Specified by:
getExtensionsin interfaceUpgradeResponse- Returns:
- the list of negotiated extensions to use.
-
getHeader
Description copied from interface:UpgradeResponseGet a header value- Specified by:
getHeaderin interfaceUpgradeResponse- Parameters:
name- the header name- Returns:
- the value (null if header doesn't exist)
-
getHeaderNames
Description copied from interface:UpgradeResponseGet the header names- Specified by:
getHeaderNamesin interfaceUpgradeResponse- Returns:
- the set of header names
-
getHeaders
Description copied from interface:UpgradeResponseGet the headers map- Specified by:
getHeadersin interfaceUpgradeResponse- Returns:
- the map of headers
-
getHeaders
Description copied from interface:UpgradeResponseGet the multi-value header value- Specified by:
getHeadersin 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:UpgradeResponseGet the HTTP Response Status Code- Specified by:
getStatusCodein interfaceUpgradeResponse- Returns:
- the status code
-
getStatusReason
Description copied from interface:UpgradeResponseGet the HTTP Response Status Reason- Specified by:
getStatusReasonin 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:UpgradeResponseTest 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:
isSuccessin interfaceUpgradeResponse- Returns:
- true if upgrade response was generated, false if no upgrade response was generated
-
sendError
- Throws:
IOException
-
sendForbidden
Description copied from interface:UpgradeResponseIssue 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:
sendForbiddenin interfaceUpgradeResponse- Parameters:
message- the short 1 line detail message about the forbidden response- Throws:
IOException- if unable to send the forbidden
-
setAcceptedSubProtocol
Description copied from interface:UpgradeResponseSet the accepted WebSocket Protocol.- Specified by:
setAcceptedSubProtocolin interfaceUpgradeResponse- Parameters:
protocol- the protocol to list as accepted
-
setExtensions
Description copied from interface:UpgradeResponseSet 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:
setExtensionsin 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:UpgradeResponseSet the HTTP Response status code- Specified by:
setStatusCodein interfaceUpgradeResponse- Parameters:
statusCode- the status code
-
setStatusReason
Description copied from interface:UpgradeResponseSet the HTTP Response status reason phraseNote, not all implementation of UpgradeResponse can support this feature
- Specified by:
setStatusReasonin interfaceUpgradeResponse- Parameters:
statusReason- the status reason phrase
-
setSuccess
public void setSuccess(boolean success) Description copied from interface:UpgradeResponseSet the success of the upgrade response.- Specified by:
setSuccessin interfaceUpgradeResponse- Parameters:
success- true to indicate a response to the upgrade handshake was sent, false to indicate no upgrade response was sent
-
toString
-