use of com.enonic.xp.web.websocket.WebSocketConfig in project xp by enonic.
the class WebAppHandler method executeController.
private PortalResponse executeController(final PortalRequest req) throws Exception {
final ControllerScript script = getScript(req.getApplicationKey());
final PortalResponse res = script.execute(req);
final WebSocketConfig webSocketConfig = res.getWebSocket();
final WebSocketContext webSocketContext = req.getWebSocketContext();
if ((webSocketContext != null) && (webSocketConfig != null)) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig, script, req.getApplicationKey());
webSocketContext.apply(webSocketEndpoint);
}
return res;
}
use of com.enonic.xp.web.websocket.WebSocketConfig in project xp by enonic.
the class PortalResponseSerializer method populateWebSocket.
private void populateWebSocket(final PortalResponse.Builder builder, final ScriptValue value) {
if (value == null) {
return;
}
final WebSocketConfig config = new WebSocketConfig();
populateWebSocketData(config, value.getMember("data"));
populateWebSocketSubProtocols(config, value.getMember("subProtocols"));
builder.webSocket(config);
}
use of com.enonic.xp.web.websocket.WebSocketConfig in project xp by enonic.
the class ServiceHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
// Retrieves the ServiceDescriptor
final DescriptorKey descriptorKey = DescriptorKey.from(applicationKey, name);
final ServiceDescriptor serviceDescriptor = serviceDescriptorService.getByKey(descriptorKey);
if (serviceDescriptor == null) {
throw WebException.notFound(String.format("Service [%s] not found", descriptorKey));
}
// Checks if the access to ServiceDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!serviceDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
final ContentResolverResult resolvedContent = contentResolver.resolve(request);
final Site site = resolvedContent.getNearestSite();
// Checks if the application is set on the current site
if (site != null) {
final PropertyTree siteConfig = site.getSiteConfig(applicationKey);
if (siteConfig == null) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this site", descriptorKey));
}
}
// Checks if the application is set on the current application
final ApplicationKey baseApplicationKey = getBaseApplicationKey();
if (baseApplicationKey != null && !baseApplicationKey.equals(applicationKey)) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this application", descriptorKey));
}
// Prepares the request
this.request.setApplicationKey(applicationKey);
this.request.setContent(resolvedContent.getContent());
this.request.setSite(site);
// Executes the service
final ControllerScript controllerScript = getScript();
final PortalResponse portalResponse = controllerScript.execute(this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if ((webSocketContext != null) && (webSocketConfig != null)) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig);
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.web.websocket.WebSocketConfig in project xp by enonic.
the class MappingHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ControllerScript controllerScript = getScript();
final Trace trace = Tracer.current();
if (trace != null) {
trace.put("contentPath", this.request.getContentPath().toString());
trace.put("type", "mapping");
}
this.request.setControllerScript(controllerScript);
final PortalResponse portalResponse = rendererDelegate.render(mappingDescriptor, this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if (webSocketContext != null && webSocketConfig != null) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig, this::getScript, request.getApplicationKey());
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.web.websocket.WebSocketConfig in project xp by enonic.
the class WebDispatcherServlet method service.
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
final WebRequest webRequest = newWebRequest(req);
final WebSocketContext webSocketContext = this.webSocketContextFactory.newContext(req, res);
webRequest.setWebSocketContext(webSocketContext);
final WebResponse webResponse = doHandle(webRequest);
final WebSocketConfig config = webResponse.getWebSocket();
if ((webSocketContext != null) && (config != null)) {
return;
}
responseSerializationService.serialize(webRequest, webResponse, res);
}
Aggregations