List of usage examples for javax.websocket Session setMaxTextMessageBufferSize
void setMaxTextMessageBufferSize(int max);
From source file:org.wso2.carbon.device.mgt.extensions.remote.session.RemoteSessionManagementServiceImpl.java
@Override public void initializeSession(Session session, String deviceType, String deviceId, String operationId) throws RemoteSessionManagementException { // Check whether required configurations are enabled if (!RemoteSessionManagementDataHolder.getInstance().isEnabled()) { throw new RemoteSessionManagementException("Remote session feature is disabled."); } else if (RemoteSessionManagementDataHolder.getInstance().getServerUrl() == null) { throw new RemoteSessionManagementException("Server url has not been configured."); }//from www .j a v a 2s .c om // Read Query Parameters for obtain the token Map<String, List<String>> sessionQueryParam = new HashMap(); List<String> sessionQueryParamList = new LinkedList<>(); sessionQueryParamList.add(session.getQueryString()); sessionQueryParam.put(RemoteSessionConstants.QUERY_STRING, sessionQueryParamList); // Validate the token OAuthAuthenticator oAuthAuthenticator = RemoteSessionManagementDataHolder.getInstance() .getOauthAuthenticator(); AuthenticationInfo authenticationInfo = oAuthAuthenticator.isAuthenticated(sessionQueryParam); if (authenticationInfo != null && authenticationInfo.isAuthenticated()) { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(authenticationInfo.getTenantDomain(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(authenticationInfo.getUsername()); if (deviceId != null && !deviceId.isEmpty() && deviceType != null && !deviceType.isEmpty()) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(deviceType); // Check authorization of user for given device boolean userAuthorized = RemoteSessionManagementDataHolder.getInstance() .getDeviceAccessAuthorizationService() .isUserAuthorized(deviceIdentifier, authenticationInfo.getUsername()); if (userAuthorized) { // set common settings for session session.setMaxBinaryMessageBufferSize( RemoteSessionManagementDataHolder.getInstance().getMaxMessageBufferSize()); session.setMaxTextMessageBufferSize( RemoteSessionManagementDataHolder.getInstance().getMaxMessageBufferSize()); session.setMaxIdleTimeout( RemoteSessionManagementDataHolder.getInstance().getMaxIdleTimeout()); // if session initiated using operation id means request came from device if (operationId != null) { // create new device session initializeDeviceSession(session, authenticationInfo.getTenantDomain(), deviceType, deviceId, operationId); } else { // create new client session initializeClientSession(session, authenticationInfo.getTenantDomain(), deviceType, deviceId); } log.info("Current remote sessions count: " + RemoteSessionManagementDataHolder.getInstance().getSessionMap().size()); } else { throw new RemoteSessionManagementException("Missing device Id or type "); } } else { throw new RemoteSessionManagementException("Unauthorized Access for the device Type : " + deviceType + " , deviceId : " + deviceId); } } catch (OperationManagementException | InvalidDeviceException e) { throw new RemoteSessionManagementException("Error occurred while adding initial operation for the " + "device Type : " + deviceType + " , deviceId : " + deviceId); } catch (DeviceAccessAuthorizationException e) { throw new RemoteSessionManagementException( "Error occurred while device access authorization for the " + "device Type : " + deviceType + " , " + "deviceId : " + deviceId); } finally { PrivilegedCarbonContext.endTenantFlow(); } } else { throw new RemoteSessionManagementException("Invalid token"); } }
From source file:pt.webdetails.cda.push.CdaPushQueryEndpoint.java
/** * This method is called whenever a client creates a new websocket connection to the URL registered to * this endpoint.//from w w w . ja v a 2s . com * * @param session the websocket session. * @param endpointConfig the endpoint configuration. */ @Override public void onOpen(Session session, EndpointConfig endpointConfig) { PentahoRequestContextHolder.setRequestContext(() -> (String) endpointConfig.getUserProperties() .get(WebsocketEndpointConfig.getInstanceToReadProperties().getServletContextPathPropertyName())); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); this.queryHandler = new CdaPushQueryMessageHandler(session, requestContext); this.queryHandler.getWebsocketJsonQueryEndpoint().onOpen(null); session.setMaxTextMessageBufferSize(Integer.parseInt(endpointConfig.getUserProperties() .get(WebsocketEndpointConfig.getInstanceToReadProperties().getMaxMessagePropertyName()) .toString())); session.setMaxBinaryMessageBufferSize(Integer.parseInt(endpointConfig.getUserProperties() .get(WebsocketEndpointConfig.getInstanceToReadProperties().getMaxMessagePropertyName()) .toString())); session.addMessageHandler(queryHandler); }