I think I found a solution. All I did was to change the
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH of the DeviceContextHelper
to "=/" as follows. It also allow me to change the context name in servlet,
filter and the helper. I still appreciate if someone explain why context path
did not work for the DeviceContextHelper. So solution in DS as follows for
others to benefit:
ServletContextHelper Code (full code)
@Component(service = ServletContextHelper.class, scope = ServiceScope.BUNDLE,
property = {
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=your_context_name",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH + "=/" })
public class DeviceContextHelper extends ServletContextHelper {
@Override
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse
response) throws IOException {
return true;
}
}
SERVLET CODE
@Component(service = Servlet.class, property = {
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=("
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=your_context_name)",
HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN + "=/devices" })
public class DeviceRestProvider extends HttpServlet {
....
}
FILTER CODE
@Component(property = { HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN
+ "=/*",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=("
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=your_context_name)"
})
public class DeviceFilter implements Filter {
...
}
thanks in advance
-Daghan
________________________________
From: [email protected] <[email protected]> on behalf
of Daghan ACAY <[email protected]>
Sent: Tuesday, August 16, 2016 11:15 AM
To: [email protected]
Subject: [osgi-dev] Osgi Web Whiteboard specification
Dear all,
I am trying to use OSGi HTTP Whiteboard specifications to handle security on
Servlets using DS. I found this page
http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html
and also this example
http://svn.apache.org/repos/asf/felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/whiteboard/
Here is how far I got using "default" context. (using another context stops
servlet from working, which I wish to get working ideally)
ServletContextHelper Code (full code)
@Component(service = ServletContextHelper.class, scope = ServiceScope.BUNDLE,
property = {
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=default",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH + "=/devices" })
public class DeviceContextHelper extends ServletContextHelper {
@Override
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse
response) throws IOException {
return true;
}
}
SERVLET CODE
@Component(service = Servlet.class, property = {
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=("
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=default)",
HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN + "=/devices" })
public class DeviceRestProvider extends HttpServlet {
....
}
FILTER CODE
@Component(property = { HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN
+ "=/*",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=("
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=default)" })
public class DeviceFilter implements Filter {
...
}
With this code call to http://localhost:8080/devices/sensor3
I receive the following
--------------
HTTP ERROR: 404
Problem accessing /devices/sensor3. Reason:
File devices/sensor3 could not be found
________________________________
Powered by Jetty://
--------------------
Can you let me know what I am doing wrong?
Cheers
-Daghan
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev