HOW TO CONNECT
YOUR
OSGI APPLICATION
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
2
How to connect your OSGi application
Speaker
Dirk Fauth
System-Architect
Eclipse Committer
Robert Bosch GmbH
Franz-Oechsle-Straße 4
73207 Plochingen
dirk.fauth@de.bosch.com
www.bosch.com
blog.vogella.com/author/fipro/
Twitter: fipro78
INTRODUCTION
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
4
Introduction
Application A Application B
S
S
S
S
Communication Protocol,
e.g. JSON via HTTP
What does OSGi provide to realize this szenario?
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
5
Setup
JVM
OSGi Framework
JSON Converter
Servlet Container
???
e.g. Equinox or Felix
SCR Felix SCR
e.g. Jetty
Application / Services
e.g. Jackson
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
6
Setup - Service
public interface StringModifier {
String modify(String input);
}
@Component
public class StringInverter implements StringModifier {
@Override
public String modify(String input) {
return new StringBuilder(input).reverse().toString();
}
}
M(ost) U(seless) S(ervice) E(ver)
HTTP SERVICE
HTTP WHITEBOARD
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
8
HTTP Service / HTTP Whiteboard
JVM
OSGi Framework
JSON Converter
Servlet Container
HTTP Service / HTTP Whiteboard
SCR
Application / Services
Servlet
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
9
HTTP Service / HTTP Whiteboard
@Component(
service=Servlet.class,
property= "osgi.http.whiteboard.servlet.pattern=/modify",
scope=ServiceScope.PROTOTYPE)
public class ModifierServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Reference private volatile List<StringModifier> modifier;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
try {
String json = objectMapper.writeValueAsString(
modifier.stream().map(x -> x.modify(input)).collect(toList()));
resp.getWriter().write(json);
} catch (JsonProcessingException e) { ... }
}
}
@Component(
service=Servlet.class,
property= "osgi.http.whiteboard.servlet.pattern=/modify",
scope=ServiceScope.PROTOTYPE)
public class ModifierServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Reference private volatile List<StringModifier> modifier;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
try {
String json = objectMapper.writeValueAsString(
modifier.stream().map(x -> x.modify(input)).collect(toList()));
resp.getWriter().write(json);
} catch (JsonProcessingException e) { ... }
}
}
@Component(
service=Servlet.class,
property= "osgi.http.whiteboard.servlet.pattern=/modify",
scope=ServiceScope.PROTOTYPE)
public class ModifierServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Reference private volatile List<StringModifier> modifier;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
try {
String json = objectMapper.writeValueAsString(
modifier.stream().map(x -> x.modify(input)).collect(toList()));
resp.getWriter().write(json);
} catch (JsonProcessingException e) { ... }
}
}
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
10
HTTP Service / HTTP Whiteboard
Service URL: http://localhost:8080/modify?value=Eclipse
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
11
 Cons
 Dependency to Servlet API
 Conversion done in the service
 Pros
 Very simple
 Small number of bundles
HTTP Service / HTTP Whiteboard
REMOTE
SERVICES
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
13
Remote Services
Service
Producer
Remote Service
Implementation
endpoint
created by RSA
announced by Discovery
Service
Consumer
endpoint
discovered by Discovery
proxied by RSA
Remote Service
Implementation
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
15
Remote Services
JVM
OSGi Framework
JSON Converter
Servlet Container
HTTP Service / HTTP Whiteboard
SCR
Application / Services
Remote Service / RSA
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
16
Remote Services
@Component(property= {
"service.exported.interfaces=*",
"service.exported.configs=ecf.generic.server"
})
public class StringInverter implements StringModifier {
@Override
public String modify(String input) {
return new StringBuilder(input).reverse().toString();
}
}
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
17
Remote Services
@Path("/modify")
@Component(
immediate = true,
property = { "service.exported.interfaces=*",
"service.intents=osgi.async",
"service.intents=jaxrs",
"osgi.basic.timeout=50000" })
public class ModifierServiceImpl implements ModifierService {
@Reference private volatile List<StringModifier> modifier;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{value}")
@Override
public List<String> getModifications(@PathParam("value") String value) {
return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList());
}
}
@Path("/modify")
@Component(
immediate = true,
property = { "service.exported.interfaces=*",
"service.intents=osgi.async",
"service.intents=jaxrs",
"osgi.basic.timeout=50000" })
public class ModifierServiceImpl implements ModifierService {
@Reference private volatile List<StringModifier> modifier;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{value}")
@Override
public List<String> getModifications(@PathParam("value") String value) {
return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList());
}
}
@Path("/modify")
@Component(
immediate = true,
property = { "service.exported.interfaces=*",
"service.intents=osgi.async",
"service.intents=jaxrs",
"osgi.basic.timeout=50000" })
public class ModifierServiceImpl implements ModifierService {
@Reference private volatile List<StringModifier> modifier;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{value}")
@Override
public List<String> getModifications(@PathParam("value") String value) {
return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList());
}
}
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
14
 Various protocols available (e.g. via ECF)
 Discovery
