Skip to content

Commit

Permalink
Fix client marshaling problem
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samuelbjohnson committed Jun 28, 2016
1 parent b8b8a0f commit c879e4f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/jenkinsci/plugins/codedx/CodeDxPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
}

Expand All @@ -162,7 +168,7 @@ public boolean perform(
final AbstractBuild<?, ?> build,
final Launcher launcher,
final BuildListener listener) throws InterruptedException, IOException {

setupClient();
final List<InputStream> toSend = new ArrayList<InputStream>();

listener.getLogger().println("Starting Code Dx Publish");
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c879e4f

Please sign in to comment.