State of sling eclipse plugins for IDE deploy/undeploy.

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

State of sling eclipse plugins for IDE deploy/undeploy.

Bruce Edge
Also, I found 2 plugins that seem to be similar,
http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
http://sling.apache.org/documentation/development/ide-tooling.html
Which to people use?

I settled on the non-adobe one as I'm not using CQ.

Does anyone actually use the eclipse sling plugin to add/remove bundles to/from a sling server?

I got a doPost SlingAllMethodsServlet working, but only through the maven plugin, i.e.:
mvn org.apache.sling:maven-sling-plugin:install-file -Dsling.file=ingest-2.2.2.jar

Connecting to a sling server from the plugin's server manager works, as does the debugging. So just the deploy/undeploy seems broken.
I'm running on nonstandard ports (not 8080) for conflict reasons, is there anything that needs to change other than in the server's config?

I do have the port setup in the pom:
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-sling-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                    <slingUrl>http://localhost:8090/system/console</slingUrl>
                    <user>admin</user>
                    <password>admin</password>
                </configuration>
            </plugin>

-Bruce
Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Robert Munteanu-2
Hi Bruce,

On Thu, Nov 13, 2014 at 8:57 AM, Bruce Edge
<[hidden email]> wrote:
> Also, I found 2 plugins that seem to be similar,
> http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
> http://sling.apache.org/documentation/development/ide-tooling.html
> Which to people use?
>
> I settled on the non-adobe one as I'm not using CQ.

Well, that's the right approach. For now, the Adobe plugins add a new
project wizard and some AEM branding. The new project wizard generates
a project based on AEM libraries so it would not deploy on Sling at
all. The rest of the features come from the Sling IDE Tooling anyway.

>
> Does anyone actually use the eclipse sling plugin to add/remove bundles to/from a sling server?
>
> I got a doPost SlingAllMethodsServlet working, but only through the maven plugin, i.e.:
> mvn org.apache.sling:maven-sling-plugin:install-file -Dsling.file=ingest-2.2.2.jar
>
> Connecting to a sling server from the plugin's server manager works, as does the debugging. So just the deploy/undeploy seems broken.
> I'm running on nonstandard ports (not 8080) for conflict reasons, is there anything that needs to change other than in the server's config?


That should work, I'm using it for day-to-day work. A couple of questions:

1. Do you have anything in the sling log that indicates an error
deploying from Eclipse?
2. If you open the Sling console ( see [1] ) do you see anything
related to installing local bundles?

Thanks,

Robert

[1]: https://sling.apache.org/documentation/development/ide-tooling.html#gathering-debug-information

>
> I do have the port setup in the pom:
>             <plugin>
>                 <groupId>org.apache.sling</groupId>
>                 <artifactId>maven-sling-plugin</artifactId>
>                 <version>2.1.0</version>
>                 <configuration>
>                     <slingUrl>http://localhost:8090/system/console</slingUrl>
>                     <user>admin</user>
>                     <password>admin</password>
>                 </configuration>
>             </plugin>
>
> -Bruce
Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Bruce Edge
HI Robert,

Regarding the sling console log, I tried in debug mode and got no output on the console at all. Specifically, while viewing the sling console, right click on the sling server and choose Debug. No console output at all, although I can see the debugger attach in the debug view form the threads displayed.

BTW, as the sling server is on a VM, I changed the "Specify how to install bundles on the server”
from: Install bundles directly from the filesystem
to:  Install bundles via bundle upload
As my eclipse instance doesn’t have access to the target VM’s filesystem

If I disconnect the server and start again with “Start” rather than “Debug”, I get a lot of output on the console, ending with:


[November 14, 2014 7:33:26 AM PST] ListChildrenCommand -> / : JcrResult[ success:true] (27 ms

 Then when I “add” my bundle to the server I get an error dialog with:


Failed installing bundle : Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.

Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.


and an exception in the log:


[November 14, 2014 7:36:30 AM PST] InstallJarredBundle -> /Users/bedge/git/server/content/dam/postIngest/target/classes : FAILED (45 ms)

org.apache.sling.ide.osgi.OsgiClientException: Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.

at org.apache.sling.ide.osgi.impl.HttpOsgiClient$LocalBundleInstaller.installBundle(HttpOsgiClient.java:216)

at org.apache.sling.ide.osgi.impl.HttpOsgiClient.installLocalBundle(HttpOsgiClient.java:191)

at org.apache.sling.ide.osgi.impl.TracingOsgiClient.logInstallLocalBundle(TracingOsgiClient.java:73)

at org.apache.sling.ide.osgi.impl.TracingOsgiClient.installLocalBundle(TracingOsgiClient.java:101)

at org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publishBundleModule(SlingLaunchpadBehaviour.java:347)

at org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publishModule(SlingLaunchpadBehaviour.java:219)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModule(ServerBehaviourDelegate.java:1091)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModules(ServerBehaviourDelegate.java:1183)

at org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModulePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.java:137)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)

at org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModulePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.java:54)

at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3157)

at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54

Note that this same bundle does deploy with maven.

-Bruce

From: Robert Munteanu <[hidden email]<mailto:[hidden email]>>
Reply-To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date: Friday, November 14, 2014 at 5:07 AM
To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.

Hi Bruce,

On Thu, Nov 13, 2014 at 8:57 AM, Bruce Edge
<[hidden email]<mailto:[hidden email]>> wrote:
Also, I found 2 plugins that seem to be similar,
http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
http://sling.apache.org/documentation/development/ide-tooling.html
Which to people use?

I settled on the non-adobe one as I'm not using CQ.

Well, that's the right approach. For now, the Adobe plugins add a new
project wizard and some AEM branding. The new project wizard generates
a project based on AEM libraries so it would not deploy on Sling at
all. The rest of the features come from the Sling IDE Tooling anyway.


Does anyone actually use the eclipse sling plugin to add/remove bundles to/from a sling server?

I got a doPost SlingAllMethodsServlet working, but only through the maven plugin, i.e.:
mvn org.apache.sling:maven-sling-plugin:install-file -Dsling.file=ingest-2.2.2.jar

Connecting to a sling server from the plugin's server manager works, as does the debugging. So just the deploy/undeploy seems broken.
I'm running on nonstandard ports (not 8080) for conflict reasons, is there anything that needs to change other than in the server's config?


That should work, I'm using it for day-to-day work. A couple of questions:

1. Do you have anything in the sling log that indicates an error
deploying from Eclipse?
2. If you open the Sling console ( see [1] ) do you see anything
related to installing local bundles?

Thanks,

Robert

[1]: https://sling.apache.org/documentation/development/ide-tooling.html#gathering-debug-information


I do have the port setup in the pom:
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>maven-sling-plugin</artifactId>
                 <version>2.1.0</version>
                 <configuration>
                     <slingUrl>http://localhost:8090/system/console</slingUrl>
                     <user>admin</user>
                     <password>admin</password>
                 </configuration>
             </plugin>

-Bruce

Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Bruce Edge
Here’s the full stack trace from the sling error.log triggered by “adding” a bundle to the server from inside eclipse.
This shows the original felix NPE, the eclipse console did not.

14.11.2014 14:11:21.716 *INFO* [qtp124750626-43] org.apache.sling.tooling.support.install.impl.InstallServlet Unable to install/update bundle com.nim.ct.dam.bundle.ingest
org.osgi.framework.BundleException: Could not create bundle object.
        at org.apache.felix.framework.Felix.installBundle(Felix.java:2960)
        at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:165)
        at org.apache.sling.tooling.support.install.impl.InstallServlet.installOrUpdateBundle(InstallServlet.java:242)
        at org.apache.sling.tooling.support.install.impl.InstallServlet.installBasedOnUploadedJar(InstallServlet.java:149)
        at org.apache.sling.tooling.support.install.impl.InstallServlet.doPost(InstallServlet.java:101)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:339)
        at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:300)
        at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:93)
        at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:50)
        at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31)
        at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75)
        at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80)
        at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46)
        at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31)
        at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:76)
        at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:49)
        at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:370)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
        at org.apache.felix.framework.BundleProtectionDomain.<init>(BundleProtectionDomain.java:46)
        at org.apache.felix.framework.Felix.setBundleProtectionDomain(Felix.java:877)
        at org.apache.felix.framework.BundleImpl.addRevision(BundleImpl.java:1213)
        at org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:113)
        at org.apache.felix.framework.Felix.installBundle(Felix.java:2907)
        ... 42 common frames omitted

From: Bruce Edge <[hidden email]<mailto:[hidden email]>>
Reply-To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date: Friday, November 14, 2014 at 7:47 AM
To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.

HI Robert,

Regarding the sling console log, I tried in debug mode and got no output on the console at all. Specifically, while viewing the sling console, right click on the sling server and choose Debug. No console output at all, although I can see the debugger attach in the debug view form the threads displayed.

BTW, as the sling server is on a VM, I changed the "Specify how to install bundles on the server”
from: Install bundles directly from the filesystem
to:  Install bundles via bundle upload
As my eclipse instance doesn’t have access to the target VM’s filesystem

If I disconnect the server and start again with “Start” rather than “Debug”, I get a lot of output on the console, ending with:


[November 14, 2014 7:33:26 AM PST] ListChildrenCommand -> / : JcrResult[ success:true] (27 ms

Then when I “add” my bundle to the server I get an error dialog with:


Failed installing bundle : Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.

Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.


and an exception in the log:


[November 14, 2014 7:36:30 AM PST] InstallJarredBundle -> /Users/bedge/git/server/content/dam/postIngest/target/classes : FAILED (45 ms)

org.apache.sling.ide.osgi.OsgiClientException: Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.

at org.apache.sling.ide.osgi.impl.HttpOsgiClient$LocalBundleInstaller.installBundle(HttpOsgiClient.java:216)

at org.apache.sling.ide.osgi.impl.HttpOsgiClient.installLocalBundle(HttpOsgiClient.java:191)

at org.apache.sling.ide.osgi.impl.TracingOsgiClient.logInstallLocalBundle(TracingOsgiClient.java:73)

at org.apache.sling.ide.osgi.impl.TracingOsgiClient.installLocalBundle(TracingOsgiClient.java:101)

at org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publishBundleModule(SlingLaunchpadBehaviour.java:347)

at org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publishModule(SlingLaunchpadBehaviour.java:219)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModule(ServerBehaviourDelegate.java:1091)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModules(ServerBehaviourDelegate.java:1183)

at org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModulePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.java:137)

at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)

at org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModulePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.java:54)

at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3157)

at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54

Note that this same bundle does deploy with maven.

-Bruce

From: Robert Munteanu <[hidden email]<mailto:[hidden email]><mailto:[hidden email]>>
Reply-To: "[hidden email]<mailto:[hidden email]><mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]><mailto:[hidden email]>>
Date: Friday, November 14, 2014 at 5:07 AM
To: "[hidden email]<mailto:[hidden email]><mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]><mailto:[hidden email]>>
Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.

Hi Bruce,

On Thu, Nov 13, 2014 at 8:57 AM, Bruce Edge
<[hidden email]<mailto:[hidden email]><mailto:[hidden email]>> wrote:
Also, I found 2 plugins that seem to be similar,
http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
http://sling.apache.org/documentation/development/ide-tooling.html
Which to people use?

I settled on the non-adobe one as I'm not using CQ.

Well, that's the right approach. For now, the Adobe plugins add a new
project wizard and some AEM branding. The new project wizard generates
a project based on AEM libraries so it would not deploy on Sling at
all. The rest of the features come from the Sling IDE Tooling anyway.


Does anyone actually use the eclipse sling plugin to add/remove bundles to/from a sling server?

I got a doPost SlingAllMethodsServlet working, but only through the maven plugin, i.e.:
mvn org.apache.sling:maven-sling-plugin:install-file -Dsling.file=ingest-2.2.2.jar

Connecting to a sling server from the plugin's server manager works, as does the debugging. So just the deploy/undeploy seems broken.
I'm running on nonstandard ports (not 8080) for conflict reasons, is there anything that needs to change other than in the server's config?


That should work, I'm using it for day-to-day work. A couple of questions:

1. Do you have anything in the sling log that indicates an error
deploying from Eclipse?
2. If you open the Sling console ( see [1] ) do you see anything
related to installing local bundles?

Thanks,

Robert

[1]: https://sling.apache.org/documentation/development/ide-tooling.html#gathering-debug-information


I do have the port setup in the pom:
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>maven-sling-plugin</artifactId>
                 <version>2.1.0</version>
                 <configuration>
                     <slingUrl>http://localhost:8090/system/console</slingUrl>
                     <user>admin</user>
                     <password>admin</password>
                 </configuration>
             </plugin>

-Bruce


Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Stefan Egli-2
Hi Bruce,

Which version of the 'org.apache.felix.framework' bundle are you running
with ?

Cheers,
Stefan

On 11/14/14 11:15 PM, "Bruce Edge" <[hidden email]> wrote:

