Browser requests credentials in Eclipse dev environment for new servlet

I have a problem when running OH in a 2.5 dev environment (Eclipse 09/2020). Maybe someone can help - it worked in the past, but now I can’t get it working to debug the code

I’m adding a new servlet to the Shelly binding, which registers the URI /shelly/manager

    public static final String SHELLY_MANAGER_URI = "/shelly/manager";

    private static final String SERVLET_URI = SHELLY_MANAGER_URI;

    public ShellyManagerServlet(@Reference HttpService httpService, @Reference ShellyHandlerFactory handlerFactory,
            Map<String, Object> config) {
        className = substringAfterLast(getClass().toString(), ".");
        this.httpService = httpService;
        this.handlerFactory = handlerFactory;
        try {
            httpService.registerServlet(SERVLET_URI, this, null, httpService.createDefaultHttpContext());
            logger.debug("{} started at '{}'", className, SERVLET_URI);
        } catch (NamespaceException | ServletException | IllegalArgumentException e) {
            logger.warn("Could not start {}", className, e);
        manager = new ShellyManager(handlerFactory.getThingHandlers());

which is performed without errors (same I do with /shelly/event to get the event callbacks from the device).

Now I want to debug the new servlet, but I can’t access it from the browser nor with curl. Instead of getting the page the browser prompts we for credentials, which is unusual. Also when I use the default ones openhab:habopen I’m not able to complete the request - the browser brings up the popup again.

curl -v
* Trying
* Connected to ( port 8080 (#0)
> GET /shelly/manager HTTP/1.1
> Host:
> User-Agent: curl/7.64.1
> Accept: */*
< HTTP/1.1 401 Unauthorized
< Date: Tue, 29 Dec 2020 18:25:29 GMT
< WWW-Authenticate: Basic realm="OSGi Management Console"
< Content-Length: 0
< Server: Jetty(9.4.20.v20190813)
* Connection #0 to host left intact
* Closing connection 0

I also used the regular network ip instead of with the same result.

When I build the jar with mvn and put this on a “regular” OH instance the servlet works as expected and the code is executed. works as expected nor does not.

I see no request nor any debug output from my servlet in the log.

I did not any changes to the jetty config nor

openhab = habopen,_g_:admingroup
_g_\:admingroup = group,admin,manager,viewer,systembundles

@hilbrand Any idea how to authorizes access to /shelly/*?

It might be not specifically be an authentication problem. If I remember correctly you can also get this when the servlet (or page) can’t be found.

It should work I think. However you’re registering the servlet in it’s own constructor. Using this in a constructor to refer to the instance is generally not recommended as it’s at that point still creating the instance. So I would start by moving the registration out of the constructor and move it to the factory.

I also don’t know what getThingHandlers() returns. But if it returns the created handlers it doesn’t seem right. Because that would be dynamic information and so needs to be dynamically added/removed on creating on a handler and not something I would expect in a constructor.

Thanks for the feedback on the code style, I‘ll take that into account.

I made some progress with the page itself, but still not able to debug

  • when I run it inside the IDE the browser prompts for credentials
  • It works fine when I build it with mvn and copy on a regular installation, I could use /shelly/manager
  • also the existing /shelly/event (existing code) shows the same behavior

I also tried to setup a fresh 2.5 IDE, but noticed that Java 8 is no longer selectable (only J11)

Now it gets even strange

  • I tried my OH3 IDE
  • there the Servlet constructor is not triggered = prefix will not be registered
  • and I see a “not found” in the browser

What blocks calling the constructur for the servlet?

ok, after Project Clean, mvn clean install etc. AND setting the version to 3.1 in pom.xml for the demo app I’m able to debug in the OH3 environment (even I did that more than once).
it seems that Eclipse loaded an older jar, because the bnd dependencies were not refreshed

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.