java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl in Jenkins pipeline











up vote
1
down vote

favorite












There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS doesn't seem to work. Here's the relevant piece of the code:



@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()

withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}

connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true

if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}

connection.connect();

def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}

return connection.content.text
}


Note that it does have @NonCPS on the function. However executing this still produces the same error:



an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...


How can I solve it?










share|improve this question






















  • Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
    – Matt Schuchard
    Nov 8 at 13:37












  • What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
    – Joerg S
    Nov 10 at 10:31










  • @I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
    – Aleks G
    Nov 12 at 11:28















up vote
1
down vote

favorite












There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS doesn't seem to work. Here's the relevant piece of the code:



@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()

withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}

connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true

if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}

connection.connect();

def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}

return connection.content.text
}


Note that it does have @NonCPS on the function. However executing this still produces the same error:



an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...


How can I solve it?










share|improve this question






















  • Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
    – Matt Schuchard
    Nov 8 at 13:37












  • What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
    – Joerg S
    Nov 10 at 10:31










  • @I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
    – Aleks G
    Nov 12 at 11:28













up vote
1
down vote

favorite









up vote
1
down vote

favorite











There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS doesn't seem to work. Here's the relevant piece of the code:



@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()

withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}

connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true

if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}

connection.connect();

def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}

return connection.content.text
}


Note that it does have @NonCPS on the function. However executing this still produces the same error:



an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...


How can I solve it?










share|improve this question













There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS doesn't seem to work. Here's the relevant piece of the code:



@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()

withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}

connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true

if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}

connection.connect();

def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}

return connection.content.text
}


Note that it does have @NonCPS on the function. However executing this still produces the same error:



an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...


How can I solve it?







jenkins jenkins-pipeline






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 10:31









Aleks G

41.8k18120188




41.8k18120188












  • Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
    – Matt Schuchard
    Nov 8 at 13:37












  • What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
    – Joerg S
    Nov 10 at 10:31










  • @I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
    – Aleks G
    Nov 12 at 11:28


















  • Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
    – Matt Schuchard
    Nov 8 at 13:37












  • What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
    – Joerg S
    Nov 10 at 10:31










  • @I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
    – Aleks G
    Nov 12 at 11:28
















Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
– Matt Schuchard
Nov 8 at 13:37






Marking the method as @NonCPS would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection(), which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
– Matt Schuchard
Nov 8 at 13:37














What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31




What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31












@I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28




@I don't think calling code has anything to do with it, as the stacktrace points to HTTPUrlConnection class. In any event, an example calling code would be def result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205882%2fjava-io-notserializableexception-sun-net-www-protocol-https-httpsurlconnectioni%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205882%2fjava-io-notserializableexception-sun-net-www-protocol-https-httpsurlconnectioni%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check