>Here¹s the full stack trace from the sling error.log triggered by
>³adding² a bundle to the server from inside eclipse.
>This shows the original felix NPE, the eclipse console did not.
>
>14.11.2014 14:11:21.716 *INFO* [qtp124750626-43]
>org.apache.sling.tooling.support.install.impl.InstallServlet Unable to
>install/update bundle com.nim.ct.dam.bundle.ingest
>org.osgi.framework.BundleException: Could not create bundle object.
>        at org.apache.felix.framework.Felix.installBundle(Felix.java:2960)
>        at
>org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextIm
>pl.java:165)
>        at
>org.apache.sling.tooling.support.install.impl.InstallServlet.installOrUpda
>teBundle(InstallServlet.java:242)
>        at
>org.apache.sling.tooling.support.install.impl.InstallServlet.installBasedO
>nUploadedJar(InstallServlet.java:149)
>        at
>org.apache.sling.tooling.support.install.impl.InstallServlet.doPost(Instal
>lServlet.java:101)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>        at
>org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(Servle
>tHandler.java:339)
>        at
>org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletH
>andler.java:300)
>        at
>org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(Servle
>tPipeline.java:93)
>        at
>org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilte
>r(InvocationFilterChain.java:50)
>        at
>org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(Http
>FilterChain.java:31)
>        at
>org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLogge
>rFilter.java:75)
>        at
>org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterH
>andler.java:108)
>        at
>org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHan
>dler.java:80)
>        at
>org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilte
>r(InvocationFilterChain.java:46)
>        at
>org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(Http
>FilterChain.java:31)
>        at
>org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(Filte
>rPipeline.java:76)
>        at
>org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatche
>r.java:49)
>        at
>org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherSe
>rvlet.java:67)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>        at
>org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
>        at
>org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
>        at
>org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.ja
>va:229)
>        at
>org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.ja
>va:1086)
>        at
>org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
>        at
>org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.jav
>a:193)
>        at
>org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.jav
>a:1020)
>        at
>org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:1
>35)
>        at
>org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHa
>ndlerCollection.java:255)
>        at
>org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java
>:116)
>        at org.eclipse.jetty.server.Server.handle(Server.java:370)
>        at
>org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttp
>Connection.java:494)
>        at
>org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnec
>tion.java:982)
>        at
>org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(Abs
>tractHttpConnection.java:1043)
>        at
>org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
>        at
>org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>        at
>org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.ja
>va:82)
>        at
>org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoin
>t.java:667)
>        at
>org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint
>.java:52)
>        at
>org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.jav
>a:608)
>        at
>org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java
>:543)
>        at java.lang.Thread.run(Thread.java:745)
>Caused by: java.lang.NullPointerException: null
>        at
>org.apache.felix.framework.BundleProtectionDomain.<init>(BundleProtectionD
>omain.java:46)
>        at
>org.apache.felix.framework.Felix.setBundleProtectionDomain(Felix.java:877)
>        at
>org.apache.felix.framework.BundleImpl.addRevision(BundleImpl.java:1213)
>        at
>org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:113)
>        at org.apache.felix.framework.Felix.installBundle(Felix.java:2907)
>        ... 42 common frames omitted
>
>From: Bruce Edge
><[hidden email]<mailto:[hidden email]>>
>Reply-To: "[hidden email]<mailto:[hidden email]>"
><[hidden email]<mailto:[hidden email]>>
>Date: Friday, November 14, 2014 at 7:47 AM
>To: "[hidden email]<mailto:[hidden email]>"
><[hidden email]<mailto:[hidden email]>>
>Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.
>
>HI Robert,
>
>Regarding the sling console log, I tried in debug mode and got no output
>on the console at all. Specifically, while viewing the sling console,
>right click on the sling server and choose Debug. No console output at
>all, although I can see the debugger attach in the debug view form the
>threads displayed.
>
>BTW, as the sling server is on a VM, I changed the "Specify how to
>install bundles on the server²
>from: Install bundles directly from the filesystem
>to:  Install bundles via bundle upload
>As my eclipse instance doesn¹t have access to the target VM¹s filesystem
>
>If I disconnect the server and start again with ³Start² rather than
>³Debug², I get a lot of output on the console, ending with:
>
>
>[November 14, 2014 7:33:26 AM PST] ListChildrenCommand -> / : JcrResult[
>success:true] (27 ms
>
>Then when I ³add² my bundle to the server I get an error dialog with:
>
>
>Failed installing bundle : Unable to install/update bundle
>com.nim.ct.dam.bundle.ingest : Could not create bundle object.
>
>Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not
>create bundle object.
>
>
>and an exception in the log:
>
>
>[November 14, 2014 7:36:30 AM PST] InstallJarredBundle ->
>/Users/bedge/git/server/content/dam/postIngest/target/classes : FAILED
>(45 ms)
>
>org.apache.sling.ide.osgi.OsgiClientException: Unable to install/update
>bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.
>
>at
>org.apache.sling.ide.osgi.impl.HttpOsgiClient$LocalBundleInstaller.install
>Bundle(HttpOsgiClient.java:216)
>
>at
>org.apache.sling.ide.osgi.impl.HttpOsgiClient.installLocalBundle(HttpOsgiC
>lient.java:191)
>
>at
>org.apache.sling.ide.osgi.impl.TracingOsgiClient.logInstallLocalBundle(Tra
>cingOsgiClient.java:73)
>
>at
>org.apache.sling.ide.osgi.impl.TracingOsgiClient.installLocalBundle(Tracin
>gOsgiClient.java:101)
>
>at
>org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publish
>BundleModule(SlingLaunchpadBehaviour.java:347)
>
>at
>org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publish
>Module(SlingLaunchpadBehaviour.java:219)
>
>at
>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModule(Se
>rverBehaviourDelegate.java:1091)
>
>at
>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModules(S
>erverBehaviourDelegate.java:1183)
>
>at
>org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModu
>lePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.j
>ava:137)
>
>at
>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBe
>haviourDelegate.java:774)
>
>at
>org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithModu
>lePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.j
>ava:54)
>
>at
>org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3157)
>
>at
>org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345
>)
>
>at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54
>
>Note that this same bundle does deploy with maven.
>
>-Bruce
>
>From: Robert Munteanu
><[hidden email]<mailto:[hidden email]><mailto:[hidden email]>>
>Reply-To:
>"[hidden email]<mailto:[hidden email]><mailto:users@sling.
>apache.org>"
><[hidden email]<mailto:[hidden email]><mailto:users@sling.
>apache.org>>
>Date: Friday, November 14, 2014 at 5:07 AM
>To:
>"[hidden email]<mailto:[hidden email]><mailto:users@sling.
>apache.org>"
><[hidden email]<mailto:[hidden email]><mailto:users@sling.
>apache.org>>
>Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.
>
>Hi Bruce,
>
>On Thu, Nov 13, 2014 at 8:57 AM, Bruce Edge
><[hidden email]<mailto:[hidden email]><mailt
>o:[hidden email]>> wrote:
>Also, I found 2 plugins that seem to be similar,
>http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
>http://sling.apache.org/documentation/development/ide-tooling.html
>Which to people use?
>
>I settled on the non-adobe one as I'm not using CQ.
>
>Well, that's the right approach. For now, the Adobe plugins add a new
>project wizard and some AEM branding. The new project wizard generates
>a project based on AEM libraries so it would not deploy on Sling at
>all. The rest of the features come from the Sling IDE Tooling anyway.
>
>
>Does anyone actually use the eclipse sling plugin to add/remove bundles
>to/from a sling server?
>
>I got a doPost SlingAllMethodsServlet working, but only through the maven
>plugin, i.e.:
>mvn org.apache.sling:maven-sling-plugin:install-file
>-Dsling.file=ingest-2.2.2.jar
>
>Connecting to a sling server from the plugin's server manager works, as
>does the debugging. So just the deploy/undeploy seems broken.
>I'm running on nonstandard ports (not 8080) for conflict reasons, is
>there anything that needs to change other than in the server's config?
>
>
>That should work, I'm using it for day-to-day work. A couple of questions:
>
>1. Do you have anything in the sling log that indicates an error
>deploying from Eclipse?
>2. If you open the Sling console ( see [1] ) do you see anything
>related to installing local bundles?
>
>Thanks,
>
>Robert
>
>[1]:
>https://sling.apache.org/documentation/development/ide-tooling.html#gather
>ing-debug-information
>
>
>I do have the port setup in the pom:
>             <plugin>
>                 <groupId>org.apache.sling</groupId>
>                 <artifactId>maven-sling-plugin</artifactId>
>                 <version>2.1.0</version>
>                 <configuration>
>                  
><slingUrl>http://localhost:8090/system/console</slingUrl>
>                     <user>admin</user>
>                     <password>admin</password>
>                 </configuration>
>             </plugin>
>
>-Bruce
>
>


Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Bruce Edge
inline

From:  Stefan Egli <[hidden email]>
Reply-To:  "[hidden email]" <[hidden email]>
Date:  Monday, November 17, 2014 at 1:03 AM
To:  "[hidden email]" <[hidden email]>
Subject:  Re: State of sling eclipse plugins for IDE deploy/undeploy.


>Hi Bruce,
>
>Which version of the 'org.apache.felix.framework' bundle are you running
>with ?
>
>

I’m using org.apache.felix.framework 4.4.1.

This is the version I get when running the current (or a few days old)
sling trunk launchpad standalone jar.

-Bruce


