openhab-cloud icon indicating copy to clipboard operation
openhab-cloud copied to clipboard

415 error while trying to execute a rule manually

Open candiesdoodle opened this issue 4 years ago • 6 comments

On myopenhab.org While trying to trigger a rule manually from UI by clicking the play button, there is an error "Error while running the rule: Ok"

In the openhab logs there is a 415 error I have tried with other rules too as call be seen in the screenshots When trying to do the same from local network, the rule is executed as expected. I had posted here in the community but didn't get a response. I have also upgraded to the latest snapshot but this still remains

2021-02-09 07:58:47.357 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.ClientErrorException: HTTP 415 Unsupported Media Type
	at org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
	at org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:514)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:494)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918)
	at java.base/java.lang.Thread.run(Thread.java:834)

Expected behavior

The rule should execute

Steps to reproduce

  1. Goto myopenhab.org and login
  2. Try to execute a rule manually by clicking the play button

candiesdoodle avatar Feb 09 '21 02:02 candiesdoodle

Hello, any feedback on this Thanks

candiesdoodle avatar Feb 10 '21 16:02 candiesdoodle

I too have this problem but seem to have narrowed it down a bit.

  1. It happens when I have an overview cell that triggers a rule on click
  2. It DOESN'T happen when I'm directly connected to my OpenHAB instance
  3. It only happens when I'm connected through a cloud instance (either myopenhab.org or my personal cloud server)

The error itself seems to be generated because a REST POST request is made, without setting the content-type in the header to application/json.

As to WHERE in the code that's happening, I have no idea yet.

iwilliamson avatar Apr 03 '21 22:04 iwilliamson

I fixed this for myself in my personal cloud instance (though I think it's a bug in the OpenHab Core). The trouble is, when you're running rules directly, there is no data for the REST API call. I suspect that, because there is no data, the "content-type" setting for the request never gets set.

I added a simple change in routes/index.js, Routes.prototype.proxyRouteOpenhab() to add a "content-type" header entry if there wasn't one, just before the call where the request is forwarded:

    if( requestHeaders['content-type'] === undefined )
    {
        requestHeaders['content-type'] = 'text/plain';
    }

    // Send a message with request to openhab agent module
    this.io.sockets.in(req.openhab.uuid).emit('request', {
        id: requestId,
        method: req.method,
        headers: requestHeaders,
        path: requestPath,
        query: req.query,
        body: req.rawBody
    });

iwilliamson avatar Apr 05 '21 19:04 iwilliamson

Alright, just adding content-type of plain/text is not the answer...It seems to have side effects that cause the web page not to load...

iwilliamson avatar Apr 05 '21 20:04 iwilliamson

I've had some time to do a little more research and SEEM to have it working now. I think the trouble is that the content-length is set (to zero) but no content-type gets set. So the fix that seems to work without any side effects is:

    if( requestHeaders['content-length'] === '0' )
    {
        requestHeaders['content-type'] = 'text/plain';
    }

    // Send a message with request to openhab agent module
    this.io.sockets.in(req.openhab.uuid).emit('request', {
        id: requestId,
        method: req.method,
        headers: requestHeaders,
        path: requestPath,
        query: req.query,
        body: req.rawBody
    });

I've been using it for a while now without any side effects except my rule running properly.

Could someone else please try it out and see if that's the fix?

iwilliamson avatar Apr 11 '21 19:04 iwilliamson

https://github.com/openhab/openhab-addons/pull/10600 has been merged.

cweitkamp avatar Apr 28 '21 07:04 cweitkamp