Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Cannot get HttpContext trough BundleContext in AEM 6.4

Avatar

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile
ralvarado88
Level 2

26-07-2018

Hi!

I am working on migrating some bundles from AEM 6.2 to 6.4 and I ran into the following issue:

I have an Activator.java in a bundle with the following code:

@Override

public synchronized void start(final BundleContext bc) throws Exception {

     myBundleContext= bc

     private ServiceTracker<HttpService, HttpService> tracker = new ServiceTracker<HttpService, HttpService>(myBundleContext, HttpService.class, null) {

          @Override

          public HttpService addingService(ServiceReference<HttpService> sRef) {

               ServiceReference<HttpContext> httpSRef = bundleContext.getServiceReference(HttpContext.class);

               HttpContext hc = bundleContext.getService(httpSRef);

               //some more code here working with the hc object...

           }

     }

}

When I start the bundle and run this code in AEM 6.2, I can successfully retrieve the HttpContext.class serviceReference and then get the HttpContext service, but when I run the exact same code in AEM 6.4 I get a null reference when trying to retrieve the HttpContext.class serviceReference.
I am aware that this kind of thing (using an activator and getting the HttpContext serviceReference) are not that common to do. I have already googled the problem for quite a while, read all kind of forums and threads but no luck yet.
I also checked that the service name  and class are still the same in 6.2 and 6.4 and also the getServiceReference(Class) method is not deprecated in 6.4

So I'm starting to suspect that for some reason the HttpContext is not available in 6.4 as it was in 6.2. Not sure if it's something that was done intentionally or if it's a bug


Any help on this would be very appreciated!

Thanks!!

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

27-07-2018

Hi,
could you please check if HttpContext service is available at http://localhost:4502/system/console/status-Services  ?

I can't see this service in AEM6.3 and AEM6.4

Thanks

Arun

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

27-07-2018

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

27-07-2018

I used Dep Finder on 6.4

Dep11.png

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

27-07-2018

Hi,

I think service is missing or deprecated.

Please Use ServletContextHelper instead of HttpContext

Both have the same purpose.

ServletContextHelper works with AEM6.4

Thanks

Arun

Avatar

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile
ralvarado88
Level 2

06-08-2018

Thanks! actually the service is not available in 6.3 and 6.4
No idea why it is not

Avatar

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
ralvarado88
Level 2

Likes

10 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile
ralvarado88
Level 2

06-08-2018

Hi guys

As you mentioned above, the HttpContext service is not available in AEM 6.3 and 6.4
The good news is that what this service did in 6.2 was using the org.apache.sling.auth.core.AuthenticationSupport handleSecurity method, and the AuthenticationSupport service is available in 6.3 and 6.4.
I managed to solve it by creating a custom HttpContext that inside uses the AuthenticationSupport class. I explain it here:

https://medium.com/@rijoalvi/aem-6-4-httpcontext-use-case-5824e486ebaf

Thank you all for your help with this!

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,346 likes

Total Posts

3,223 posts

Correct Reply

915 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

07-08-2018

Thanks rijoalvi for posting this.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

07-08-2018

Thanks for posting solution.