Skip to content

Commit af8f8f8

Browse files
laeubistbischof
authored andcommitted
Add Http WHiteboard Publisher
this adds an implementation of the publisher SPI that uses the http whiteboard as its backend implementation.
1 parent f6aeb83 commit af8f8f8

14 files changed

+1017
-1
lines changed

runtime/httpwhiteboard/.classpath

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
<attribute name="optional" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
16+
<attributes>
17+
<attribute name="optional" value="true"/>
18+
<attribute name="maven.pomderived" value="true"/>
19+
<attribute name="test" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
23+
<attributes>
24+
<attribute name="maven.pomderived" value="true"/>
25+
<attribute name="test" value="true"/>
26+
<attribute name="optional" value="true"/>
27+
</attributes>
28+
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
30+
<attributes>
31+
<attribute name="maven.pomderived" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
35+
<attributes>
36+
<attribute name="maven.pomderived" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="output" path="target/classes"/>
40+
</classpath>

runtime/httpwhiteboard/.project

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>httpwhiteboard</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.pde.PluginNature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
23+
</natures>
24+
</projectDescription>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
4+
encoding//src/test/java=UTF-8
5+
encoding//src/test/resources=UTF-8
6+
encoding/<project>=UTF-8
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_ROOT_PATH=target/classes
2+
eclipse.preferences.version=1

