Gen EJB Web Service via React web server blocked by WebSphere CORS policy
search cancel

Gen EJB Web Service via React web server blocked by WebSphere CORS policy

book

Article ID: 408257

calendar_today

Updated On:

Products

Gen

Issue/Introduction

Gen 8.6 EJB web service deployed to WebSphere Application Server (WAS).
When called from React web server it is blocked by WAS CORS policy and using browser in Developer Mode shows this error on the Console tab:

Access to XMLHttpRequest at 'http://was_server:9080/SM1/PSETP1' from origin 'http://localhost:5173' 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.

Environment

Gen 8.6 EJB Web Service

Resolution

This not a Gen problem.

The message means that WAS running on host was_server is not allowing the access to the Gen EJB Web Service URL from the origin/domain localhost.
Assuming there is no firewall and there is direct network access to the WebSphere Application Server was_server/9080 loading the web service wsdl 'http://was_server:9080/SM1/PSTEP1?wsdl' directly into a browser should be successful .

There are several articles on the internet about the CORS policy message "No 'Access-Control-Allow-Origin' header is present on the requested resource" and how to resolve it e.g. Bannerbear Blog > Developers > What Is a CORS Error and How to Fix It (3 Ways)

Of the 3 options listed there for #1 (Configure the Backend to Allow CORS) that does not seem possible with Traditional WebSphere Application Server (only with WebSphere Liberty)
So only the 2nd (Use a Proxy Server) or 3rd (Bypass the Error Using a Browser Extension) options might be possible.

Alternatively if React and WAS are installed on the same server if run React web server under hostname was_server instead of localhost then the problem may go away because the domains will be the same.