Enabling CORS on tomcat

Long time no post!

Hi

As i have already told, our Dynamic CRM Customizations deals with ABAS ERP software.

To respond some requirements of Service Processing subsystem, in a CASE form we want a button that by clicking on, product information get loaded to the form. User inputs a serial number, and by that SN, a request made to ERP server and products information get back as response.

ABAS ERP developing team already developed a SOAP web service which sync customer data between ERP and CRM. It works fine when it used as a service reference int a CRM plugin. But when it comes to use web service in a html client using Java Script, story changes. First of all I had to find a JS lib to parse SOAP messages. It was easy, I googled and found javascriptsoapclient. But as the origin of CRM and web service host are different, browser does not allow js to request the web service and throws “Access-Control-Allow-Origin” error.

I am new to Java developed web services and also to apache tomcat web. If it was a .net web service, I could solve problem by adding required headers. But the web service is a Java project and developed using Eclipse IDE. After a lots of research I found that I cand add CORS (Cross Origin resource sharing) to tomcat, but for versions higher than 7.0.41 !

I installed latest version and read lots of documents and questions around web. In official docs of tomcat, it says by adding some xml tags you can enable CORS for entire apps hosted in tomcat. As it seems it is not actually that easy.

What I had to do? I had to download two libraries mentioned in this  guideline and them to lib folder of tomcat. It is the best solution, but in addition to add those libraries to the lib folder of tomcat, you also  have to add them to lib folder of the application you want to have CORS enabled.

Regards.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s