Search code examples
dependencieshttpclient

ClassNotFoundException : org.apache.http.util.Args - how to upload file using MultipartEntityBuilder?


This is what I am getting

org.apache.http.util.Args. Stacktrace follows: Message: org.apache.http.util.Args Line | Method ->> 366 | run in java.net.URLClassLoader$1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 355 | run in '' | 354 | findClass . . . . . . . . . . . . in java.net.URLClassLoader | 423 | loadClass in java.lang.ClassLoader | 48 | . . . . . . . . . . . . . . in org.apache.http.entity.mime.content.AbstractContentBod | 155 | in org.apache.http.entity.mime.content.StringBody | 121 | addTextBody . . . . . . . . . . . in org.apache.http.entity.mime.MultipartEntityBuilder | 271 | $tt__getResponseFromHttpPostServer in com.org.basepin.UserService$$ER2a9kvc | 184 | $tt__createRequest . . . . . . . . in '' | 437 | $tt__uploadClashImages
in '' | 1325 | doCall . . . . . . . . . . . . . . in com.org.basepin.UserController$_fetchClashReportImages | 1323 | fetchClashReportImages in com.org.basepin.UserController | 198 | doFilter . . . . . . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilt | 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter | 1110 | runWorker . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor |
603 | run in java.util.concurrent.ThreadPoolExecutor$Worker ^ 722 | run . . . . . . . . . . . . . . . in java.lang.Thread

BuildConfig.groovy dependencies{

 compile('org.apache.httpcomponents:httpcore:4.2.4'){
             excludes "commons-codec"
         }
         compile('org.apache.httpcomponents:httpclient:4.1.2'){
             excludes "commons-codec"
         }
         compile('org.apache.httpcomponents:httpmime:4.3'){
             excludes "commons-codec"
         }
         //compile "org.grails.plugins:rest:0.8"

        runtime('org.apache.httpcomponents:httpcore:4.2.4'){
            excludes "commons-codec"
        }
        runtime('org.apache.httpcomponents:httpclient:4.1.2'){
            excludes "commons-codec"
        }
        runtime('org.apache.httpcomponents:httpmime:4.3'){
            excludes "commons-codec"
        }
     }

Solution

  • At a quick glance, I would assume that httpmime 4.3 uses that Args class, and it's expecting it to be supplied by the httpcore dependency. You aren't depending on version 4.3 of httpcore, and that would appear to be when it was introduced.

    Update your httpcore dependency to 4.3, and this error should resolve. While you're at it, I'd make all three of these dependencies use the same version, or you might see another of these errors crop up.