title: Chef download and install Oracle Java on Windows
body: <p>I want to install Java with Chef 13 on Windows 7.</p>
  
  <p>Installing from file is easy, but I want also to download it from Oracle archives. The thing is, Oracle requires special cookie - <code>oraclelicense=accept-securebackup-cookie</code>.</p>
  
  <p>I've tried <a href="https://supermarket.chef.io/cookbooks/java#readme" rel="nofollow noreferrer">java</a> cookbook, as it seems people did it without problems. Hovewer, after running Chef I get error:</p>
  
  <pre><code>Recipe: java::notify
    * log[jdk-version-changed] action nothing (skipped due to action :nothing)
  Recipe: java::windows
    * ruby_block[Enable Accessing cookies] action run
      - execute the ruby block Enable Accessing cookies
    * remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] action create[2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"
  [2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"
  
  
    ================================================================================
    Error executing action `create` on resource 'remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe]'
    ================================================================================
  
    Net::HTTPServerException
    ------------------------
    401 "Authorization Required"
  
    Resource Declaration:
    ---------------------
    # In C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb
  
     62:   remote_file cache_file_path do
     63:     checksum pkg_checksum if pkg_checksum
     64:     source node['java']['windows']['url']
     65:     backup false
     66:     action :create
     67:   end
     68: end
  
    Compiled Resource:
    ------------------
    # Declared in C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb:62:in `from_file'
  
    remote_file("C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe") do
      provider Chef::Provider::RemoteFile
      action [:create]
      default_guard_interpreter :default
      source ["http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe"]
      use_etag true
      use_last_modified true
      declared_type :remote_file
      cookbook_name "java"
      recipe_name "windows"
      path "C:/Users/User\\.chef\\local-mode-cache\\cache/jdk-7u79-windows-i586.exe"
      checksum nil
      rights nil
      deny_rights nil
      verifications []
    end
  
    System Info:
    ------------
    chef_version=13.0.118
    platform=windows
    platform_version=6.1.7600
    ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [i386-mingw32]
    program_name=C:/opscode/chef/bin/chef-client
    executable=C:/opscode/chef/bin/chef-client
  </code></pre>
  
  <p>As you can see in logs above, I've set <code>['java']['oracle']['accept_oracle_download_terms']</code> to true (<code>execute the ruby block Enable Accessing cookies</code>).</p>
  
  <p>Since this cookbook didn't work for me, I've tried to do my own java cookbook:</p>
  
  <pre><code>windows_package package_name do
         source                 source
         action                 :install
         installer_type         :custom
         remote_file_attributes ({
           :headers =&gt; {"Cookie" =&gt; "oraclelicense=accept-securebackup-cookie"}
        })
        options                 opts
  end
  </code></pre>
  
  <p>... and it still gets the same error.</p>
  
  <p>Did anything change on Oracle site that downloading JDK doesn't work anymore? Or do I have to set firewall or something?</p>