From c879e4f7f2debc5d487cc12e2d625ba789f0ddb7 Mon Sep 17 00:00:00 2001 From: "Samuel B. Johnson" Date: Tue, 28 Jun 2016 11:03:09 -0400 Subject: [PATCH] Fix client marshaling problem For some reason, Jenkins was having problems when trying to reload the `CodeDxClient` instance from the config.xml file for the job. The problem was related to being unable to instantiate an instance of `LayeredSocketConnectionFactory` (which is an interface). Why it was trying to do that rather than instantiating an implementing class is unknown. Making the `client` property transient, and then reloading it only when it's needed solves the problem, as there's nothing in the client itself that needs to be persisted. --- .../plugins/codedx/CodeDxPublisher.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/codedx/CodeDxPublisher.java b/src/main/java/org/jenkinsci/plugins/codedx/CodeDxPublisher.java index 93ff9f4..6600a9b 100644 --- a/src/main/java/org/jenkinsci/plugins/codedx/CodeDxPublisher.java +++ b/src/main/java/org/jenkinsci/plugins/codedx/CodeDxPublisher.java @@ -72,7 +72,7 @@ public class CodeDxPublisher extends Recorder { private final AnalysisResultConfiguration analysisResultConfiguration; - private final CodeDxClient client; + private transient CodeDxClient client; private final String selfSignedCertificateFingerprint; @@ -105,7 +105,13 @@ public CodeDxPublisher(final String url, this.toolOutputFiles = toolOutputFiles; this.analysisResultConfiguration = analysisResultConfiguration; this.selfSignedCertificateFingerprint = selfSignedCertificateFingerprint; - this.client = buildClient(url, key, selfSignedCertificateFingerprint); + setupClient(); + } + + private void setupClient() { + if (this.client == null) { + this.client = buildClient(url, key, selfSignedCertificateFingerprint); + } } public AnalysisResultConfiguration getAnalysisResultConfiguration() { @@ -150,7 +156,7 @@ public Action getProjectAction(AbstractProject project) { String latestUrl = null; if (projectId.length() != 0 && !projectId.equals("-1")) { - + setupClient(); latestUrl = client.buildLatestFindingsUrl(Integer.parseInt(projectId)); } @@ -162,7 +168,7 @@ public boolean perform( final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException { - + setupClient(); final List toSend = new ArrayList(); listener.getLogger().println("Starting Code Dx Publish"); @@ -397,6 +403,9 @@ public static CodeDxClient buildClient(String url, String key, String fingerprin logger.warning("A valid CodeDxClient could not be built. Malformed URL: " + url); } catch (GeneralSecurityException e) { logger.warning("A valid CodeDxClient could not be built. GeneralSecurityException: url: " + url + ", fingerprint: " + fingerprint); + } catch (Exception e) { + logger.warning("An exception was thrown while building the client " + e); + e.printStackTrace(); } return client; }