You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Evan Ruff <ev...@hendersonsawmill.com> on 2012/08/23 00:18:11 UTC

Change HTTPService Port Through Configuration Admin

Hey guys!

I'm having some problems changing the port of the HttpService using the
Configuration Admin.

In my activator, I get the ExtHttpService through a service tracker. Once
I've got the service, I add some Servlets and a Servlet Filter to it. Once
that's done, go hit the ConfigurationAdmin to try to change the port.

Every time I get the properties, it's null. I change it and do the Update,
but it has no effect.

Can someone tell me what I'm doing wrong? Here's my method:

private void setHttpConnectorInfo ()
{
 try
{
 ServiceReference configurationAdminReference =
bundleContext.getServiceReference( ConfigurationAdmin.class.getName() );
 if ( configurationAdminReference != null )
{
 ConfigurationAdmin confAdmin = ( ConfigurationAdmin )
bundleContext.getService( configurationAdminReference );
 Configuration configuration = confAdmin.getConfiguration(
"org.apache.felix.http", CORE_SERVICE_LOCATION );
 Dictionary properties = configuration.getProperties();
if ( properties == null )
 {
properties = new Hashtable();
 }

properties.put( "service.pid", "org.apache.felix.http" );
 properties.put( "org.osgi.service.http.port", "80" );
properties.put( "org.apache.felix.http.jettyEnabled", "true" );
 configuration.update();
}
 }
catch ( Exception ioEx )
 {
ioEx.printStackTrace();
 }
}

I've been porting my application over to OSGi/Felix and, I have to say,
it's quite a bear. This is my last outstanding thing!! ALMOST THERE!

Appreciate all your help guys!

Thanks,

E

Re: Change HTTPService Port Through Configuration Admin

Posted by Evan Ruff <ev...@hendersonsawmill.com>.
My god. I can't believe I biff'd that.

Thanks guys. I am quite dumb.

E

On Thu, Aug 23, 2012 at 2:20 AM, Felix Meschberger <fm...@adobe.com>wrote:

> Hi,
>
> Am 23.08.2012 um 05:46 schrieb Chetan Mehrotra:
>
> > From the code below it appears that the new properties instance that you
> > create is not being passed back. Try passing the properties object as
> part
> > of update call
> >
> > configuration.update(properties);
>
> Correct.
>
> Configuration.getProperties() returns a private copy which you may modify
> at your desire. To write back the changes your have to call the
> Configuration.update(Dictionary) method.
>
> The Configuration.update() method just causes the configuration to be read
> from persistence again, which is not what you want.
>
> Regards
> Felix
>
> >
> > Chetan Mehrotra
> >
> >
> > On Thu, Aug 23, 2012 at 3:48 AM, Evan Ruff
> > <ev...@hendersonsawmill.com>wrote:
> >
> >> Hey guys!
> >>
> >> I'm having some problems changing the port of the HttpService using the
> >> Configuration Admin.
> >>
> >> In my activator, I get the ExtHttpService through a service tracker.
> Once
> >> I've got the service, I add some Servlets and a Servlet Filter to it.
> Once
> >> that's done, go hit the ConfigurationAdmin to try to change the port.
> >>
> >> Every time I get the properties, it's null. I change it and do the
> Update,
> >> but it has no effect.
> >>
> >> Can someone tell me what I'm doing wrong? Here's my method:
> >>
> >> private void setHttpConnectorInfo ()
> >> {
> >> try
> >> {
> >> ServiceReference configurationAdminReference =
> >> bundleContext.getServiceReference( ConfigurationAdmin.class.getName() );
> >> if ( configurationAdminReference != null )
> >> {
> >> ConfigurationAdmin confAdmin = ( ConfigurationAdmin )
> >> bundleContext.getService( configurationAdminReference );
> >> Configuration configuration = confAdmin.getConfiguration(
> >> "org.apache.felix.http", CORE_SERVICE_LOCATION );
> >> Dictionary properties = configuration.getProperties();
> >> if ( properties == null )
> >> {
> >> properties = new Hashtable();
> >> }
> >>
> >> properties.put( "service.pid", "org.apache.felix.http" );
> >> properties.put( "org.osgi.service.http.port", "80" );
> >> properties.put( "org.apache.felix.http.jettyEnabled", "true" );
> >> configuration.update();
> >> }
> >> }
> >> catch ( Exception ioEx )
> >> {
> >> ioEx.printStackTrace();
> >> }
> >> }
> >>
> >> I've been porting my application over to OSGi/Felix and, I have to say,
> >> it's quite a bear. This is my last outstanding thing!! ALMOST THERE!
> >>
> >> Appreciate all your help guys!
> >>
> >> Thanks,
> >>
> >> E
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: Change HTTPService Port Through Configuration Admin

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 23.08.2012 um 05:46 schrieb Chetan Mehrotra:

