PRVS
PRVS

Reputation: 1690

TypeError: g.getResponseHeader is undefined

I have this code:

Connector conn = FrameworkUtil.getConnector(context, ALFRESCO_ENDPOINT_ID);
ConnectorContext c = new ConnectorContext(HttpMethod.POST);
c.setContentType("application/json");

Response res = conn.call("/slingshot/profile/userprofile", c,
                    new ByteArrayInputStream(buf.toString().getBytes()));

That makes a POST to the link: POST http://localhost:8080/share/service/components/profile/userprofile

But, I got the error:

TypeError: g.getResponseHeader is undefined

...unction(g){var b=g.argument.config;var f=g.getResponseHeader["Content-Type"]||g....

In a search on the Internet, I saw that this can be a problem that is solved adding Content-Type with CORS.

Something like:

 .header("Access-Control-Allow-Headers", "x-requested-with,Content-Type");

How can I do this in my code? With Connector or ConnectorContext I don't find a way to set the header...

Or if this is not the way to solve this, how can I solve this error?

Upvotes: 1

Views: 192

Answers (1)

Dave Draper
Dave Draper

Reputation: 1845

I think you might have a few things configured incorrectly here, or you might be misunderstanding a few things. If you're making a remote connection to the ALFRESCO_ENDPOINT_ID then this typically means that you're trying to connect to the Alfresco Repository - and based on where you say you're trying to make the call from it would appear that this is in a Java-backed WebScript running within the Share application - is this correct?

If so, the URL that should be requested would actually be:

http://localhost:8080/alfresco/service/slingshot/profile/userprofile

Which would be equivalent to calling the following:

http://localhost:8080/share/proxy/alfresco/slingshot/profile/userprofile

(the second URL automatically proxies to the Alfresco enpoint).

If you have both the Alfresco Repository and Share running in the same server (which the use of the port 8080 implies you do) then you shouldn't be hitting CORS issues - unless you're trying to go from localhost to some remote location where the Alfresco Repository is running.

Share/Surf should be taking care of all of this for you - perhaps you can provide a bit more context on exactly what it is you're trying to do, where the code is running (e.g. WebScript, Share, etc) and where you're trying to connect to?

This might help in best advising how to solve your main problem.

Upvotes: 2

Related Questions