MikePatel
MikePatel

Reputation: 2672

CORS - Origin http://localhost is not allowed by Access-Control-Allow-Origin. error.

I'm having trouble enabling CORS for a web-app i'm building using the atmosphere framework (https://github.com/Atmosphere/atmosphere)

My request looks something like :

/**
 * @constructor
 * @extends {goog.events.EventTarget}
 *
 * @param {string} id The id.
 * @param {string} url The url.
 * @param {Object} request The request options.
 */
atom.Request = function(id, url, request) {
  this.setParentEventTarget(core.inject(atom));
  this.url = url;
  this.requestOptions_ = {};
  goog.object.extend(this.requestOptions_, request);
  goog.object.extend(this.requestOptions_, {
    'url' : url,
    'onError' : goog.bind(this.onError, this),
    'onClose' : goog.bind(this.onClose, this),
    'onOpen': goog.bind(this.onOpen, this),
    'fallbackTransport' : 'jsonp',
    'onMessage' : goog.bind(this.onMessage, this),
    'onMessagePublished': goog.bind(this.onMessagePublished, this),
    'onReconnect': goog.bind(this.onReconnect, this),
    'enableXDR': 'true',
    'transport': 'streaming'
  });
  this.id_ = id;
  this.request_ = $.atmosphere.subscribe(this.requestOptions_);
};
goog.inherits(atom.Request, goog.events.EventTarget);

and on the server (tomcat7.0.32) my filter is the transactioncompany cors filter (http://software.dzhuvinov.com/cors-filter.html)

web.xml :

<filter>
    <filter-name>corsFilter</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

      <init-param>
            <param-name>cors.allowGenericHttpRequests</param-name>
            <param-value>true</param-value>
       </init-param>
        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
       </init-param>
        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, HEAD, POST, OPTIONS</param-value>
       </init-param>
        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>Origin, Content-Type, X-Requested-With, Access-Control-Allow-Origin</param-value>
       </init-param>
        <init-param>
            <param-name>cors.supportsCredentials</param-name>
            <param-value>true</param-value>
       </init-param>
        <init-param>
            <param-name>cors.maxAge</param-name>
            <param-value>3600</param-value>
       </init-param>
</filter>

When I make a request from the client I will get the Origin http://localhost is not allowed by Access-Control-Allow-Origin. error.

Request information :

Request Headers 

Cache-Control:no-cache
Origin:http://localhost
Pragma:no-cache
Referer:http://localhost/sportsdesk/build/development/en/application.html
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1

Query String Parameters

X-Atmosphere-tracking-id:0
X-Atmosphere-Framework:1.1
X-Atmosphere-Transport:streaming
X-Cache-Date:0
_:1352918719739

At this point i'm really out of ideas when it comes to the problem. Can someone spot it ?

Cheers, Mike.

Upvotes: 0

Views: 3284

Answers (1)

monsur
monsur

Reputation: 47927

Set cors.supportsCredentials to "false" (You can always reenable it if you set withCredentials on your XHR request).

Upvotes: 1

Related Questions