runtime/httpwhiteboard/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>org.eclipse.osgi-technology.webservices</groupId>
19+
<artifactId>org.eclipse.osgi.technology.webservices.runtime</artifactId>
20+
<version>1.0.0-SNAPSHOT</version>
21+
</parent>
22+
<artifactId>org.eclipse.osgi.technology.webservices.httpwhiteboard</artifactId>
23+
<name>Http WHiteboard Publisher</name>
24+
<description>Publish the Endpoints using Http Whiteboard Service</description>
25+
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.eclipse.osgi-technology.webservices</groupId>
30+
<artifactId>
31+
org.eclipse.osgi.technology.webservices.runtime.registrar</artifactId>
32+
<version>${project.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>jakarta.xml.ws</groupId>
36+
<artifactId>jakarta.xml.ws-api</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.osgi</groupId>
40+
<artifactId>org.osgi.annotation.bundle</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.osgi</groupId>
44+
<artifactId>osgi.core</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.osgi</groupId>
48+
<artifactId>org.osgi.service.component.annotations</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.osgi</groupId>
52+
<artifactId>org.osgi.service.component</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>jakarta.servlet</groupId>
56+
<artifactId>jakarta.servlet-api</artifactId>
57+
<version>6.1.0</version>
58+
<scope>provided</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.osgi</groupId>
62+
<artifactId>org.osgi.service.http.whiteboard</artifactId>
63+
<version>1.1.1</version>
64+
<scope>provided</scope>
65+
</dependency>
66+
<!-- TODO can we somehow embedd the classes instead of copy the source-->
67+
<!-- <dependency>-->
68+
<!-- <groupId>com.sun.xml.ws</groupId>-->
69+
<!-- <artifactId>jaxws-rt</artifactId>-->
70+
<!-- <version>4.0.3</version>-->
71+
<!-- <scope>provided</scope>-->
72+
<!-- </dependency>-->
73+
</dependencies>
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.osgi.technology.webservices.httpwhiteboard;
14+
15+
import java.util.Map;
16+
import java.util.concurrent.ConcurrentHashMap;
17+
18+
import org.eclipse.osgi.technology.webservices.spi.EndpointPublisher;
19+
import org.eclipse.osgi.technology.webservices.spi.PublishedEndpoint;
20+
import org.osgi.framework.BundleContext;
21+
import org.osgi.service.component.annotations.Activate;
22+
import org.osgi.service.component.annotations.Component;
23+
import org.osgi.service.component.annotations.Reference;
24+
import org.osgi.service.http.whiteboard.annotations.RequireHttpWhiteboard;
25+
import org.osgi.service.log.Logger;
26+
import org.osgi.service.log.LoggerFactory;
27+
import org.osgi.service.webservice.whiteboard.WebserviceWhiteboardConstants;
28+
import org.osgi.service.webservice.whiteboard.annotations.RequireWebserviceWhiteboard;
29+
30+
import jakarta.xml.ws.Endpoint;
31+
32+
/**
33+
* Publishes Endpoints with the HttpWhiteboard service
34+
*
35+
*/
36+
@RequireHttpWhiteboard
37+
@RequireWebserviceWhiteboard
38+
@Component(immediate = true, name = "org.eclipse.osgi.technology.webservices.httpwhiteboard", service = EndpointPublisher.class)
39+
public class HttpWhiteboardPublisher implements EndpointPublisher {
40+
41+
private BundleContext bundleContext;
42+
private Logger logger;
43+
private Map<Endpoint, WhiteboardHttpContext> registrationMap = new ConcurrentHashMap<>();
44+
45+
/**
46+
* Constructor
47+
*
48+
* @param bundleContext the context
49+
* @param logger the logger
50+
*/
51+
@Activate
52+
public HttpWhiteboardPublisher(BundleContext bundleContext,
53+
@Reference(service = LoggerFactory.class) Logger logger) {
54+
this.bundleContext = bundleContext;
55+
this.logger = logger;
56+
}
57+
58+
@Override
59+
public PublishedEndpoint publishEndpoint(Endpoint endpoint) {
60+
Map<String, Object> properties = endpoint.getProperties();
61+
Object prefix = properties.get(WebserviceWhiteboardConstants.WEBSERVICE_HTTP_ENDPOINT_PREFIX);
62+
if (prefix instanceof String contextPath) {
63+
logger.info("Registering {} with http whiteboard at context path {}", endpoint, contextPath);
64+
WhiteboardHttpContext httpContext = new WhiteboardHttpContext(contextPath, endpoint.getProperties());
65+
registrationMap.put(endpoint, httpContext);
66+
endpoint.publish(httpContext);
67+
httpContext.register(bundleContext);
68+
return httpContext;
69+
}
70+
return null;
71+
}
72+
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.osgi.technology.webservices.httpwhiteboard;
14+
15+
import java.io.IOException;
16+
import java.net.HttpURLConnection;
17+
import java.util.Collections;
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import java.util.Set;
21+
22+
import org.eclipse.osgi.technology.webservices.httpwhiteboard.wsri.EndpointHttpExchange;
23+
import org.eclipse.osgi.technology.webservices.spi.PublishedEndpoint;
24+
import org.osgi.framework.BundleContext;
25+
import org.osgi.framework.FrameworkUtil;
26+
import org.osgi.framework.ServiceRegistration;
27+
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
28+
29+
import jakarta.servlet.Servlet;
30+
import jakarta.servlet.ServletException;
31+
import jakarta.servlet.http.HttpServlet;
32+
import jakarta.servlet.http.HttpServletRequest;
33+
import jakarta.servlet.http.HttpServletResponse;
34+
import jakarta.xml.ws.spi.http.HttpContext;
35+
36+
/**
37+
* Http context to use with the whiteboard
38+
*/
39+
public class WhiteboardHttpContext extends HttpContext implements PublishedEndpoint {
40+
41+
private String path;
42+
private Map<String, ?> attributes;
43+
private Set<String> names;
44+
private boolean closed;
45+
private ServiceRegistration<?> serviceRegistration;
46+
47+
WhiteboardHttpContext(String path, Map<String, ?> attributes) {
48+
this.path = path;
49+
this.attributes = attributes;
50+
names = Collections.unmodifiableSet(attributes.keySet());
51+
}
52+
53+
@Override
54+
public String getPath() {
55+
return path;
56+
}
57+
58+
@Override
59+
public Object getAttribute(String name) {
60+
return attributes.get(name);
61+
}
62+
63+
@Override
64+
public Set<String> getAttributeNames() {
65+
return names;
66+
}
67+
68+
synchronized void register(BundleContext bundleContext) {
69+
if (closed) {
70+
return;
71+
}
72+
HashMap<String, Object> properties = new HashMap<>(attributes);
73+
if (!properties.containsKey(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME)) {
74+
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "JAX-WS Service for path "+getPath());
75+
}
76+
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, getPath());
77+
serviceRegistration = bundleContext.registerService(Servlet.class, new JaxWsServlet(), FrameworkUtil.asDictionary(properties));
78+
}
79+
80+
private class JaxWsServlet extends HttpServlet {
81+
82+
private static final long serialVersionUID = 1L;
83+
84+
85+
@Override
86+
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
87+
if (handler == null || closed) {
88+
resp.sendError(HttpURLConnection.HTTP_UNAVAILABLE);
89+
return;
90+
}
91+
handler.handle(new EndpointHttpExchange(req, resp, getServletContext(), WhiteboardHttpContext.this));
92+
}
93+
94+
}
95+
96+
@Override
97+
public synchronized void unpublish() {
98+
closed = true;
99+
if (serviceRegistration != null) {
100+
serviceRegistration.unregister();
101+
}
102+
}
103+
104+
@Override
105+
public String getAddress() {
106+
// FIXME we need the full path here, how to get it from the whiteboard?!?
107+
return path;
108+
}
109+
110+
}

0 commit comments

Comments
 (0)