>
>Cheers,
>Stefan
>
>On 11/14/14 11:15 PM, "Bruce Edge" <[hidden email]> wrote:
>
>>Here¹s the full stack trace from the sling error.log triggered by
>>³adding² a bundle to the server from inside eclipse.
>>This shows the original felix NPE, the eclipse console did not.
>>
>>14.11.2014 14:11:21.716 *INFO* [qtp124750626-43]
>>org.apache.sling.tooling.support.install.impl.InstallServlet Unable to
>>install/update bundle com.nim.ct.dam.bundle.ingest
>>org.osgi.framework.BundleException: Could not create bundle object.
>>        at
>>org.apache.felix.framework.Felix.installBundle(Felix.java:2960)
>>        at
>>org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextI
>>m
>>pl.java:165)
>>        at
>>org.apache.sling.tooling.support.install.impl.InstallServlet.installOrUpd
>>a
>>teBundle(InstallServlet.java:242)
>>        at
>>org.apache.sling.tooling.support.install.impl.InstallServlet.installBased
>>O
>>nUploadedJar(InstallServlet.java:149)
>>        at
>>org.apache.sling.tooling.support.install.impl.InstallServlet.doPost(Insta
>>l
>>lServlet.java:101)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>>        at
>>org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(Servl
>>e
>>tHandler.java:339)
>>        at
>>org.apache.felix.http.base.internal.handler.ServletHandler.handle(Servlet
>>H
>>andler.java:300)
>>        at
>>org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(Servl
>>e
>>tPipeline.java:93)
>>        at
>>org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilt
>>e
>>r(InvocationFilterChain.java:50)
>>        at
>>org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(Htt
>>p
>>FilterChain.java:31)
>>        at
>>org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLogg
>>e
>>rFilter.java:75)
>>        at
>>org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(Filter
>>H
>>andler.java:108)
>>        at
>>org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHa
>>n
>>dler.java:80)
>>        at
>>org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilt
>>e
>>r(InvocationFilterChain.java:46)
>>        at
>>org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(Htt
>>p
>>FilterChain.java:31)
>>        at
>>org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(Filt
>>e
>>rPipeline.java:76)
>>        at
>>org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatch
>>e
>>r.java:49)
>>        at
>>org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherS
>>e
>>rvlet.java:67)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>>        at
>>org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
>>        at
>>org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501
>>)
>>        at
>>org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.j
>>a
>>va:229)
>>        at
>>org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.j
>>a
>>va:1086)
>>        at
>>org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
>>        at
>>org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.ja
>>v
>>a:193)
>>        at
>>org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.ja
>>v
>>a:1020)
>>        at
>>org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:
>>1
>>35)
>>        at
>>org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextH
>>a
>>ndlerCollection.java:255)
>>        at
>>org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.jav
>>a
>>:116)
>>        at org.eclipse.jetty.server.Server.handle(Server.java:370)
>>        at
>>org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHtt
>>p
>>Connection.java:494)
>>        at
>>org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConne
>>c
>>tion.java:982)
>>        at
>>org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(Ab
>>s
>>tractHttpConnection.java:1043)
>>        at
>>org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
>>        at
>>org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>>        at
>>org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.j
>>a
>>va:82)
>>        at
>>org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoi
>>n
>>t.java:667)
>>        at
>>org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoin
>>t
>>.java:52)
>>        at
>>org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.ja
>>v
>>a:608)
>>        at
>>org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.jav
>>a
>>:543)
>>        at java.lang.Thread.run(Thread.java:745)
>>Caused by: java.lang.NullPointerException: null
>>        at
>>org.apache.felix.framework.BundleProtectionDomain.<init>(BundleProtection
>>D
>>omain.java:46)
>>        at
>>org.apache.felix.framework.Felix.setBundleProtectionDomain(Felix.java:877
>>)
>>        at
>>org.apache.felix.framework.BundleImpl.addRevision(BundleImpl.java:1213)
>>        at
>>org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:113)
>>        at
>>org.apache.felix.framework.Felix.installBundle(Felix.java:2907)
>>        ... 42 common frames omitted
>>
>>From: Bruce Edge
>><[hidden email]<mailto:[hidden email]>>
>>Reply-To: "[hidden email]<mailto:[hidden email]>"
>><[hidden email]<mailto:[hidden email]>>
>>Date: Friday, November 14, 2014 at 7:47 AM
>>To: "[hidden email]<mailto:[hidden email]>"
>><[hidden email]<mailto:[hidden email]>>
>>Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.
>>
>>HI Robert,
>>
>>Regarding the sling console log, I tried in debug mode and got no output
>>on the console at all. Specifically, while viewing the sling console,
>>right click on the sling server and choose Debug. No console output at
>>all, although I can see the debugger attach in the debug view form the
>>threads displayed.
>>
>>BTW, as the sling server is on a VM, I changed the "Specify how to
>>install bundles on the server²
>>from: Install bundles directly from the filesystem
>>to:  Install bundles via bundle upload
>>As my eclipse instance doesn¹t have access to the target VM¹s filesystem
>>
>>If I disconnect the server and start again with ³Start² rather than
>>³Debug², I get a lot of output on the console, ending with:
>>
>>
>>[November 14, 2014 7:33:26 AM PST] ListChildrenCommand -> / : JcrResult[
>>success:true] (27 ms
>>
>>Then when I ³add² my bundle to the server I get an error dialog with:
>>
>>
>>Failed installing bundle : Unable to install/update bundle
>>com.nim.ct.dam.bundle.ingest : Could not create bundle object.
>>
>>Unable to install/update bundle com.nim.ct.dam.bundle.ingest : Could not
>>create bundle object.
>>
>>
>>and an exception in the log:
>>
>>
>>[November 14, 2014 7:36:30 AM PST] InstallJarredBundle ->
>>/Users/bedge/git/server/content/dam/postIngest/target/classes : FAILED
>>(45 ms)
>>
>>org.apache.sling.ide.osgi.OsgiClientException: Unable to install/update
>>bundle com.nim.ct.dam.bundle.ingest : Could not create bundle object.
>>
>>at
>>org.apache.sling.ide.osgi.impl.HttpOsgiClient$LocalBundleInstaller.instal
>>l
>>Bundle(HttpOsgiClient.java:216)
>>
>>at
>>org.apache.sling.ide.osgi.impl.HttpOsgiClient.installLocalBundle(HttpOsgi
>>C
>>lient.java:191)
>>
>>at
>>org.apache.sling.ide.osgi.impl.TracingOsgiClient.logInstallLocalBundle(Tr
>>a
>>cingOsgiClient.java:73)
>>
>>at
>>org.apache.sling.ide.osgi.impl.TracingOsgiClient.installLocalBundle(Traci
>>n
>>gOsgiClient.java:101)
>>
>>at
>>org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publis
>>h
>>BundleModule(SlingLaunchpadBehaviour.java:347)
>>
>>at
>>org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.publis
>>h
>>Module(SlingLaunchpadBehaviour.java:219)
>>
>>at
>>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModule(S
>>e
>>rverBehaviourDelegate.java:1091)
>>
>>at
>>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModules(
>>S
>>erverBehaviourDelegate.java:1183)
>>
>>at
>>org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithMod
>>u
>>lePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.
>>j
>>ava:137)
>>
>>at
>>org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerB
>>e
>>haviourDelegate.java:774)
>>
>>at
>>org.apache.sling.ide.eclipse.core.internal.ServerBehaviourDelegateWithMod
>>u
>>lePublishSupport.publish(ServerBehaviourDelegateWithModulePublishSupport.
>>j
>>ava:54)
>>
>>at
>>org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3157)
>>
>>at
>>org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:34
>>5
>>)
>>
>>at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54
>>
>>Note that this same bundle does deploy with maven.
>>
>>-Bruce
>>
>>From: Robert Munteanu
>><[hidden email]<mailto:[hidden email]><mailto:[hidden email]>
>>>
>>Reply-To:
>>"[hidden email]<mailto:[hidden email]><mailto:users@sling
>>.
>>apache.org>"
>><[hidden email]<mailto:[hidden email]><mailto:users@sling
>>.
>>apache.org>>
>>Date: Friday, November 14, 2014 at 5:07 AM
>>To:
>>"[hidden email]<mailto:[hidden email]><mailto:users@sling
>>.
>>apache.org>"
>><[hidden email]<mailto:[hidden email]><mailto:users@sling
>>.
>>apache.org>>
>>Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.
>>
>>Hi Bruce,
>>
>>On Thu, Nov 13, 2014 at 8:57 AM, Bruce Edge
>><[hidden email]<mailto:[hidden email]><mail
>>t
>>o:[hidden email]>> wrote:
>>Also, I found 2 plugins that seem to be similar,
>>http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
>>http://sling.apache.org/documentation/development/ide-tooling.html
>>Which to people use?
>>
>>I settled on the non-adobe one as I'm not using CQ.
>>
>>Well, that's the right approach. For now, the Adobe plugins add a new
>>project wizard and some AEM branding. The new project wizard generates
>>a project based on AEM libraries so it would not deploy on Sling at
>>all. The rest of the features come from the Sling IDE Tooling anyway.
>>
>>
>>Does anyone actually use the eclipse sling plugin to add/remove bundles
>>to/from a sling server?
>>
>>I got a doPost SlingAllMethodsServlet working, but only through the maven
>>plugin, i.e.:
>>mvn org.apache.sling:maven-sling-plugin:install-file
>>-Dsling.file=ingest-2.2.2.jar
>>
>>Connecting to a sling server from the plugin's server manager works, as
>>does the debugging. So just the deploy/undeploy seems broken.
>>I'm running on nonstandard ports (not 8080) for conflict reasons, is
>>there anything that needs to change other than in the server's config?
>>
>>
>>That should work, I'm using it for day-to-day work. A couple of
>>questions:
>>
>>1. Do you have anything in the sling log that indicates an error
>>deploying from Eclipse?
>>2. If you open the Sling console ( see [1] ) do you see anything
>>related to installing local bundles?
>>
>>Thanks,
>>
>>Robert
>>
>>[1]:
>>https://sling.apache.org/documentation/development/ide-tooling.html#gathe
>>r
>>ing-debug-information
>>
>>
>>I do have the port setup in the pom:
>>             <plugin>
>>                 <groupId>org.apache.sling</groupId>
>>                 <artifactId>maven-sling-plugin</artifactId>
>>                 <version>2.1.0</version>
>>                 <configuration>
>>                
>><slingUrl>http://localhost:8090/system/console</slingUrl>
>>                     <user>admin</user>
>>                     <password>admin</password>
>>                 </configuration>
>>             </plugin>
>>
>>-Bruce
>>
>>

