Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » javax.xml.ws.Endpoint & org.osgi.service.http.HttpService(How to remove EndpointContext from the http server?)
javax.xml.ws.Endpoint & org.osgi.service.http.HttpService [message #1703235] Wed, 29 July 2015 15:24 Go to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Hi all,

I am bit struggling with the following topic. I am by no means an expert on servlets and alike, and nor do I know this part of the core ESH code very well.

As far as I understand, when you use javax.xml.ws.* web services in Java, you basically register - in my usecase SOAP - services on the set http server in the JVM. As far as I understand, in ESH, this is provided by org.osgi.service.http.HttpService, right?

I have a binding for which the Thing Handler is basically a web service that publishes its service using Endpoint.publish() on a URL, which is something like openhabserver:portnumber/notification , with each Thing having its own portnumber (to keep communication flows apart).

The service stack on the physical device (in this case, a videophone) is configured through a series of calls, and basically it is told where to publish events, e.g openhabserver:portnumber/notification. However, when the videophone is reconfigured, or looses power, it kinda resets all its communications stacks, and thus it also looses the information where to publish its event data. In other words, the whole configuration handshaking process of the Thing Handler has to be done over again

the Thing Handler can detect this situation, and could do a dispose()/initialize() sequence to get things going again. However, when doing so, I get things like

2015-07-28 20:09:54 [ERROR] [b.helios.handler.HeliosHandler:174 ] - An exception occurred while setting up the notification consumer webservice: Server Runtime Error: java.lang.IllegalArgumentException: Context with URL path /notification already exists on the server /192.168.0.5:8502

e.g. the server implementation of ESH does not allow to re-use the context of the Endpoint. Note that the Endpoint.stop() method is called before

There are a few quick solutions to this problem:
1. use a different url, like /notification-something
2. use a different port number, like portnumber+1, +2, ... until you find a port that works/is free

The better solution would be to remove the offending Context, but I don't know how this can be done (cfr org.osgi.service.http.HttpService), let alone if it can be done.

Strangely enough, when I google the exception.message() nothing shows up, so, I do not even know where to look.

Any help or ideas are appreciated

Karel
Re: javax.xml.ws.Endpoint & org.osgi.service.http.HttpService [message #1703248 is a reply to message #1703235] Wed, 29 July 2015 18:15 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Ok - in the meantime I understood that the javax package is basically using com.sun.net.httpserver.HttpServer as an underlying server infrastructure (https://today.java.net/pub/a/today/2007/07/03/jax-ws-web-services-without-ee-containers.html).

So, to rephrase the subject in the ESH context: should I stay with this httpServer implementation or use the Jetty-via-OSGi implemtation? Is there a chance that this could clash with what is already used by the core? and in doing so, I presume that the ESH core has a clean tear-down procedure when it is stopped?

Karel
Re: javax.xml.ws.Endpoint & org.osgi.service.http.HttpService [message #1703400 is a reply to message #1703248] Fri, 31 July 2015 09:59 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Hi Karel,

In general I think it is a bad idea to launch a second HTTP server besides the already existing one (Jetty in the case of openHAB). I must admit that I have never used JAX-WS so far and thus cannot really give good advice on how to make it work on an OSGi HttpService. What the HttpService offers is registering servlets for certain contexts/urls - this is what e.g. the JAX-RS integration with Jersey does for offering the REST API. I guess something similar would be needed here. Didn't you do a lot of research on this before? Afair it boilt down to somehow integrating Apache CXF, right?

Regards,
Kai

Re: javax.xml.ws.Endpoint & org.osgi.service.http.HttpService [message #1703412 is a reply to message #1703400] Fri, 31 July 2015 11:53 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Yes I did but I very often do an "rm -rf *" of my brain to make room for new stuff

I have investigated it, and as far as I conceptually understand, Servlets are one layer down compared to WebServices. Servlets rather focus on the (HTTP) protocol part, whereas the WebServices focuses on the SOAP part (and JAXB etc for message handling) I have searched it but could not find a way to build a WebService with Servlets without writing a complete SOAP message handler myself. Given that on top of that I am using WS-Notification (as the videophone is only speaking that stuff), and that this implementation is available in an CXF jar, and is exposing it interfaces specifically as a WebService (XML namespace etc), I am not inclined to rewrite the binding for the sake of having one webserver. It was a very complicated thing to do the first time around.

Basically, I have given up on resetting the Context of the webserver, and rather went for the option to use a different URL. Less beautiful, but it works
Re: javax.xml.ws.Endpoint & org.osgi.service.http.HttpService [message #1703498 is a reply to message #1703412] Sat, 01 August 2015 13:09 Go to previous message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
I spent some more time on this subject, and basically, if one steps out of the ordinary WebServices stuff (that is, using web.xml for declaring services, and deploying on a standard servlet container server like tomcat or websphere), then things are a bit more complicated. In the ordinary case with tomcat and others, it is the server that will take on an HTTP request, then instantiate the servlet, contain it in a container, and have the request handled. If you on the other hand want to define your servlets beforehand, and be ready to handle HTTP requests, the whole point is that one needs to find a servlet transport mechanism that can host the WebService. And there are not many options, with in fact the only one being referenced is the Apache CXF Servlet that is Spring disabled. It looks more as a dirty hack than anything else, but one does not have any other option, as there is no real servlet container implementation in javax(.servlet). Well, there is, e.g. the HttpServlet, but if you opt for that, then you need to do write your own SOAP handler to deal with WebServices.

I will give it a try to have the Helios Thing Handlers bind the OSGi HttpService, and have them register themselves as Servlets on the already present Jetty. I am curious how this work in term of life-time management, e.g. HttpService being available, or not and so forth.

In any case, the standard javax.ws API is working well, e.g. it creates a light and standard Sun provided http server, which is maybe not ideal, but it works wonderfully well.

Maybe one day we will provide not only a full REST interface to OH, but maybe also a full SOAP WebService interface so that OH can be interconnected with other services or parties. Wink
Previous Topic:Conversion of channels to different systems of measurements
Next Topic:Yoxos installer requests credentials because of non OpenSource profile
Goto Forum:
  


Current Time: Sat Apr 20 02:47:41 GMT 2024

Powered by FUDForum. Page generated in 0.02940 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top