> From the code below it appears that the new properties instance that you
> create is not being passed back. Try passing the properties object as part
> of update call
> 
> configuration.update(properties);

Correct.

Configuration.getProperties() returns a private copy which you may modify at your desire. To write back the changes your have to call the Configuration.update(Dictionary) method.

The Configuration.update() method just causes the configuration to be read from persistence again, which is not what you want.

Regards
Felix

> 
> Chetan Mehrotra
> 
> 
> On Thu, Aug 23, 2012 at 3:48 AM, Evan Ruff
> <ev...@hendersonsawmill.com>wrote:
> 
>> Hey guys!
>> 
>> I'm having some problems changing the port of the HttpService using the
>> Configuration Admin.
>> 
>> In my activator, I get the ExtHttpService through a service tracker. Once
>> I've got the service, I add some Servlets and a Servlet Filter to it. Once
>> that's done, go hit the ConfigurationAdmin to try to change the port.
>> 
>> Every time I get the properties, it's null. I change it and do the Update,
>> but it has no effect.
>> 
>> Can someone tell me what I'm doing wrong? Here's my method:
>> 
>> private void setHttpConnectorInfo ()
>> {
>> try
>> {
>> ServiceReference configurationAdminReference =
>> bundleContext.getServiceReference( ConfigurationAdmin.class.getName() );
>> if ( configurationAdminReference != null )
>> {
>> ConfigurationAdmin confAdmin = ( ConfigurationAdmin )
>> bundleContext.getService( configurationAdminReference );
>> Configuration configuration = confAdmin.getConfiguration(
>> "org.apache.felix.http", CORE_SERVICE_LOCATION );
>> Dictionary properties = configuration.getProperties();
>> if ( properties == null )
>> {
>> properties = new Hashtable();
>> }
>> 
>> properties.put( "service.pid", "org.apache.felix.http" );
>> properties.put( "org.osgi.service.http.port", "80" );
>> properties.put( "org.apache.felix.http.jettyEnabled", "true" );
>> configuration.update();
>> }
>> }
>> catch ( Exception ioEx )
>> {
>> ioEx.printStackTrace();
>> }
>> }
>> 
>> I've been porting my application over to OSGi/Felix and, I have to say,
>> it's quite a bear. This is my last outstanding thing!! ALMOST THERE!
>> 
>> Appreciate all your help guys!
>> 
>> Thanks,
>> 
>> E
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Change HTTPService Port Through Configuration Admin

Posted by Chetan Mehrotra <ch...@gmail.com>.
>From the code below it appears that the new properties instance that you
create is not being passed back. Try passing the properties object as part
of update call

configuration.update(properties);

Chetan Mehrotra


On Thu, Aug 23, 2012 at 3:48 AM, Evan Ruff
<ev...@hendersonsawmill.com>wrote:

> Hey guys!
>
> I'm having some problems changing the port of the HttpService using the
> Configuration Admin.
>
> In my activator, I get the ExtHttpService through a service tracker. Once
> I've got the service, I add some Servlets and a Servlet Filter to it. Once
> that's done, go hit the ConfigurationAdmin to try to change the port.
>
> Every time I get the properties, it's null. I change it and do the Update,
> but it has no effect.
>
> Can someone tell me what I'm doing wrong? Here's my method:
>
> private void setHttpConnectorInfo ()
> {
>  try
> {
>  ServiceReference configurationAdminReference =
> bundleContext.getServiceReference( ConfigurationAdmin.class.getName() );
>  if ( configurationAdminReference != null )
> {
>  ConfigurationAdmin confAdmin = ( ConfigurationAdmin )
> bundleContext.getService( configurationAdminReference );
>  Configuration configuration = confAdmin.getConfiguration(
> "org.apache.felix.http", CORE_SERVICE_LOCATION );
>  Dictionary properties = configuration.getProperties();
> if ( properties == null )
>  {
> properties = new Hashtable();
>  }
>
> properties.put( "service.pid", "org.apache.felix.http" );
>  properties.put( "org.osgi.service.http.port", "80" );
> properties.put( "org.apache.felix.http.jettyEnabled", "true" );
>  configuration.update();
> }
>  }
> catch ( Exception ioEx )
>  {
> ioEx.printStackTrace();
>  }
> }
>
> I've been porting my application over to OSGi/Felix and, I have to say,
> it's quite a bear. This is my last outstanding thing!! ALMOST THERE!
>
> Appreciate all your help guys!
>
> Thanks,
>
> E
>