-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Admin Event API to Universal API #10762
- Loading branch information
1 parent
fb86601
commit 7fd5d51
Showing
8 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
modules/admin/admin-event/src/main/java/com/enonic/xp/admin/event/impl/EventApiHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.enonic.xp.admin.event.impl; | ||
|
||
import java.util.List; | ||
|
||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import com.enonic.xp.portal.universalapi.UniversalApiHandler; | ||
import com.enonic.xp.web.HttpStatus; | ||
import com.enonic.xp.web.WebRequest; | ||
import com.enonic.xp.web.WebResponse; | ||
import com.enonic.xp.web.websocket.EndpointFactory; | ||
import com.enonic.xp.web.websocket.WebSocketConfig; | ||
import com.enonic.xp.web.websocket.WebSocketService; | ||
|
||
@Component(immediate = true, service = UniversalApiHandler.class, property = {"applicationKey=admin", "apiKey=event", | ||
"displayName=Event API", "allowedPrincipals=role:system.admin.login", "mount=true"}) | ||
public class EventApiHandler | ||
implements UniversalApiHandler | ||
{ | ||
private final WebSocketService webSocketService; | ||
|
||
private final EndpointFactory endpointFactory; | ||
|
||
@Activate | ||
public EventApiHandler( @Reference final WebSocketService webSocketService, | ||
@Reference/*(service = EventEndpointFactory.class)*/ final EndpointFactory endpointFactory ) | ||
{ | ||
this.webSocketService = webSocketService; | ||
this.endpointFactory = endpointFactory; | ||
} | ||
|
||
@Override | ||
public WebResponse handle( final WebRequest request ) | ||
{ | ||
final WebResponse.Builder<?> responseBuilder = WebResponse.create(); | ||
|
||
if ( !webSocketService.isUpgradeRequest( request.getRawRequest(), null ) ) | ||
{ | ||
responseBuilder.status( HttpStatus.FORBIDDEN ); | ||
return responseBuilder.build(); | ||
} | ||
|
||
final WebSocketConfig webSocketConfig = new WebSocketConfig(); | ||
webSocketConfig.setSubProtocols( List.of( "text" ) ); | ||
|
||
responseBuilder.webSocket( webSocketConfig ); | ||
|
||
return responseBuilder.build(); | ||
} | ||
|
||
@Override | ||
public EndpointFactory getEndpointFactory() | ||
{ | ||
return endpointFactory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters