I was just telling Alex that I'm not sure how the code ended up as it is because I remember hooking it up in start(). The activation operation is always called last, after the services are set.
This was most likely some error during our transition to Github. Maybe I forgot to merge a branch or commit something.
Jay
On Apr 22, 2015 12:13 PM, "Jordan Deyton" <deytonjh@xxxxxxxx> wrote:
I wanted to find some sort of documentation about this outside a
short StackOverflow answer, and found something in the Eclipse
series book, OSGi and Equinox.
In section 15.2.2 (p250 in my copy), it says "the activate method is
called immediately upon the component's configuration being
satisfied...."
In section 24.2.1 (p445 in my copy), a component's configuration is
satisfied if ... "all of the component's referenced services have
been acquired per their cardinality attribute".
So, start(...) will *always* be called after setHttpService(...) and
the other service references are set. Doing cool things with the
HttpService reference should be happening in the start(...) method,
which is set as the component activation method in the component.xml
(see the overview page).
Jordan and I
just dug around a little bit and found that the setHttpService
method, which is bound to the Core’s Referenced Services,
should not be doing all that heavy lifting after the service
is set. Basically, the service reference should just be set,
and then the connection / register servlet stuff after it
should be done in the start method (or some private method
invoked at the end of start), which is the Core’s activate
method on the component definition.
This seems to be an easy fix, we can move forward with it if
you’re cool with it.
Yeah, that is not the way to fix that problem. I'll look into
this at some point. As of, I think, Christmas, the HTTP
service worked fine, but I notice now that ICE isn't
registering with it correctly. Hopefully I'll fix this later
today or tomorrow.
Jay
On Wed, Apr 22, 2015 at 10:30 AM, McCaskey, Alex <mccaskeyaj@xxxxxxxx<mailto:mccaskeyaj@xxxxxxxx>>
wrote:
I forgot to add that the Core as it is could not establish
this connection.
Basically, the Core.setHttpService method was being called
through the OSGi DS before the Core.start method was being
called. The start method initializes the ComponentContext
object which is used by the setHttpService method, so the
method was throwing a NullPointerException when it went to use
the ComponentContext because it hadn’t been set yet.
To fix this, I just added a call to setHttpService at the end
of the start method and added a null check for the
componentContext in setHttpService. I’m sure there’s a better
way to fix this, so I’ll hold of on committing any changes. I
didn’t take any time to dig into a better fix.
Here’s the code I was able to put together to let python post
updates to a running Core instance.
import json
import requests
import base64
if __name__ == '__main__':
# Set the ICore url for updates
url = "" href="http://localhost:8080/ice/update" target="_blank">http://localhost:8080/ice/update'
# It requires the username:password be encoded
s = base64.b64encode('ice:veryice')
# Set up your json map
payload = {'some': 'data'}
# Set up the headers, These have to be here
headers = {'Authorization' : 'Basic ' + s, 'Content-type':
'application/x-www-form-urlencoded', 'Accept': 'text/plain'}
# Start a requests session
session = requests.session()
# Get the ICE update url
session.get(url)
# Post the json message with the given headers
r = session.post(url, json=payload, headers=headers)
print r
# Close the session
session.close()
Jordan, I imagine you should be able to start experimenting
with the Peacock IO stuff using this code now.