Reply | Threaded
Open this post in threaded view
|

Injecting OSGI services using sling models

Hass Joseph Khafaji
In reply to this post by Bruce Edge
Hello,

I am trying to inject OSGI service defined using scr annotation into a sling model class using the @inject annotation.

What we seem to be getting is that the ModelAdapterFactory is unable to inject the service into the corresponding field as if it was an incompatible type. We not doing anything fancy here, it's just a simple service injection.

Did anyone faced a similar issue in the past? Do we have to use custom injectors for this?

Note: tried to use the @inject @source with an osgi-service but getting the same result.

Cheers.
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Sarwar Bhuiyan
The model is not an OSGi service/component right?

I'm not sure of why you need a reference to an osgi service in the model
but you can probably use a setter by yourself but I still think you can
just have another service which does the action on the model instead of the
model calling the service.

On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
wrote:

> Hello,
>
> I am trying to inject OSGI service defined using scr annotation into a
> sling model class using the @inject annotation.
>
> What we seem to be getting is that the ModelAdapterFactory is unable to
> inject the service into the corresponding field as if it was an
> incompatible type. We not doing anything fancy here, it's just a simple
> service injection.
>
> Did anyone faced a similar issue in the past? Do we have to use custom
> injectors for this?
>
> Note: tried to use the @inject @source with an osgi-service but getting
> the same result.
>
> Cheers.
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Hass Joseph Khafaji
The model is simply a sling model class, not an osgi service at all.

The model is being looked up via slightly, thus it has to be fully populated when that happen which require that the model invoke a service to obtain data from.

Sling model documentation says that you can inject osgi services into sling models but that is not seem to be working.

Sent from my iPhone

> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]> wrote:
>
> The model is not an OSGi service/component right?
>
> I'm not sure of why you need a reference to an osgi service in the model
> but you can probably use a setter by yourself but I still think you can
> just have another service which does the action on the model instead of the
> model calling the service.
>
> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
> wrote:
>
>> Hello,
>>
>> I am trying to inject OSGI service defined using scr annotation into a
>> sling model class using the @inject annotation.
>>
>> What we seem to be getting is that the ModelAdapterFactory is unable to
>> inject the service into the corresponding field as if it was an
>> incompatible type. We not doing anything fancy here, it's just a simple
>> service injection.
>>
>> Did anyone faced a similar issue in the past? Do we have to use custom
>> injectors for this?
>>
>> Note: tried to use the @inject @source with an osgi-service but getting
>> the same result.
>>
>> Cheers.
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Sarwar Bhuiyan
Could you paste that bit of code please?

On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
wrote:

> The model is simply a sling model class, not an osgi service at all.
>
> The model is being looked up via slightly, thus it has to be fully
> populated when that happen which require that the model invoke a service to
> obtain data from.
>
> Sling model documentation says that you can inject osgi services into
> sling models but that is not seem to be working.
>
> Sent from my iPhone
>
> > On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
> <javascript:;>> wrote:
> >
> > The model is not an OSGi service/component right?
> >
> > I'm not sure of why you need a reference to an osgi service in the model
> > but you can probably use a setter by yourself but I still think you can
> > just have another service which does the action on the model instead of
> the
> > model calling the service.
> >
> > On Wednesday, November 19, 2014, Hass Joseph Khafaji <
> [hidden email] <javascript:;>>
> > wrote:
> >
> >> Hello,
> >>
> >> I am trying to inject OSGI service defined using scr annotation into a
> >> sling model class using the @inject annotation.
> >>
> >> What we seem to be getting is that the ModelAdapterFactory is unable to
> >> inject the service into the corresponding field as if it was an
> >> incompatible type. We not doing anything fancy here, it's just a simple
> >> service injection.
> >>
> >> Did anyone faced a similar issue in the past? Do we have to use custom
> >> injectors for this?
> >>
> >> Note: tried to use the @inject @source with an osgi-service but getting
> >> the same result.
> >>
> >> Cheers.
>
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Hass Joseph Khafaji
Let's assume that Bundle A defines a service interface and export the
package that contains it to OSGi:

Public interface ServiceInterface
{
      .....
}

Bundle B, provides an OSGi component/service that implement the
service interface

@Component(immediate = true, metatype = true)
@Service(value = {ServiceInterface.class, ManagedService.class})
@org.apache.felix.scr.annotations.Properties({
        @Property(name = Constants.SERVICE_PID, value =
"com.example.MyService"),
        @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
        @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"),
})
public class MyService implements ServiceInterface
{
     ...
}

Bundle C, contains Sling model classes that needs to use the above
service, we inject it using @Inject or @Inject @Source("osgi-service")
as per Sling Model documentation

@Model(adaptables = {Resource.class})
public class MyModel
{
    @Inject
    private ServiceInterface serviceInterface;
    ...
}

The problem is that the service never get injected into the model as
it should be, the Exception we get is thrown by the
ModelAdapterFactory saying that it's unable to inject MyService into
ServiceInterface as if they were an incompatible types but they are
not.

On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
<[hidden email]> wrote:

> Could you paste that bit of code please?
>
> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
> wrote:
>
>> The model is simply a sling model class, not an osgi service at all.
>>
>> The model is being looked up via slightly, thus it has to be fully
>> populated when that happen which require that the model invoke a service to
>> obtain data from.
>>
>> Sling model documentation says that you can inject osgi services into
>> sling models but that is not seem to be working.
>>
>> Sent from my iPhone
>>
>> > On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
>> <javascript:;>> wrote:
>> >
>> > The model is not an OSGi service/component right?
>> >
>> > I'm not sure of why you need a reference to an osgi service in the model
>> > but you can probably use a setter by yourself but I still think you can
>> > just have another service which does the action on the model instead of
>> the
>> > model calling the service.
>> >
>> > On Wednesday, November 19, 2014, Hass Joseph Khafaji <
>> [hidden email] <javascript:;>>
>> > wrote:
>> >
>> >> Hello,
>> >>
>> >> I am trying to inject OSGI service defined using scr annotation into a
>> >> sling model class using the @inject annotation.
>> >>
>> >> What we seem to be getting is that the ModelAdapterFactory is unable to
>> >> inject the service into the corresponding field as if it was an
>> >> incompatible type. We not doing anything fancy here, it's just a simple
>> >> service injection.
>> >>
>> >> Did anyone faced a similar issue in the past? Do we have to use custom
>> >> injectors for this?
>> >>
>> >> Note: tried to use the @inject @source with an osgi-service but getting
>> >> the same result.
>> >>
>> >> Cheers.
>>
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Felix Meschberger-3
Hi

Could it be that you announce the component to be „ManagedService“ but the class does not implement it and thus the component cannot be instantiated at all ?

Regards
Felix

