[MarkLogic Dev General] AngularJS to MarkLogic Connectivity Isssue

Varinder Tandon varinder.tandon at gmail.com
Tue Mar 31 07:04:41 PDT 2015


Try adding cross filters in web.xml your app..

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
      <param-name>cors.allowed.origins</param-name>
      <param-value>*</param-value>
    </init-param>
    <init-param>
      <param-name>cors.allowed.methods</param-name>
      <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
    </init-param>
    <init-param>
      <param-name>cors.allowed.headers</param-name>

<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
    </init-param>
    <init-param>
      <param-name>cors.exposed.headers</param-name>

<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
    </init-param>
    <init-param>
      <param-name>cors.support.credentials</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>cors.preflight.maxage</param-name>
      <param-value>10</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

On Mon, Mar 30, 2015 at 10:23 PM, SateeshKumar Bheemsetty <
sateesh.bheemsetty at gmail.com> wrote:

> Hi Team,
>
> I am trying to save a user entered[page developed in AngularJS]
> information as a json document in Mark Logic through ML REST API but am
> facing below issue :
>
> *browser console:*
> "NetworkError: 401 Unauthorized -
> http://localhost:8003/v1/documents?uri=/docs/"
> documen...=/docs/
> 2
> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
> remote resource at http://localhost:8003/v1/documents?uri=/docs/. This
> can be fixed by moving the resource to the same domain or enabling CORS.
>
>
> *In browser NetWork Tab it shows as below :*
>
> <error-response xmlns="http://marklogic.com/xdmp/error">
>   <status-code>404</status-code>
>   <status>Not Found</status>
>   <message-code>RESTAPI-NODOCUMENT</message-code>
>   <message>RESTAPI-NODOCUMENT: (err:FOER0000) Resource or document does
> not exist:  category: content message: /docs/userInfo.json
> </message>
> </error-response>
>
> *code tried to connect :*
> $http({
>     method: 'PUT',
>     url: 'http://localhost:8003/v1/documents?uri=/docs/userInfo.json',
>     data: data1,
> headers:{
>                 'Access-Control-Allow-Origin': '*',
>                 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE,
> OPTIONS',
>                 'Access-Control-Allow-Headers': 'Content-Type,
> X-Requested-With'
>             }
> }).success(function () {alert('Successfully Added In DB');});
> }
> });
>
> My Angular JS web page is deployed in tomcat on port 7080 and my REST API
> is located at 8003.Also i have not passed any credentials to connect ML and
> am not not sure on how to pass authentication .
>
> Could you please guide me in getting this resolved.
>
>
> Thanks,
> Sateesh
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150331/443bb038/attachment-0001.html 


More information about the General mailing list