2

When I try to access Webhdfs from my Angular 6 app I get the error shown below. It seems to me that I tried almost everything including changing settings in core-site.xml and hdfs-site.xml unfortunately without positive result. Obviously, most likely it is needed to configure Hadoop properly. Does anyone have an idea how can I solve this problem?

[Error] Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.
[Error] XMLHttpRequest cannot load http://192.168.0.16:9870/webhdfs/v1/user/myuser/myfile.csv?op=CREATE&user.name=myuser&createflag=&createparent=true&overwrite=false due to access control checks.
[Error] Failed to load resource: Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin. (myfile.csv, line 0)
thedbogh
  • 614
  • 2
  • 10
  • 26

4 Answers4

1

From the docs:

To enable cross-origin support (CORS), please set the following configuration parameters:

Add org.apache.hadoop.security.HttpCrossOriginFilterInitializer to hadoop.http.filter.initializers in core-site.xml. You will also need to set the following properties in core-site.xml -

hadoop.http.cross-origin.enabled = true

hadoop.http.cross-origin.allowed-origins = *

hadoop.http.cross-origin.allowed-methods = GET,POST,HEAD,DELETE,OPTIONS

hadoop.http.cross-origin.allowed-headers = X-Requested-With,Content-Type,Accept,Origin

hadoop.http.cross-origin.max-age = 1800

Community
  • 1
  • 1
danday74
  • 52,471
  • 49
  • 232
  • 283
  • I did it multiple times without effects. Can you show me how exactly should code added to `core-site.xml` look like? – thedbogh Oct 11 '18 at 21:27
0

you should config hdfs-site.xml, and add configuration

<property>
    <name>dfs.permissions</name>
    <value>false</value>
    <description>If "true", enable permission checking in HDFS. If "false", permission checking is turned off, but all other behavior is unchanged. Switching from one parameter value to the other does not change the mode, owner or group of files or directories.</description>
</property>

0

In core-site.xml add this if not there...

<property>
  <name>hadoop.http.filter.initializers</name>
  <value>org.apache.hadoop.http.lib.StaticUserWebFilter,org.apache.hadoop.security.HttpCrossOriginFilterInitializer</value>
  <description>A comma separated list of class names. Each class in the list
  must extend org.apache.hadoop.http.FilterInitializer. The corresponding
  Filter will be initialized. Then, the Filter will be applied to all user
  facing jsp and servlet web pages.  The ordering of the list defines the
  ordering of the filters.</description>
</property>
<property>
<name>hadoop.http.cross-origin.enabled</name>
<value>true</value>
<description>Enables cross origin support for all web-services</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-origins</name>
<value>*</value>
<description>Comma separated list of origins that are allowed, wildcards (*) and patterns allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-methods</name>
<value>GET,POST,HEAD,PUT,OPTIONS,DELETE</value>
<description>Comma separated list of methods that are allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-headers</name>
<value>X-Requested-With,Content-Type,Accept,Origin,WWW-Authenticate,Accept-Encoding,Transfer-Encoding</value>
<description>Comma separated list of headers that are allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.max-age</name>
<value>1800</value>
<description>Number of seconds a pre-flighted request can be cached</description>
</property>
Keshav Sharma
  • 483
  • 4
  • 7
0

You have to append these properties into this file etc/hadoop/core-site.xml

<configuration>
    <property>
            <name>hadoop.http.cross-origin.enabled</name>
            <value>false</value>
    </property>
    <property>
            <name>hadoop.http.cross-origin.allowed-origins</name>
            <value>*</value>
    </property>
    <property>
            <name>hadoop.http.cross-origin.allowed-methods</name>
            <value>GET,POST,HEAD</value>
    </property>
    <property>
            <name>hadoop.http.cross-origin.allowed-headers</name>
            <value>X-Requested-With,Content-Type,Accept,Origin</value>
    </property>
    <property>
            <name>hadoop.http.cross-origin.max-age</name>
            <value>1800</value>
    </property></configuration>
Shabab Qaisar
  • 60
  • 1
  • 9