jenkinsci / google-chat-notification-plugin

Google Chat Notification Jenkins Plugin to send build status
https://plugins.jenkins.io/google-chat-notification/
MIT License
39 stars 20 forks source link

Don't use deprecated org.apache.commons.httpclient #38

Closed gpflaum closed 1 year ago

gpflaum commented 1 year ago

Calling googlechatnotification in a pipeline on Jenkins 2.387 fails with this error:

java.lang.ClassNotFoundException: org.apache.commons.httpclient.util.URIUtil
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
    at jenkins.util.URLClassLoader2.findClass(URLClassLoader2.java:35)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
Caused: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/util/URIUtil
    at io.cnaik.service.CommonUtil.call(CommonUtil.java:175)
    at io.cnaik.service.CommonUtil.notifyForEachUrl(CommonUtil.java:89)
    at io.cnaik.service.CommonUtil.send(CommonUtil.java:66)
    at io.cnaik.GoogleChatNotification.performAction(GoogleChatNotification.java:399)
    at io.cnaik.GoogleChatNotification.perform(GoogleChatNotification.java:241)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

https://javadoc.io/static/commons-httpclient/commons-httpclient/3.1-jenkins-1/org/apache/commons/httpclient/util/URIUtil.html says:

Jakarta Commons HttpClient 3.x is deprecated in the Jenkins project. It is not recommended to use it in any new code. Instead, use HTTP client API plugins as a dependency in your code. E.g. Apache HttpComponents Client API 4.x Plugin or Async HTTP Client Plugin.

It seems it is not just deprecated, but actually removed from Jenkins.

As noted in that quote, one fix for this would be to add a dependency on an API plugin such as apache-httpcomponents-client-4-api, and use URIBuilder. Or we could use Java's URI class. Instead, I added back the org.springframework.web.util.UriUtils import that was recently removed because it was unused.