Skip to content

Commit 3802dc7

Browse files
committed
Refactor XMLA Servlet and add localization with improved modularity...
- Replaced old `XmlaServlet` with new implementation using metatype annotations. - Added `Constants` class for reusable definitions and servlet properties. - Introduced `ServletOCD` interface for configuration definitions. - Implemented `XmlaServletOCD` with localization and OCD support. - Updated `pom.xml` to include OSGi metatype annotations dependency. - Added `package-info.java` for `impl` package with versioning annotations. - Removed `package-info.java` from root `jakarta.saaj` package. - Added localization properties for servlet configuration in resource files. - Defined OCD names and descriptions in localization file. - Improved project structure for better modularity and maintainability.
1 parent eca0d3b commit 3802dc7

File tree

8 files changed

+208
-7
lines changed

8 files changed

+208
-7
lines changed

server/jakarta.saaj/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
<groupId>org.osgi</groupId>
3333
<artifactId>org.osgi.service.servlet</artifactId>
3434
</dependency>
35+
36+
<dependency>
37+
<groupId>org.osgi</groupId>
38+
<artifactId>org.osgi.service.metatype.annotations</artifactId>
39+
<scope>compile</scope>
40+
</dependency>
41+
3542
<dependency>
3643
<groupId>org.apache.felix</groupId>
3744
<artifactId>org.apache.felix.http.servlet-api</artifactId>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.xmla.server.jakarta.saaj.api;
15+
16+
import org.osgi.framework.Bundle;
17+
18+
/**
19+
* Constants of this {@link Bundle}.
20+
*/
21+
public class Constants {
22+
23+
private Constants() {
24+
}
25+
26+
/**
27+
* Constant for the {@link org.osgi.framework.Constants#SERVICE_PID} of the XMLA Servlet Service.
28+
*/
29+
public static final String PID_XMLA_SERVLET = "daanse.xmla.server.jakarta.saaj.XmlaServlet";
30+
31+
/**
32+
* Constant for the reference attribute name for the XMLA service. This is used as a service filter
33+
* for selecting the XMLA service.
34+
*/
35+
public static final String REFERENCE_XMLA_SERVICE = "xmlaService";
36+
37+
/**
38+
* Constant for the OSGi HTTP Whiteboard servlet pattern property. Service property specifying the
39+
* request mappings for a Servlet service. This allows specifying paths or patterns that the servlet
40+
* should listen to according to the Jakarta Servlet specification.
41+
*/
42+
public static final String SERVLET_PATTERN_PROPERTY = "osgi.http.whiteboard.servlet.pattern";
43+
44+
/**
45+
* Default value for the servlet pattern property.
46+
*/
47+
public static final String DEFAULT_SERVLET_PATTERN = "/daanse/xmla";
48+
49+
/**
50+
* Constant for the OSGi HTTP Whiteboard context select property. Service property referencing a
51+
* ServletContextHelper service. For servlet, listener, servlet filter, or resource services, this
52+
* service property refers to the associated ServletContextHelper service. The value of this
53+
* property is a filter expression which is matched against the service registration properties of
54+
* the ServletContextHelper service. If this service property is not specified, the default context
55+
* is used.
56+
*/
57+
public static final String SERVLET_CONTEXT_SELECT_PROPERTY = "osgi.http.whiteboard.context.select";
58+
59+
/**
60+
* Constant for the OSGi HTTP Whiteboard servlet name property. Service property specifying the
61+
* servlet name of a Servlet service. The servlet is registered with this name and the name can be
62+
* used as a reference to the servlet for filtering or request dispatching. This name is in addition
63+
* used as the value for the ServletConfig.getServletName() method. If this service property is not
64+
* specified, the fully qualified name of the service object's class is used as the servlet name.
65+
* Servlet names should be unique among all servlet services associated with a single
66+
* ServletContextHelper.
67+
*/
68+
public static final String SERVLET_NAME_PROPERTY = "osgi.http.whiteboard.servlet.name";
69+
70+
/**
71+
* Default value for the servlet name property.
72+
*/
73+
public static final String DEFAULT_SERVLET_NAME = "XMLA Servlet";
74+
75+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2023 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+
* SmartCity Jena - initial
12+
*/
13+
@Export
14+
@Version("0.0.1")
15+
package org.eclipse.daanse.xmla.server.jakarta.saaj.api;
16+
17+
import org.osgi.annotation.bundle.Export;
18+
import org.osgi.annotation.versioning.Version;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.eclipse.daanse.xmla.server.jakarta.saaj.impl;
2+
3+
import org.eclipse.daanse.xmla.server.jakarta.saaj.api.Constants;
4+
import org.osgi.service.metatype.annotations.AttributeDefinition;
5+
6+
public interface ServletOCD {
7+
8+
String L10N_SERVLET_NAME_NAME = XmlaServletOCD.L10N_PREFIX + Constants.SERVLET_NAME_PROPERTY
9+
+ XmlaServletOCD.L10N_POSTFIX_NAME;
10+
String L10N_SERVLET_NAME_DESCRIPTION = XmlaServletOCD.L10N_PREFIX + Constants.SERVLET_NAME_PROPERTY
11+
+ XmlaServletOCD.L10N_POSTFIX_DESCRIPTION;
12+
13+
String L10N_SERVLET_CONTEXT_SELECT_NAME = XmlaServletOCD.L10N_PREFIX + Constants.SERVLET_CONTEXT_SELECT_PROPERTY
14+
+ XmlaServletOCD.L10N_POSTFIX_NAME;
15+
16+
String L10N_SERVLET_CONTEXT_SELECT_DESCRIPTION = XmlaServletOCD.L10N_PREFIX
17+
+ Constants.SERVLET_CONTEXT_SELECT_PROPERTY + XmlaServletOCD.L10N_POSTFIX_DESCRIPTION;
18+
19+
String L10N_SERVLET_PATTERN_NAME = XmlaServletOCD.L10N_PREFIX + Constants.SERVLET_PATTERN_PROPERTY
20+
+ XmlaServletOCD.L10N_POSTFIX_NAME;
21+
String L10N_SERVLET_PATTERN_DESCRIPTION = XmlaServletOCD.L10N_PREFIX + Constants.SERVLET_PATTERN_PROPERTY
22+
+ XmlaServletOCD.L10N_POSTFIX_DESCRIPTION;
23+
24+
@AttributeDefinition(name = L10N_SERVLET_NAME_NAME, description = L10N_SERVLET_NAME_DESCRIPTION, defaultValue = Constants.DEFAULT_SERVLET_NAME)
25+
default String osgi_http_whiteboard_servlet_name() {
26+
return Constants.DEFAULT_SERVLET_NAME;
27+
}
28+
29+
@AttributeDefinition(name = L10N_SERVLET_PATTERN_NAME, description = L10N_SERVLET_PATTERN_DESCRIPTION, defaultValue = Constants.DEFAULT_SERVLET_PATTERN)
30+
default String osgi_http_whiteboard_servlet_pattern() {
31+
return Constants.DEFAULT_SERVLET_PATTERN;
32+
}
33+
34+
@AttributeDefinition(name = L10N_SERVLET_CONTEXT_SELECT_NAME, description = L10N_SERVLET_CONTEXT_SELECT_DESCRIPTION, required = false)
35+
String osgi_http_whiteboard_context_select();
36+
37+
}

server/jakarta.saaj/src/main/java/org/eclipse/daanse/xmla/server/jakarta/saaj/XmlaServlet.java renamed to server/jakarta.saaj/src/main/java/org/eclipse/daanse/xmla/server/jakarta/saaj/impl/XmlaServlet.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
* Contributors:
1111
* SmartCity Jena - initial
1212
*/
13-
package org.eclipse.daanse.xmla.server.jakarta.saaj;
13+
package org.eclipse.daanse.xmla.server.jakarta.saaj.impl;
1414

1515
import jakarta.servlet.Servlet;
1616
import jakarta.xml.soap.MimeHeader;
1717
import jakarta.xml.soap.SOAPMessage;
1818
import org.eclipse.daanse.jakarta.servlet.soap.AbstractSoapServlet;
1919
import org.eclipse.daanse.xmla.api.XmlaService;
2020
import org.eclipse.daanse.xmla.server.adapter.soapmessage.XmlaApiAdapter;
21+
import org.eclipse.daanse.xmla.server.jakarta.saaj.api.Constants;
2122
import org.osgi.service.component.annotations.Activate;
2223
import org.osgi.service.component.annotations.Component;
2324
import org.osgi.service.component.annotations.Reference;
2425
import org.osgi.service.component.annotations.ServiceScope;
26+
import org.osgi.service.metatype.annotations.Designate;
2527
import org.osgi.service.servlet.whiteboard.propertytypes.HttpWhiteboardServletPattern;
2628
import org.slf4j.Logger;
2729
import org.slf4j.LoggerFactory;
@@ -36,18 +38,20 @@
3638
import java.util.stream.StreamSupport;
3739

3840
@HttpWhiteboardServletPattern("/xmla")
41+
@Designate(ocd = XmlaServletOCD.class, factory = true)
3942
@Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
4043
public class XmlaServlet extends AbstractSoapServlet {
4144

45+
private static final long serialVersionUID = 1L;
4246
private static Logger LOGGER = LoggerFactory.getLogger(XmlaServlet.class);
43-
private XmlaApiAdapter wsAdapter;
47+
private XmlaApiAdapter xmlaAdapter;
4448

45-
@Reference
49+
@Reference(name = Constants.REFERENCE_XMLA_SERVICE)
4650
private XmlaService xmlaService;
4751

4852
@Activate
4953
public void activate() {
50-
wsAdapter = new XmlaApiAdapter(xmlaService);
54+
xmlaAdapter = new XmlaApiAdapter(xmlaService);
5155
}
5256

5357
@Override
@@ -57,9 +61,10 @@ public SOAPMessage onMessage(SOAPMessage soapMessage) {
5761
LOGGER.debug("SoapMessage in:", prettyPrint(soapMessage).toString());
5862
}
5963
Iterable<MimeHeader> iterable = () -> soapMessage.getMimeHeaders().getAllHeaders();
60-
Map<String, Object> map = StreamSupport.stream(iterable.spliterator(), true).collect(Collectors.toMap(MimeHeader::getName, MimeHeader::getValue, (oldValue, newValue) -> oldValue));
64+
Map<String, Object> map = StreamSupport.stream(iterable.spliterator(), true).collect(
65+
Collectors.toMap(MimeHeader::getName, MimeHeader::getValue, (oldValue, newValue) -> oldValue));
6166

62-
SOAPMessage returnMessage = wsAdapter.handleRequest(soapMessage, map);
67+
SOAPMessage returnMessage = xmlaAdapter.handleRequest(soapMessage, map);
6368

6469
LOGGER.debug("SoapMessage out:", prettyPrint(returnMessage).toString());
6570

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.xmla.server.jakarta.saaj.impl;
15+
16+
import org.eclipse.daanse.xmla.server.jakarta.saaj.api.Constants;
17+
import org.osgi.service.metatype.annotations.AttributeDefinition;
18+
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
19+
20+
@ObjectClassDefinition(name = XmlaServletOCD.L10N_OCD_NAME, description = XmlaServletOCD.L10N_OCD_DESCRIPTION, localization = XmlaServletOCD.OCD_LOCALIZATION)
21+
public interface XmlaServletOCD extends ServletOCD {
22+
23+
String OCD_LOCALIZATION = "OSGI-INF/l10n/org.eclipse.daanse.xmla.server.jakarta.saaj.ocd";
24+
String L10N_PREFIX = "%";
25+
String L10N_POSTFIX_DESCRIPTION = ".description";
26+
String L10N_POSTFIX_NAME = ".name";
27+
28+
String L10N_OCD_NAME = L10N_PREFIX + "ocd.xmlaservlet" + L10N_POSTFIX_NAME;
29+
String L10N_OCD_DESCRIPTION = L10N_PREFIX + "ocd.xmlaservlet" + L10N_POSTFIX_DESCRIPTION;
30+
31+
String L10N_XMLA_SERVICE_TARGET_NAME = L10N_PREFIX + Constants.REFERENCE_XMLA_SERVICE + ".target"
32+
+ L10N_POSTFIX_NAME;
33+
String L10N_XMLA_SERVICE_TARGET_DESCRIPTION = L10N_PREFIX + Constants.REFERENCE_XMLA_SERVICE + ".target"
34+
+ L10N_POSTFIX_DESCRIPTION;
35+
36+
@AttributeDefinition(name = L10N_XMLA_SERVICE_TARGET_NAME, description = L10N_XMLA_SERVICE_TARGET_DESCRIPTION)
37+
String xmlaService_target();
38+
}

server/jakarta.saaj/src/main/java/org/eclipse/daanse/xmla/server/jakarta/saaj/package-info.java renamed to server/jakarta.saaj/src/main/java/org/eclipse/daanse/xmla/server/jakarta/saaj/impl/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
* Contributors:
1111
* SmartCity Jena - initial
1212
*/
13-
package org.eclipse.daanse.xmla.server.jakarta.saaj;
13+
package org.eclipse.daanse.xmla.server.jakarta.saaj.impl;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# XMLA Jakarta SAAJ Servlet Configuration Localization
2+
3+
# OCD Names and Descriptions
4+
ocd.xmlaservlet.name=XMLA Jakarta SAAJ Servlet
5+
ocd.xmlaservlet.description=XMLA web interface based on a Jakarta SAAJ Servlet. This can easily be integrated as a servlet into the Servlet Whiteboard. Further details can be found in the OSGi Servlet Specification.
6+
7+
# Servlet Pattern Property
8+
osgi.http.whiteboard.servlet.pattern.name=Servlet Pattern
9+
osgi.http.whiteboard.servlet.pattern.description=Service property specifying the request mappings for a Servlet service. Allows specifying paths or patterns that the servlet should listen to according to the Jakarta Servlet specification.
10+
11+
# Servlet Name Property
12+
osgi.http.whiteboard.servlet.name.name=Servlet Name
13+
osgi.http.whiteboard.servlet.name.description=Service property specifying the servlet name. The servlet is registered with this name and can be used as a reference for filtering or request dispatching. If not specified, the fully qualified class name is used. Servlet names should be unique among all servlet services associated with a single ServletContextHelper.
14+
15+
# Servlet Context Select Property
16+
osgi.http.whiteboard.context.select.name=Servlet Context Select
17+
osgi.http.whiteboard.context.select.description=Service property referencing a ServletContextHelper service. The value is a filter expression matched against service registration properties of the ServletContextHelper service. If not specified, the default context is used. Examples: "(osgi.http.whiteboard.context.name=Admin)" or "(osgi.http.whiteboard.context.name=*)".
18+
19+
# XMLA Service Target Property
20+
xmlaService.target.name=XMLA Service Target
21+
xmlaService.target.description=Service filter for selecting the XMLA Service that will be provided under the servlet URL

0 commit comments

Comments
 (0)