Skip to content

Websocket updates #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ release.properties
dist/
yarn-debug.log*
yarn-error.log*
ddf-ui-deplist.out
ddf-ui-deplist.out
**/.java-version
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<fmt.maven.plugin.version>2.3.0</fmt.maven.plugin.version>

<!--Backend properties-->
<ddf.version>2.29.17</ddf.version>
<ddf.version>2.29.18</ddf.version>
<ddf-jsonrpc.version>0.9</ddf-jsonrpc.version>
<ddf.support.version>2.3.16</ddf.support.version>
<antlr.version>4.3</antlr.version>
Expand Down
15 changes: 15 additions & 0 deletions ui-backend/catalog-ui-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@
<artifactId>ows-v_1_1_0-schema</artifactId>
<version>${ows-v_1_0_0-schema.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.codice.ddf.search</groupId>
<artifactId>catalog-ui-websockets</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ Implementation details
<argument ref="sourceWarningsFilterManager"/>
</bean>


<bean id="jsonRpc" class="org.codice.ddf.catalog.ui.ws.JsonRpc">
<argument>
<map>
Expand Down Expand Up @@ -425,6 +426,13 @@ Implementation details
<argument ref="sessionPlugins"/>
</bean>

<service interface="org.eclipse.jetty.websocket.servlet.WebSocketCreator" ref="socketServlet">
<service-properties>
<entry key="name" value="secureWebsocketCreatorSearchCatalog"/>
</service-properties>
</service>


<!--
=============================================================
QUERY METACARD APPLICATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ Services (HTTP/WS) that catalog-ui-search provides for the UI
</service-properties>
</service>

<service ref="socketServlet" interface="javax.servlet.Servlet">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer register a standard servlet for websockets. The specifications pax web adheres to are for osgi's whiteboard pattern - which is for http. As a result websockets aren't directly supported through whiteboard servlet registration.

<service-properties>
<entry key="osgi.http.whiteboard.servlet.pattern" value="/*"/>
<entry key="osgi.http.whiteboard.servlet.name" value="websocketServlet"/>
<entry key="osgi.http.whiteboard.context.select" value="(osgi.http.whiteboard.context.path=websocketContextHelper)"/>
<entry key="osgi.http.whiteboard.servlet.asyncSupported" value="true"/>
</service-properties>
</service>

<!--
=============================================================
Expand Down
51 changes: 51 additions & 0 deletions ui-backend/catalog-ui-websockets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright (c) Codice Foundation
*
* This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at
* <http://www.gnu.org/licenses/lgpl.html>.
*
**/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>backend</artifactId>
<groupId>org.codice.ddf.search</groupId>
<version>5.2.19-SNAPSHOT</version>
</parent>
<packaging>bundle</packaging>

<artifactId>catalog-ui-websockets</artifactId>
<name>DDF :: Catalog :: UI :: Websockets</name>

<dependencies>
<dependency>
<groupId>ddf.security.servlet</groupId>
<artifactId>security-servlet-web-socket-api</artifactId>
<version>${ddf.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Web-ContextPath>/search/catalog/ws</Web-ContextPath>
Copy link
Collaborator Author

@malmgrens4 malmgrens4 Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register as a WAB. Pax web listens for websockets created in WABs (but not the old websocket annotations)

</instructions>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.codice.ddf.catalog.ui.websockets;

import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;

public class CustomWebSocketCreator implements WebSocketCreator {

@Override
public Object createWebSocket(
ServletUpgradeRequest servletUpgradeRequest, ServletUpgradeResponse servletUpgradeResponse) {
return StaticHolder.webSocketCreator.createWebSocket(
servletUpgradeRequest, servletUpgradeResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
* License is distributed along with this program and can be found at
* <http://www.gnu.org/licenses/lgpl.html>.
*/
package org.codice.ddf.catalog.ui;
package org.codice.ddf.catalog.ui.websockets;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContext;
import javax.servlet.annotation.WebServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;

@Component(service = ServletContextHelper.class, scope = ServiceScope.BUNDLE)
@HttpWhiteboardContext(name = "websocketContextHelper", path = "/search/catalog/ws")
public class WebSocketContextHelper extends ServletContextHelper {}
@WebServlet(
name = "SearchCatalogWebsockets",
urlPatterns = {"/*", "/"},
asyncSupported = true
)
public class SearchCatalogWebSocket extends WebSocketServlet {
@Override
public void configure(WebSocketServletFactory factory) {
factory.setCreator(new CustomWebSocketCreator());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.codice.ddf.catalog.ui.websockets;

import org.eclipse.jetty.websocket.servlet.WebSocketCreator;

public class StaticHolder {
public static WebSocketCreator webSocketCreator;

public StaticHolder(WebSocketCreator webSocketCreator) {
StaticHolder.webSocketCreator = webSocketCreator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">


<reference id="websocketCreator"
interface="org.eclipse.jetty.websocket.servlet.WebSocketCreator"
filter="(name=secureWebsocketCreatorSearchCatalog)"
availability="optional"/>

<bean id="staticHolder" class="org.codice.ddf.catalog.ui.websockets.StaticHolder">
<argument ref="websocketCreator"/>
</bean>


</blueprint>
1 change: 1 addition & 0 deletions ui-backend/intrigue-ui-app/src/main/resources/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<bundle>mvn:org.codice.ddf.search/catalog-ui-enumeration/${project.version}</bundle>
<bundle>mvn:com.google.code.gson/gson/${gson.version}</bundle>
<bundle>mvn:org.codice.ddf.search/catalog-ui-splitter/${project.version}</bundle>
<bundle>mvn:org.codice.ddf.search/catalog-ui-websockets/${project.version}</bundle>
<bundle>mvn:org.apache.commons/commons-math3/${commons-math3.version}</bundle>
<bundle>mvn:org.codice.ddf.search/audit-api/${project.version}</bundle>
<bundle>mvn:org.codice.ddf.search/audit-application/${project.version}</bundle>
Expand Down
1 change: 1 addition & 0 deletions ui-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<module>audit</module>
<module>javalin-utils</module>
<module>deprecatable-enumeration-api</module>
<module>catalog-ui-websockets</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (StartupDataStore.Configuration.getWebSocketsEnabled() && window.WebSocket) {
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
const url = `${protocol[location.protocol]}//${location.hostname}:${
location.port
}${location.pathname}ws`
}${location.pathname}ws/`
rpcInitial = new Client(url, { autoconnect: false })

// Only set rpc if the connection succeeds
Expand Down