‒ Zeroconf/aka Bonjour/Rendevous (JmDNS)
‒ jSLP aka SLP/RFC2608
 Distribution Provider
‒ Generic Provider
‒ r-OSGi Provider
‒ Jax-RS Distribution Provider
Remote Services
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
18
Remote Services
Service URL: http://localhost:8080/1/modify/Eclipse
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
19
 Cons
 Complicated bundle composition
 High risk with networking issues
 Client side is an OSGi application
 URL contains dynamic containerID
 Pros
 Simple definition via component
properties
 Usage of default JAX-RS
annotations
 Importing remote services without
efforts in programming
Remote Services
JAX-RS
WHITEBOARD
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
21
JAX-RS Whiteboard
JVM
OSGi Framework
JSON Converter
Servlet Container
HTTP Service / HTTP Whiteboard
SCR
Application / Services
JAX-RS Whiteboard
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
22
JAX-RS Whiteboard
@Path("/modify")
@Produces(MediaType.APPLICATION_JSON)
@Component(service=ModifierServiceImpl.class)
@JaxrsResource
@JSONRequired
public class ModifierServiceImpl {
@Reference
private volatile List<StringModifier> modifier;
@GET
@Path("/{value}")
public List<String> getModifications(@PathParam("value") String value) {
return modifier.stream().map(x -> x.modify(value)).collect(toList());
}
}
@Path("/modify")
@Produces(MediaType.APPLICATION_JSON)
@Component(service=ModifierServiceImpl.class)
@JaxrsResource
@JSONRequired
public class ModifierServiceImpl {
@Reference
private volatile List<StringModifier> modifier;
@GET
@Path("/{value}")
public List<String> getModifications(@PathParam("value") String value) {
return modifier.stream().map(x -> x.modify(value)).collect(toList());
}
}
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
23
JAX-RS Whiteboard
@Component(scope = PROTOTYPE)
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON)
public class JacksonJsonConverter<T>
implements MessageBodyReader<T>, MessageBodyWriter<T> {
@Reference(service=LoggerFactory.class)
private Logger logger;
private final Converter converter = Converters.newConverterBuilder()
.rule(String.class, this::toJson)
.rule(this::toObject)
.build();
private ObjectMapper mapper = new ObjectMapper();
...
@Component(scope = PROTOTYPE)
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON)
public class JacksonJsonConverter<T>
implements MessageBodyReader<T>, MessageBodyWriter<T> {
@Reference(service=LoggerFactory.class)
private Logger logger;
private final Converter converter = Converters.newConverterBuilder()
.rule(String.class, this::toJson)
.rule(this::toObject)
.build();
private ObjectMapper mapper = new ObjectMapper();
...
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
24
JAX-RS Whiteboard
Service URL: http://localhost:8080/modify/Eclipse
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
26
 Cons
 Only CXF based reference
implementation from Aries
available
 osgi.contract capabilities not
widely integrated yet
 Pros
 Simple definition via Component
Property Types
 Usage of default JAX-RS
annotations
 Easy combination of different
OSGi R7 specifications
 Runtime requirements resolved
via osgi.contract capabilities
JAX-RS Whiteboard
ALTERNATIVES
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
28
 OSGi JAX-RS Connector
https://github.com/hstaudacher/osgi-jax-rs-connector
 Inactive for > 3 years
 With R7 actually no use anymore
 enRoute
https://enroute.osgi.org
 Basic guidance for using R7 specifications
 Maven based toolchain
 Custom communication implementations
Alternatives
REFERENCES
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
30
 OSGi Core Release 7 Specification
https://osgi.org/specification/osgi.core/7.0.0/
 OSGi Compendium Release 7 Specification
https://osgi.org/specification/osgi.cmpn/7.0.0/
 Eclipse Communication Framework Wiki
https://wiki.eclipse.org/Eclipse_Communication_Framework_Project#OS
Gi_Remote_Services
References
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
31
 HTTP Service Specification
https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.html
 HTTP Whiteboard Specification
https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html
 Remote Services
https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteservices.html
 Remote Service Admin Service Specification
https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteserviceadmin
.html
 JAX-RS Whiteboard Specification
https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html
References
How to connect your OSGi application
Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018
© Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen.
32
 ECF JAX-RS Distribution Provider
https://github.com/ECF/JaxRSProviders
https://wiki.eclipse.org/Tutorial:_Exposing_a_Jax_REST_service_as_an_
OSGi_Remote_Service
 Access OSGi services via web interface
http://blog.vogella.com/2017/04/20/access-osgi-services-via-web-
interface/
 Microservices with OSGi
https://www.eclipsecon.org/europe2017/session/microservices-osgi
https://www.youtube.com/watch?v=IOusIWAziFE
 Example sources
https://github.com/fipro78/access_osgi_services
References
How to connect your OSGi application - Dirk Fauth (Bosch)

How to connect your OSGi application - Dirk Fauth (Bosch)

  • 1.
  • 2.
    Automotive Service Solutions| AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 2 How to connect your OSGi application Speaker Dirk Fauth System-Architect Eclipse Committer Robert Bosch GmbH Franz-Oechsle-Straße 4 73207 Plochingen dirk.fauth@de.bosch.com www.bosch.com blog.vogella.com/author/fipro/ Twitter: fipro78
  • 3.
  • 4.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 4 Introduction Application A Application B S S S S Communication Protocol, e.g. JSON via HTTP What does OSGi provide to realize this szenario?
  • 5.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 5 Setup JVM OSGi Framework JSON Converter Servlet Container ??? e.g. Equinox or Felix SCR Felix SCR e.g. Jetty Application / Services e.g. Jackson
  • 6.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 6 Setup - Service public interface StringModifier { String modify(String input); } @Component public class StringInverter implements StringModifier { @Override public String modify(String input) { return new StringBuilder(input).reverse().toString(); } } M(ost) U(seless) S(ervice) E(ver)
  • 7.
  • 8.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 8 HTTP Service / HTTP Whiteboard JVM OSGi Framework JSON Converter Servlet Container HTTP Service / HTTP Whiteboard SCR Application / Services Servlet
  • 9.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 9 HTTP Service / HTTP Whiteboard @Component( service=Servlet.class, property= "osgi.http.whiteboard.servlet.pattern=/modify", scope=ServiceScope.PROTOTYPE) public class ModifierServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Reference private volatile List<StringModifier> modifier; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(MediaType.APPLICATION_JSON); ObjectMapper objectMapper = new ObjectMapper(); try { String json = objectMapper.writeValueAsString( modifier.stream().map(x -> x.modify(input)).collect(toList())); resp.getWriter().write(json); } catch (JsonProcessingException e) { ... } } } @Component( service=Servlet.class, property= "osgi.http.whiteboard.servlet.pattern=/modify", scope=ServiceScope.PROTOTYPE) public class ModifierServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Reference private volatile List<StringModifier> modifier; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(MediaType.APPLICATION_JSON); ObjectMapper objectMapper = new ObjectMapper(); try { String json = objectMapper.writeValueAsString( modifier.stream().map(x -> x.modify(input)).collect(toList())); resp.getWriter().write(json); } catch (JsonProcessingException e) { ... } } } @Component( service=Servlet.class, property= "osgi.http.whiteboard.servlet.pattern=/modify", scope=ServiceScope.PROTOTYPE) public class ModifierServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Reference private volatile List<StringModifier> modifier; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(MediaType.APPLICATION_JSON); ObjectMapper objectMapper = new ObjectMapper(); try { String json = objectMapper.writeValueAsString( modifier.stream().map(x -> x.modify(input)).collect(toList())); resp.getWriter().write(json); } catch (JsonProcessingException e) { ... } } }
  • 10.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 10 HTTP Service / HTTP Whiteboard Service URL: http://localhost:8080/modify?value=Eclipse
  • 11.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 11  Cons  Dependency to Servlet API  Conversion done in the service  Pros  Very simple  Small number of bundles HTTP Service / HTTP Whiteboard
  • 12.
  • 13.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 13 Remote Services Service Producer Remote Service Implementation endpoint created by RSA announced by Discovery Service Consumer endpoint discovered by Discovery proxied by RSA Remote Service Implementation
  • 14.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 15 Remote Services JVM OSGi Framework JSON Converter Servlet Container HTTP Service / HTTP Whiteboard SCR Application / Services Remote Service / RSA
  • 15.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 16 Remote Services @Component(property= { "service.exported.interfaces=*", "service.exported.configs=ecf.generic.server" }) public class StringInverter implements StringModifier { @Override public String modify(String input) { return new StringBuilder(input).reverse().toString(); } }
  • 16.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 17 Remote Services @Path("/modify") @Component( immediate = true, property = { "service.exported.interfaces=*", "service.intents=osgi.async", "service.intents=jaxrs", "osgi.basic.timeout=50000" }) public class ModifierServiceImpl implements ModifierService { @Reference private volatile List<StringModifier> modifier; @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{value}") @Override public List<String> getModifications(@PathParam("value") String value) { return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList()); } } @Path("/modify") @Component( immediate = true, property = { "service.exported.interfaces=*", "service.intents=osgi.async", "service.intents=jaxrs", "osgi.basic.timeout=50000" }) public class ModifierServiceImpl implements ModifierService { @Reference private volatile List<StringModifier> modifier; @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{value}") @Override public List<String> getModifications(@PathParam("value") String value) { return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList()); } } @Path("/modify") @Component( immediate = true, property = { "service.exported.interfaces=*", "service.intents=osgi.async", "service.intents=jaxrs", "osgi.basic.timeout=50000" }) public class ModifierServiceImpl implements ModifierService { @Reference private volatile List<StringModifier> modifier; @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{value}") @Override public List<String> getModifications(@PathParam("value") String value) { return modifier.stream().map(x -> x.modify(value)).collect(Collectors.toList()); } }
  • 17.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 14  Various protocols available (e.g. via ECF)  Discovery ‒ Zeroconf/aka Bonjour/Rendevous (JmDNS) ‒ jSLP aka SLP/RFC2608  Distribution Provider ‒ Generic Provider ‒ r-OSGi Provider ‒ Jax-RS Distribution Provider Remote Services
  • 18.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 18 Remote Services Service URL: http://localhost:8080/1/modify/Eclipse
  • 19.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 19  Cons  Complicated bundle composition  High risk with networking issues  Client side is an OSGi application  URL contains dynamic containerID  Pros  Simple definition via component properties  Usage of default JAX-RS annotations  Importing remote services without efforts in programming Remote Services
  • 20.
  • 21.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 21 JAX-RS Whiteboard JVM OSGi Framework JSON Converter Servlet Container HTTP Service / HTTP Whiteboard SCR Application / Services JAX-RS Whiteboard
  • 22.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 22 JAX-RS Whiteboard @Path("/modify") @Produces(MediaType.APPLICATION_JSON) @Component(service=ModifierServiceImpl.class) @JaxrsResource @JSONRequired public class ModifierServiceImpl { @Reference private volatile List<StringModifier> modifier; @GET @Path("/{value}") public List<String> getModifications(@PathParam("value") String value) { return modifier.stream().map(x -> x.modify(value)).collect(toList()); } } @Path("/modify") @Produces(MediaType.APPLICATION_JSON) @Component(service=ModifierServiceImpl.class) @JaxrsResource @JSONRequired public class ModifierServiceImpl { @Reference private volatile List<StringModifier> modifier; @GET @Path("/{value}") public List<String> getModifications(@PathParam("value") String value) { return modifier.stream().map(x -> x.modify(value)).collect(toList()); } }
  • 23.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 23 JAX-RS Whiteboard @Component(scope = PROTOTYPE) @JaxrsExtension @JaxrsMediaType(APPLICATION_JSON) public class JacksonJsonConverter<T> implements MessageBodyReader<T>, MessageBodyWriter<T> { @Reference(service=LoggerFactory.class) private Logger logger; private final Converter converter = Converters.newConverterBuilder() .rule(String.class, this::toJson) .rule(this::toObject) .build(); private ObjectMapper mapper = new ObjectMapper(); ... @Component(scope = PROTOTYPE) @JaxrsExtension @JaxrsMediaType(APPLICATION_JSON) public class JacksonJsonConverter<T> implements MessageBodyReader<T>, MessageBodyWriter<T> { @Reference(service=LoggerFactory.class) private Logger logger; private final Converter converter = Converters.newConverterBuilder() .rule(String.class, this::toJson) .rule(this::toObject) .build(); private ObjectMapper mapper = new ObjectMapper(); ...
  • 24.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 24 JAX-RS Whiteboard Service URL: http://localhost:8080/modify/Eclipse
  • 25.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 26  Cons  Only CXF based reference implementation from Aries available  osgi.contract capabilities not widely integrated yet  Pros  Simple definition via Component Property Types  Usage of default JAX-RS annotations  Easy combination of different OSGi R7 specifications  Runtime requirements resolved via osgi.contract capabilities JAX-RS Whiteboard
  • 26.
  • 27.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 28  OSGi JAX-RS Connector https://github.com/hstaudacher/osgi-jax-rs-connector  Inactive for > 3 years  With R7 actually no use anymore  enRoute https://enroute.osgi.org  Basic guidance for using R7 specifications  Maven based toolchain  Custom communication implementations Alternatives
  • 28.
  • 29.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 30  OSGi Core Release 7 Specification https://osgi.org/specification/osgi.core/7.0.0/  OSGi Compendium Release 7 Specification https://osgi.org/specification/osgi.cmpn/7.0.0/  Eclipse Communication Framework Wiki https://wiki.eclipse.org/Eclipse_Communication_Framework_Project#OS Gi_Remote_Services References
  • 30.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 31  HTTP Service Specification https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.html  HTTP Whiteboard Specification https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html  Remote Services https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteservices.html  Remote Service Admin Service Specification https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteserviceadmin .html  JAX-RS Whiteboard Specification https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html References
  • 31.
    How to connectyour OSGi application Automotive Service Solutions | AA-AS/EIS2-EU | 23.10.2018 © Robert Bosch GmbH 2018. Alle Rechte vorbehalten, auch bzgl. jeder Verfügung, Verwertung, Reproduktion, Bearbeitung, Weitergabe sowie für den Fall von Schutzrechtsanmeldungen. 32  ECF JAX-RS Distribution Provider https://github.com/ECF/JaxRSProviders https://wiki.eclipse.org/Tutorial:_Exposing_a_Jax_REST_service_as_an_ OSGi_Remote_Service  Access OSGi services via web interface http://blog.vogella.com/2017/04/20/access-osgi-services-via-web- interface/  Microservices with OSGi https://www.eclipsecon.org/europe2017/session/microservices-osgi https://www.youtube.com/watch?v=IOusIWAziFE  Example sources https://github.com/fipro78/access_osgi_services References