> Am 19.11.2014 um 12:32 schrieb Hasanein Khafaji <[hidden email]>:
>
> Let's assume that Bundle A defines a service interface and export the
> package that contains it to OSGi:
>
> Public interface ServiceInterface
> {
>      .....
> }
>
> Bundle B, provides an OSGi component/service that implement the
> service interface
>
> @Component(immediate = true, metatype = true)
> @Service(value = {ServiceInterface.class, ManagedService.class})
> @org.apache.felix.scr.annotations.Properties({
>        @Property(name = Constants.SERVICE_PID, value =
> "com.example.MyService"),
>        @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
>        @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"),
> })
> public class MyService implements ServiceInterface
> {
>     ...
> }
>
> Bundle C, contains Sling model classes that needs to use the above
> service, we inject it using @Inject or @Inject @Source("osgi-service")
> as per Sling Model documentation
>
> @Model(adaptables = {Resource.class})
> public class MyModel
> {
>    @Inject
>    private ServiceInterface serviceInterface;
>    ...
> }
>
> The problem is that the service never get injected into the model as
> it should be, the Exception we get is thrown by the
> ModelAdapterFactory saying that it's unable to inject MyService into
> ServiceInterface as if they were an incompatible types but they are
> not.
>
> On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
> <[hidden email]> wrote:
>> Could you paste that bit of code please?
>>
>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
>> wrote:
>>
>>> The model is simply a sling model class, not an osgi service at all.
>>>
>>> The model is being looked up via slightly, thus it has to be fully
>>> populated when that happen which require that the model invoke a service to
>>> obtain data from.
>>>
>>> Sling model documentation says that you can inject osgi services into
>>> sling models but that is not seem to be working.
>>>
>>> Sent from my iPhone
>>>
>>>> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
>>> <javascript:;>> wrote:
>>>>
>>>> The model is not an OSGi service/component right?
>>>>
>>>> I'm not sure of why you need a reference to an osgi service in the model
>>>> but you can probably use a setter by yourself but I still think you can
>>>> just have another service which does the action on the model instead of
>>> the
>>>> model calling the service.
>>>>
>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
>>> [hidden email] <javascript:;>>
>>>> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I am trying to inject OSGI service defined using scr annotation into a
>>>>> sling model class using the @inject annotation.
>>>>>
>>>>> What we seem to be getting is that the ModelAdapterFactory is unable to
>>>>> inject the service into the corresponding field as if it was an
>>>>> incompatible type. We not doing anything fancy here, it's just a simple
>>>>> service injection.
>>>>>
>>>>> Did anyone faced a similar issue in the past? Do we have to use custom
>>>>> injectors for this?
>>>>>
>>>>> Note: tried to use the @inject @source with an osgi-service but getting
>>>>> the same result.
>>>>>
>>>>> Cheers.
>>>

Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Hass Joseph Khafaji
Sorry, I forgot to add that. It implements ManagedService.

Do you think it has anything to do with the fact that the interface
and the implementation are in different bundles, thus get loaded by a
different class loader? and end up being incompatible when reflection
is used to set one type to the other?

I've tried o keep the interface and the implementation in a single
bundle and it seems to be working now. But I am deviating from the
project convention we have in place to keep interfaces in separate
bundle than it's implementation.

On Wed, Nov 19, 2014 at 11:43 AM, Felix Meschberger <[hidden email]> wrote:

> Hi
>
> Could it be that you announce the component to be „ManagedService“ but the class does not implement it and thus the component cannot be instantiated at all ?
>
> Regards
> Felix
>
>> Am 19.11.2014 um 12:32 schrieb Hasanein Khafaji <[hidden email]>:
>>
>> Let's assume that Bundle A defines a service interface and export the
>> package that contains it to OSGi:
>>
>> Public interface ServiceInterface
>> {
>>      .....
>> }
>>
>> Bundle B, provides an OSGi component/service that implement the
>> service interface
>>
>> @Component(immediate = true, metatype = true)
>> @Service(value = {ServiceInterface.class, ManagedService.class})
>> @org.apache.felix.scr.annotations.Properties({
>>        @Property(name = Constants.SERVICE_PID, value =
>> "com.example.MyService"),
>>        @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
>>        @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"),
>> })
>> public class MyService implements ServiceInterface
>> {
>>     ...
>> }
>>
>> Bundle C, contains Sling model classes that needs to use the above
>> service, we inject it using @Inject or @Inject @Source("osgi-service")
>> as per Sling Model documentation
>>
>> @Model(adaptables = {Resource.class})
>> public class MyModel
>> {
>>    @Inject
>>    private ServiceInterface serviceInterface;
>>    ...
>> }
>>
>> The problem is that the service never get injected into the model as
>> it should be, the Exception we get is thrown by the
>> ModelAdapterFactory saying that it's unable to inject MyService into
>> ServiceInterface as if they were an incompatible types but they are
>> not.
>>
>> On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
>> <[hidden email]> wrote:
>>> Could you paste that bit of code please?
>>>
>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
>>> wrote:
>>>
>>>> The model is simply a sling model class, not an osgi service at all.
>>>>
>>>> The model is being looked up via slightly, thus it has to be fully
>>>> populated when that happen which require that the model invoke a service to
>>>> obtain data from.
>>>>
>>>> Sling model documentation says that you can inject osgi services into
>>>> sling models but that is not seem to be working.
>>>>
>>>> Sent from my iPhone
>>>>
>>>>> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
>>>> <javascript:;>> wrote:
>>>>>
>>>>> The model is not an OSGi service/component right?
>>>>>
>>>>> I'm not sure of why you need a reference to an osgi service in the model
>>>>> but you can probably use a setter by yourself but I still think you can
>>>>> just have another service which does the action on the model instead of
>>>> the
>>>>> model calling the service.
>>>>>
>>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
>>>> [hidden email] <javascript:;>>
>>>>> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am trying to inject OSGI service defined using scr annotation into a
>>>>>> sling model class using the @inject annotation.
>>>>>>
>>>>>> What we seem to be getting is that the ModelAdapterFactory is unable to
>>>>>> inject the service into the corresponding field as if it was an
>>>>>> incompatible type. We not doing anything fancy here, it's just a simple
>>>>>> service injection.
>>>>>>
>>>>>> Did anyone faced a similar issue in the past? Do we have to use custom
>>>>>> injectors for this?
>>>>>>
>>>>>> Note: tried to use the @inject @source with an osgi-service but getting
>>>>>> the same result.
>>>>>>
>>>>>> Cheers.
>>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Felix Meschberger-3
Hi

> Am 19.11.2014 um 12:54 schrieb Hasanein Khafaji <[hidden email]>:
>
> Sorry, I forgot to add that. It implements ManagedService.

I see. On the other hand you service does not need to implement ManagedService unless you do something very special and uncommon since a component can always get its own configuration in the @Activate method.

>
> Do you think it has anything to do with the fact that the interface
> and the implementation are in different bundles, thus get loaded by a
> different class loader? and end up being incompatible when reflection
> is used to set one type to the other?

No, unless you have two exports of the same interface/package. If your model binds the package to one export and your service implementation to another export, this may cause the incompatibility.

One situation where this could happen is if the service implementation bundle inadvertently exports the API a second time.

Regards
Felix

