本文整理匯總了Java中org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse.setAcceptedSubProtocol方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletUpgradeResponse.setAcceptedSubProtocol方法的具體用法?Java ServletUpgradeResponse.setAcceptedSubProtocol怎麽用?Java ServletUpgradeResponse.setAcceptedSubProtocol使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse
的用法示例。
在下文中一共展示了ServletUpgradeResponse.setAcceptedSubProtocol方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createWebSocket
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
public Object createWebSocket( final ServletUpgradeRequest req, final ServletUpgradeResponse res )
{
final Set<String> allowSubProtocols = this.config.getSubProtocols();
if ( allowSubProtocols.isEmpty() )
{
return doCreateWebSocket();
}
for ( final String protocol : req.getSubProtocols() )
{
if ( allowSubProtocols.contains( protocol ) )
{
res.setAcceptedSubProtocol( protocol );
return doCreateWebSocket();
}
}
return null;
}
示例2: createWebSocket
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
@Override
public Object createWebSocket(ServletUpgradeRequest req,
ServletUpgradeResponse resp) {
// Borrow WebSocket sub-protocols as input for channels and filters,
// which are at position 0 and 1 in the sub-protocols array
MetricWebSocket socket = new MetricWebSocket(req.getSubProtocols().get(0), req.getSubProtocols().get(1), wsConnectionManager);
resp.setAcceptedSubProtocol(req.getSubProtocols().get(0));
return socket;
}
示例3: validateAppId
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
private boolean validateAppId(ServletUpgradeRequest req, ServletUpgradeResponse res) throws ServletException, IOException {
boolean valid = false;
String ourAppId = null;
try {
ourAppId = getReceiver().getAppId().get();
} catch (StageException e) {
throw new IOException("Cant resolve credential value", e);
}
String requester = req.getRemoteAddress() + ":" + req.getRemotePort();
String reqAppId = req.getHeader(HttpConstants.X_SDC_APPLICATION_ID_HEADER);
if (reqAppId == null && receiver.isAppIdViaQueryParamAllowed()) {
Map<String,List<String>> parameterMap = req.getParameterMap();
if (parameterMap != null && parameterMap.containsKey(HttpConstants.SDC_APPLICATION_ID_QUERY_PARAM)) {
List<String> values = parameterMap.get(HttpConstants.SDC_APPLICATION_ID_QUERY_PARAM);
if (values != null && values.size() > 0) {
reqAppId = values.get(0);
}
}
}
if (reqAppId == null) {
// Since it is not possible to pass headers in some of the WebSockets client (example: browser WebSocket API)
// http://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api
// check sub-protocol header for APP ID
List<String> subProtocols = req.getSubProtocols();
if (subProtocols != null && subProtocols.contains(ourAppId)) {
reqAppId = ourAppId;
res.setAcceptedSubProtocol(reqAppId);
}
}
if (reqAppId == null) {
LOG.warn("Request from '{}' missing appId, rejected", requester);
res.sendError(HttpServletResponse.SC_FORBIDDEN, "Missing 'appId'");
} if (reqAppId != null && !ourAppId.equals(reqAppId)) {
LOG.warn("Request from '{}' invalid appId '{}', rejected", requester, reqAppId);
res.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid 'appId'");
} else {
valid = true;
}
return valid;
}