CORS header issues when using KNIME REST API

#1

Hello, I’ve been trying to implement a web service in which I would only have to ‘call’ a REST API workflow by using a GET method.

I’ve done this before using postman and the swagger UI to get a successful result, but when I call it in my web-service (which incorporates a browser, I guess), I tend to get the CORS error saying that

[Request] from origin ‘http://localhost:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

This is the screenshot of the headers minus the authentication on postman.

Is there any advice I can get about deploying KNIME REST as a webservice?

0 Likes

#2

Also, I would like a guide about implementing CORS setting on the Knime AWS server.

0 Likes

#3

Am I correct in assuming you are trying to deploy a KNIME workflow as a RESTful web service on a KNIME Server? This isn’t clear from your description.
Can be a bit more specific what exactly you want to achive? Are you trying to call the workflow from inside a web page hosted on a different server?

0 Likes

#4

Yes that is exactly what I am trying to do, deploy a KNIME workflow as a RESTful web service based on an AWS-based KNIME server.

So I have my workflow in the knime server(AWS). My client will call the REST API (GET), then it will run the model with his credentials, and he will get the recommendation.

Thanks.

0 Likes

#5

Then you will need to add an Access-Control-Allow-Originheader the the response from the KNIME Server. This can be achieved by changing the TomEE configuration. The changes should be made in /conf/web.xml. Alternatively you can also run the KNIME Server behind a frontend server and add the header there. For more details on CORS see https://www.w3.org/wiki/CORS_Enabled.

0 Likes

#6

How can i access the conf/web.xml in the AWS-loaded knime server?

0 Likes

#7

I am not originally a AWS developer, and am very inexperienced with server-management related services… Thus I might seem like a real newbie.

0 Likes

#8

You have to log into the instance with SSH and then edit the file.

0 Likes

#9

thanks. Could I know the location of the conf/web.xml file? I tried accessing it through putty, and could not see it. Is it a hidden file?

0 Likes

#10

Thanks. I’ve been going into the file and editing the cors settings.

I’ve done my settings as such, and now am getting a “connection refused” message.

Could you help me out where did I set this wrong? The headers I am using from my client side are
Authorization
Access-Control-Allow-Headers
Access-Control-Allow-Origin

Furthermore, if I tweak with the CORS settings, then there is a connection problem that persists within the server. Even when I try to access the workflow from my desktop knime program, the error message comes out saying that the server does not support session cookies.

It would be nice if you could give further assistance on CORS setting.

Thanks.

0 Likes

#11

By the way, thank you so much. I’ve just now finished this CORS authorization issue. Now the JDBC is raising another issue.

Thank you so much for your help. Thanks to you, I’ve got this issue solved!

1 Like