>
> I've tried o keep the interface and the implementation in a single
> bundle and it seems to be working now. But I am deviating from the
> project convention we have in place to keep interfaces in separate
> bundle than it's implementation.
>
> On Wed, Nov 19, 2014 at 11:43 AM, Felix Meschberger <[hidden email]> wrote:
>> Hi
>>
>> Could it be that you announce the component to be „ManagedService“ but the class does not implement it and thus the component cannot be instantiated at all ?
>>
>> Regards
>> Felix
>>
>>> Am 19.11.2014 um 12:32 schrieb Hasanein Khafaji <[hidden email]>:
>>>
>>> Let's assume that Bundle A defines a service interface and export the
>>> package that contains it to OSGi:
>>>
>>> Public interface ServiceInterface
>>> {
>>>     .....
>>> }
>>>
>>> Bundle B, provides an OSGi component/service that implement the
>>> service interface
>>>
>>> @Component(immediate = true, metatype = true)
>>> @Service(value = {ServiceInterface.class, ManagedService.class})
>>> @org.apache.felix.scr.annotations.Properties({
>>>       @Property(name = Constants.SERVICE_PID, value =
>>> "com.example.MyService"),
>>>       @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
>>>       @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"),
>>> })
>>> public class MyService implements ServiceInterface
>>> {
>>>    ...
>>> }
>>>
>>> Bundle C, contains Sling model classes that needs to use the above
>>> service, we inject it using @Inject or @Inject @Source("osgi-service")
>>> as per Sling Model documentation
>>>
>>> @Model(adaptables = {Resource.class})
>>> public class MyModel
>>> {
>>>   @Inject
>>>   private ServiceInterface serviceInterface;
>>>   ...
>>> }
>>>
>>> The problem is that the service never get injected into the model as
>>> it should be, the Exception we get is thrown by the
>>> ModelAdapterFactory saying that it's unable to inject MyService into
>>> ServiceInterface as if they were an incompatible types but they are
>>> not.
>>>
>>> On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
>>> <[hidden email]> wrote:
>>>> Could you paste that bit of code please?
>>>>
>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
>>>> wrote:
>>>>
>>>>> The model is simply a sling model class, not an osgi service at all.
>>>>>
>>>>> The model is being looked up via slightly, thus it has to be fully
>>>>> populated when that happen which require that the model invoke a service to
>>>>> obtain data from.
>>>>>
>>>>> Sling model documentation says that you can inject osgi services into
>>>>> sling models but that is not seem to be working.
>>>>>
>>>>> Sent from my iPhone
>>>>>
>>>>>> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
>>>>> <javascript:;>> wrote:
>>>>>>
>>>>>> The model is not an OSGi service/component right?
>>>>>>
>>>>>> I'm not sure of why you need a reference to an osgi service in the model
>>>>>> but you can probably use a setter by yourself but I still think you can
>>>>>> just have another service which does the action on the model instead of
>>>>> the
>>>>>> model calling the service.
>>>>>>
>>>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
>>>>> [hidden email] <javascript:;>>
>>>>>> wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am trying to inject OSGI service defined using scr annotation into a
>>>>>>> sling model class using the @inject annotation.
>>>>>>>
>>>>>>> What we seem to be getting is that the ModelAdapterFactory is unable to
>>>>>>> inject the service into the corresponding field as if it was an
>>>>>>> incompatible type. We not doing anything fancy here, it's just a simple
>>>>>>> service injection.
>>>>>>>
>>>>>>> Did anyone faced a similar issue in the past? Do we have to use custom
>>>>>>> injectors for this?
>>>>>>>
>>>>>>> Note: tried to use the @inject @source with an osgi-service but getting
>>>>>>> the same result.
>>>>>>>
>>>>>>> Cheers.
>>>>>
>>

Reply | Threaded
Open this post in threaded view
|

RE: Injecting OSGI services using sling models

Jason Bailey
In reply to this post by Hass Joseph Khafaji
That's an usual problem you're having. You should be able to see the service you've defined in the OSGi panel before executing the request that creates the model.

-Jason
________________________________________
From: Hasanein Khafaji <[hidden email]>
Sent: Wednesday, November 19, 2014 6:54 AM
To: [hidden email]
Subject: Re: Injecting OSGI services using sling models

Sorry, I forgot to add that. It implements ManagedService.

Do you think it has anything to do with the fact that the interface
and the implementation are in different bundles, thus get loaded by a
different class loader? and end up being incompatible when reflection
is used to set one type to the other?

I've tried o keep the interface and the implementation in a single
bundle and it seems to be working now. But I am deviating from the
project convention we have in place to keep interfaces in separate
bundle than it's implementation.

On Wed, Nov 19, 2014 at 11:43 AM, Felix Meschberger <[hidden email]> wrote:

> Hi
>
> Could it be that you announce the component to be „ManagedService“ but the class does not implement it and thus the component cannot be instantiated at all ?
>
> Regards
> Felix
>
>> Am 19.11.2014 um 12:32 schrieb Hasanein Khafaji <[hidden email]>:
>>
>> Let's assume that Bundle A defines a service interface and export the
>> package that contains it to OSGi:
>>
>> Public interface ServiceInterface
>> {
>>      .....
>> }
>>
>> Bundle B, provides an OSGi component/service that implement the
>> service interface
>>
>> @Component(immediate = true, metatype = true)
>> @Service(value = {ServiceInterface.class, ManagedService.class})
>> @org.apache.felix.scr.annotations.Properties({
>>        @Property(name = Constants.SERVICE_PID, value =
>> "com.example.MyService"),
>>        @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
>>        @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"),
>> })
>> public class MyService implements ServiceInterface
>> {
>>     ...
>> }
>>
>> Bundle C, contains Sling model classes that needs to use the above
>> service, we inject it using @Inject or @Inject @Source("osgi-service")
>> as per Sling Model documentation
>>
>> @Model(adaptables = {Resource.class})
>> public class MyModel
>> {
>>    @Inject
>>    private ServiceInterface serviceInterface;
>>    ...
>> }
>>
>> The problem is that the service never get injected into the model as
>> it should be, the Exception we get is thrown by the
>> ModelAdapterFactory saying that it's unable to inject MyService into
>> ServiceInterface as if they were an incompatible types but they are
>> not.
>>
>> On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
>> <[hidden email]> wrote:
>>> Could you paste that bit of code please?
>>>
>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <[hidden email]>
>>> wrote:
>>>
>>>> The model is simply a sling model class, not an osgi service at all.
>>>>
>>>> The model is being looked up via slightly, thus it has to be fully
>>>> populated when that happen which require that the model invoke a service to
>>>> obtain data from.
>>>>
>>>> Sling model documentation says that you can inject osgi services into
>>>> sling models but that is not seem to be working.
>>>>
>>>> Sent from my iPhone
>>>>
>>>>> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
>>>> <javascript:;>> wrote:
>>>>>
>>>>> The model is not an OSGi service/component right?
>>>>>
>>>>> I'm not sure of why you need a reference to an osgi service in the model
>>>>> but you can probably use a setter by yourself but I still think you can
>>>>> just have another service which does the action on the model instead of
>>>> the
>>>>> model calling the service.
>>>>>
>>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
>>>> [hidden email] <javascript:;>>
>>>>> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am trying to inject OSGI service defined using scr annotation into a
>>>>>> sling model class using the @inject annotation.
>>>>>>
>>>>>> What we seem to be getting is that the ModelAdapterFactory is unable to
>>>>>> inject the service into the corresponding field as if it was an
>>>>>> incompatible type. We not doing anything fancy here, it's just a simple
>>>>>> service injection.
>>>>>>
>>>>>> Did anyone faced a similar issue in the past? Do we have to use custom
>>>>>> injectors for this?
>>>>>>
>>>>>> Note: tried to use the @inject @source with an osgi-service but getting
>>>>>> the same result.
>>>>>>
>>>>>> Cheers.
>>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Injecting OSGI services using sling models

Hass Joseph Khafaji
From OSGi point of view, the service is active and the component is marked
as "satisfied". An instance of the component is being obtained from OSGi
but it only fails when the ModelAdapterFactory tries to inject this back
into the model class.

Here is the method from the ModelAdapterFactory where the Exception is
thrown from:


>    1. private boolean setField(Field field, Object createdObject, Object
>    value) {
>    2. if (value != null) {
>    3. if (!isAcceptableType(field.getClass(), value) && value instanceof
>    Adaptable) {
>    4. value = ((Adaptable) value).adaptTo(field.getClass());
>    5. if (value == null) {
>    6. return false;
>    7. }
>    8. }
>    9. boolean accessible = field.isAccessible();
>    10. try {
>    11. if (!accessible) {
>    12. field.setAccessible(true);
>    13. }
>    14. field.set(createdObject, value);
>    15. return true;
>    16. } catch (Exception e) {
>    17. log.error("unable to inject field", e);
>    18. return false;
>    19. } finally {
>    20. if (!accessible) {
>    21. field.setAccessible(false);
>    22. }
>    23. }
>    24. } else {
>    25. return false;
>    26. }
>    27. }
>
>



On Wed, Nov 19, 2014 at 4:26 PM, Jason Bailey <[hidden email]> wrote:

> That's an usual problem you're having. You should be able to see the
> service you've defined in the OSGi panel before executing the request that
> creates the model.
>
> -Jason
> ________________________________________
> From: Hasanein Khafaji <[hidden email]>
> Sent: Wednesday, November 19, 2014 6:54 AM
> To: [hidden email]
> Subject: Re: Injecting OSGI services using sling models
>
> Sorry, I forgot to add that. It implements ManagedService.
>
> Do you think it has anything to do with the fact that the interface
> and the implementation are in different bundles, thus get loaded by a
> different class loader? and end up being incompatible when reflection
> is used to set one type to the other?
>
> I've tried o keep the interface and the implementation in a single
> bundle and it seems to be working now. But I am deviating from the
> project convention we have in place to keep interfaces in separate
> bundle than it's implementation.
>
> On Wed, Nov 19, 2014 at 11:43 AM, Felix Meschberger <[hidden email]>
> wrote:
> > Hi
> >
> > Could it be that you announce the component to be „ManagedService“ but
> the class does not implement it and thus the component cannot be
> instantiated at all ?
> >
> > Regards
> > Felix
> >
> >> Am 19.11.2014 um 12:32 schrieb Hasanein Khafaji <[hidden email]
> >:
> >>
> >> Let's assume that Bundle A defines a service interface and export the
> >> package that contains it to OSGi:
> >>
> >> Public interface ServiceInterface
> >> {
> >>      .....
> >> }
> >>
> >> Bundle B, provides an OSGi component/service that implement the
> >> service interface
> >>
> >> @Component(immediate = true, metatype = true)
> >> @Service(value = {ServiceInterface.class, ManagedService.class})
> >> @org.apache.felix.scr.annotations.Properties({
> >>        @Property(name = Constants.SERVICE_PID, value =
> >> "com.example.MyService"),
> >>        @Property(name = Constants.SERVICE_VENDOR, value = "Contoso"),
> >>        @Property(name = Constants.SERVICE_DESCRIPTION, value = "My
> Service"),
> >> })
> >> public class MyService implements ServiceInterface
> >> {
> >>     ...
> >> }
> >>
> >> Bundle C, contains Sling model classes that needs to use the above
> >> service, we inject it using @Inject or @Inject @Source("osgi-service")
> >> as per Sling Model documentation
> >>
> >> @Model(adaptables = {Resource.class})
> >> public class MyModel
> >> {
> >>    @Inject
> >>    private ServiceInterface serviceInterface;
> >>    ...
> >> }
> >>
> >> The problem is that the service never get injected into the model as
> >> it should be, the Exception we get is thrown by the
> >> ModelAdapterFactory saying that it's unable to inject MyService into
> >> ServiceInterface as if they were an incompatible types but they are
> >> not.
> >>
> >> On Wed, Nov 19, 2014 at 9:24 AM, Sarwar Bhuiyan
> >> <[hidden email]> wrote:
> >>> Could you paste that bit of code please?
> >>>
> >>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
> [hidden email]>
> >>> wrote:
> >>>
> >>>> The model is simply a sling model class, not an osgi service at all.
> >>>>
> >>>> The model is being looked up via slightly, thus it has to be fully
> >>>> populated when that happen which require that the model invoke a
> service to
> >>>> obtain data from.
> >>>>
> >>>> Sling model documentation says that you can inject osgi services into
> >>>> sling models but that is not seem to be working.
> >>>>
> >>>> Sent from my iPhone
> >>>>
> >>>>> On 19 Nov 2014, at 09:09, Sarwar Bhuiyan <[hidden email]
> >>>> <javascript:;>> wrote:
> >>>>>
> >>>>> The model is not an OSGi service/component right?
> >>>>>
> >>>>> I'm not sure of why you need a reference to an osgi service in the
> model
> >>>>> but you can probably use a setter by yourself but I still think you
> can
> >>>>> just have another service which does the action on the model instead
> of
> >>>> the
> >>>>> model calling the service.
> >>>>>
> >>>>> On Wednesday, November 19, 2014, Hass Joseph Khafaji <
> >>>> [hidden email] <javascript:;>>
> >>>>> wrote:
> >>>>>
> >>>>>> Hello,
> >>>>>>
> >>>>>> I am trying to inject OSGI service defined using scr annotation
> into a
> >>>>>> sling model class using the @inject annotation.
> >>>>>>
> >>>>>> What we seem to be getting is that the ModelAdapterFactory is
> unable to
> >>>>>> inject the service into the corresponding field as if it was an
> >>>>>> incompatible type. We not doing anything fancy here, it's just a
> simple
> >>>>>> service injection.
> >>>>>>
> >>>>>> Did anyone faced a similar issue in the past? Do we have to use
> custom
> >>>>>> injectors for this?
> >>>>>>
> >>>>>> Note: tried to use the @inject @source with an osgi-service but
> getting
> >>>>>> the same result.
> >>>>>>
> >>>>>> Cheers.
> >>>>
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Robert Munteanu-2
In reply to this post by Bruce Edge
Hi Bruce,

( I realise that it's been three months, but maybe it's useful for you
now ... )

On Mon, 2014-11-17 at 15:44 +0000, Bruce Edge wrote:

> inline
>
> From:  Stefan Egli <[hidden email]>
> Reply-To:  "[hidden email]" <[hidden email]>
> Date:  Monday, November 17, 2014 at 1:03 AM
> To:  "[hidden email]" <[hidden email]>
> Subject:  Re: State of sling eclipse plugins for IDE deploy/undeploy.
>
>
> >Hi Bruce,
> >
> >Which version of the 'org.apache.felix.framework' bundle are you running
> >with ?
> >
> >
>
> I’m using org.apache.felix.framework 4.4.1.
>
> This is the version I get when running the current (or a few days old)
> sling trunk launchpad standalone jar.
>
> -Bruce
>
>
> >
> >Cheers,
> >Stefan
> >
> >On 11/14/14 11:15 PM, "Bruce Edge" <[hidden email]> wrote:
> >
> >>Here¹s the full stack trace from the sling error.log triggered by
> >>³adding² a bundle to the server from inside eclipse.
> >>This shows the original felix NPE, the eclipse console did not.
> >>
> >>14.11.2014 14:11:21.716 *INFO* [qtp124750626-43]
> >>org.apache.sling.tooling.support.install.impl.InstallServlet Unable to
> >>install/update bundle com.nim.ct.dam.bundle.ingest
> >>org.osgi.framework.BundleException: Could not create bundle object.

This looks like SLING-4405 [1], which I just fixed.

There's no need to update the IDE tooling, just deploy an updated
version of the org.apache.sling.tooling.support.install bundle [2] in
your development instance.

Cheers,

Robert

[1]: https://issues.apache.org/jira/browse/SLING-4405
[2]:
https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install/

Reply | Threaded
Open this post in threaded view
|

Re: State of sling eclipse plugins for IDE deploy/undeploy.

Bruce Edge
Nice! All I have to do is wait long enough :-)

thanks

-Bruce


From: Robert Munteanu <[hidden email]<mailto:[hidden email]>>
Reply-To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date: Tuesday, February 17, 2015 at 3:35 PM
To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Subject: Re: State of sling eclipse plugins for IDE deploy/undeploy.

Hi Bruce,

( I realise that it's been three months, but maybe it's useful for you
now ... )

On Mon, 2014-11-17 at 15:44 +0000, Bruce Edge wrote:
inline
From:  Stefan Egli <[hidden email]<mailto:[hidden email]>>
Reply-To:  "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date:  Monday, November 17, 2014 at 1:03 AM
To:  "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Subject:  Re: State of sling eclipse plugins for IDE deploy/undeploy.
>Hi Bruce,
>
>Which version of the 'org.apache.felix.framework' bundle are you running
>with ?
>
>
I’m using org.apache.felix.framework 4.4.1.
This is the version I get when running the current (or a few days old)
sling trunk launchpad standalone jar.
-Bruce

>
>Cheers,
>Stefan
>
>On 11/14/14 11:15 PM, "Bruce Edge" <[hidden email]<mailto:[hidden email]>> wrote:
>
>>Here¹s the full stack trace from the sling error.log triggered by
>>³adding² a bundle to the server from inside eclipse.
>>This shows the original felix NPE, the eclipse console did not.
>>
>>14.11.2014 14:11:21.716 *INFO* [qtp124750626-43]
>>org.apache.sling.tooling.support.install.impl.InstallServlet Unable to
>>install/update bundle com.nim.ct.dam.bundle.ingest
>>org.osgi.framework.BundleException: Could not create bundle object.

This looks like SLING-4405 [1], which I just fixed.

There's no need to update the IDE tooling, just deploy an updated
version of the org.apache.sling.tooling.support.install bundle [2] in
your development instance.

Cheers,

Robert

[1]: https://issues.apache.org/jira/browse/SLING-4405
[2]:
https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install/