Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to confluence gives response 400 on version 3.2.0 #1330

Closed
adriansuciu09 opened this issue Jan 8, 2024 · 21 comments · Fixed by #1333
Closed

Publish to confluence gives response 400 on version 3.2.0 #1330

adriansuciu09 opened this issue Jan 8, 2024 · 21 comments · Fixed by #1333

Comments

@adriansuciu09
Copy link

After changing over to doctoolchain v3.2.0 from v3.1.2, I cannot publish anything to confluence.
Here is the Error message:
doctoolchain
Here is my confluence.with{} within the Config.groovy file:
grafik
If i change back to v3.1.2, everything works again.

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 9, 2024

Thanks, this is a bug and was introduced in #1306 I think it only occurs in situations where the content excerpt is not well-formatted HTML, which is the case for eg if you use Arc42 template. I will try to implement a fix soon. Thanks for reporting! cc @faltfe i think you are in the very same situation, thanks for letting us know!

@adriansuciu09
Copy link
Author

I still get an error, after updating to 3.2.1. This time, an 404 error.
grafik

@faltfe
Copy link
Contributor

faltfe commented Jan 11, 2024

I cannot confirm the behaviour. The upload and creation of pages is working with 3.2.1.

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 11, 2024

could you please share more insights via adding the output of the command with --stacktrace

@PacoVK PacoVK reopened this Jan 11, 2024
@maksymgendin
Copy link

maksymgendin commented Jan 11, 2024

This HTTP 404 could be related to my issue #1332, which happened also in 3.2.0. I didn't try 3.2.1 yet.

@adriansuciu09
Copy link
Author

This is the --stacktrace error output
grafik
grafik
grafik
grafik
grafik

@maksymgendin
Copy link

I would suggest to run with --debug and to check the HTTP wire logs. If you see there a double base path prefix on HTTP POST request (creating attachment) like /confluence/rest/api//confluence/rest/api/content/47260738/child/attachment then the issue reported by #1332 ist NOT fixed in DTC version 3.2.1.

@adriansuciu09
Copy link
Author

I checked the http wire logs, there is no double base

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 11, 2024

The error is 404 not found and from the logs we can see it's propably the GET attachment. I'll take a deeper look later, but maybe the bug is that we fail if the attachment is not there, we should just create it then (but thats now guessing without validation)

@adriansuciu09
Copy link
Author

Initially i changed to 3.2.0 beause i wanted to have subpages without linebreaks. After upgrading to 3.2.0, from 3.1.2 I tried the publish to confluence once (without changes in my adoc and Config.groovy), and got no error (maybe because the pages were already there, from v3.1.2). It was only after I tried to publish with subpages higher than 1, that i got the error. Then, I deleted the confluence pages to try again with subpages=1, but got the 404 error again. So it is possible that the pages missing is the problem

@adriansuciu09
Copy link
Author

adriansuciu09 commented Jan 11, 2024

Ok, I went back to 3.1.2, created the confluence pages with subpage=2 (the version where the linebreaks are broken). Then upgraded to 3.2.1 and published to confluence again. Got no errors, and this fixed the broken linebreaks in the code snippets. I think it is how you said, the confluence step fails if the pages do not exist.

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 11, 2024

Alright i think i have a solution, we could give it a try as soon as #1337 gets merged, would you mind to verify and use docToolchain latest?

@adriansuciu09
Copy link
Author

I tried doctoolchain latest and got the following error:
grafik

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 12, 2024

could you please share a bit more information? at least Stacktrace, that shows the responseCode would be really helpful to get a direction to investigate :)
And i understood this occures if you set subpage > than 1

@adriansuciu09
Copy link
Author

Im sorry, here is the error with --stacktrace. I get the same error regardless of subpage being > or < 1.
grafik
grafik
grafik
grafik
grafik

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 15, 2024

@adriansuciu09 thanks for the input, although i am struggeling quite a lot to reproduce. The error indicates that the HTTP entity cannot be consumed properly. I created #1341 to ensure proper consumption in any case.

@adriansuciu09
Copy link
Author

@PacoVK thank you, i will give it a try when it merges :)

@adriansuciu09
Copy link
Author

@PacoVK works like a charm. Pages were created and everything works as expected (even subages > 1). Thanks a lot

@PacoVK
Copy link
Collaborator

PacoVK commented Jan 16, 2024

Thanks, for the feedback :) I will take care to create a release soon

@arutscheidt
Copy link

Is there any update?
I have the 404 Error with 3.2.2

Here is my file tree (image links modified)
grafik

Here is the contents.adoc

:imagesdir: images
:jbake-menu: -

// configure DE settings for asciidoc
include::chapters/config.adoc[]

// toc-title definition MUST follow document title without blank line!
:toc-title: Inhaltsverzeichnis

// Dokumentenhistorie
include::chapters/00_document_history.adoc[]

// numbering from here on
:numbered:

// 1. Anforderungen und Ziele
// include::chapters/01_introduction_and_goals.adoc[]

The 00_document_history.adoc

// :jbake-title: Dokumentenhistorie
// :jbake-type: page_toc
// :jbake-status: published
// :jbake-menu: arc42
// :jbake-order: 0
// :filename: /chapters/00_document_history.adoc
// ifndef::imagesdir[:imagesdir: images]
// :hardbreaks-option:

// :source-highlighter: highlight.js
// :highlightjs-languages: asciidoc 

[#section-document-history]
== Dokumentenhistorie
Some Testtext

[cols="~,~,~,~a"]
|===
|Version|Datum|Autor|Änderungsnotizen

|0.1|20.12.2023|ARu|Neustart der arc42 Dokumentation

- Übernahme der arc42-Template-Kapitel aus der alten Version
- Leeren der Inhalte für den Neustart
- Schrittweises Übertragen und Anpassen alter Inhalte, sofern noch gültig
- Verwendung einer aktuellen dochToolChain-Version
|===

//====================
// Footer
//====================
// Force legacy editor
// ++++
// <style></style>
// ++++

And my groovy (censored)

outputPath = 'build'

// If you want to use the Antora integration, set this to true.
// This requires your project to be setup as Antora module.
// You can use `downloadTemplate` task to bootstrap your project.
//useAntoraIntegration = false

// Path where the docToolchain will search for the input files.
// This path is appended to the docDir property specified in gradle.properties
// or in the command line, and therefore must be relative to it.

inputPath = './';

// the pdfThemeDir config in this file is outdated.
// please check http://doctoolchain.org/docToolchain/v2.0.x/020_tutorial/030_generateHTML.html#_pdf_style for further details
// pdfThemeDir = './src/docs/pdfTheme'

inputFiles = [
	    [file: 'contents.adoc', formats: ['html','pdf']],
]

//folders in which asciidoc will find images.
//these will be copied as resources to ./images
//folders are relative to inputPath
// Hint: If you define an imagepath in your documents like
// :imagesdir: ./whatsoever
// define it conditional like
// ifndef::imagesdir[:imagesdir: ./whatsoever]
// as doctoolchain defines :imagesdir: during generation
imageDirs = [
    'images',
]

// whether the build should fail when detecting broken image references
// if this config is set to true all images will be embedded
failOnMissingImages = true

// these are directories (dirs) and files which Gradle monitors for a change
// in order to decide if the docs have to be re-build
taskInputsDirs = [
                    "${inputPath}",
//                  "${inputPath}/src",
//                  "${inputPath}/images",
                 ]

taskInputsFiles = []

...

confluence.with {
    input = [
            [ file: "build/html5/contents.html" ],
    ]

    // endpoint of the confluenceAPI (REST) to be used
    // if you use Confluence Cloud, you can set this value to
    // https://[yourServer]
    // a working example is https://arc42-template.atlassian.net
    // if you use Confluence Server, you may need to set a context:
    // https://[yourServer]/[context]
    // a working example is https://arc42-template.atlassian.net/wiki
    api = 'https://CENSORED.atlassian.net/'

    // requests per second for confluence API calls
    //rateLimit = 10

    // if true API V1 only will be used. Default is true.
    //useV1Api = false

    // if true, the new editor v2 will be used. Default is false.
    // enforceNewEditor = false

    //    Additionally, spaceKey, subpagesForSections, pagePrefix and pageSuffix can be globally defined here. The assignment in the input array has precedence

    // the key of the confluence space to write to
    spaceKey = 'CENSORED'
    ancestorId = '123456'

    // if true, all pages will be created using the new editor v2
    // enforceNewEditor = false

    // variable to determine how many layers of sub pages should be created
    subpagesForSections = 1

    // the pagePrefix will be a prefix for each page title
    // use this if you only have access to one confluence space but need to store several
    // pages with the same title - a different pagePrefix will make them unique
    pagePrefix = '[CENSORED] - '

    pageSuffix = ''

    // the comment used for the page version
    pageVersionComment = ''

    /*
    WARNING: It is strongly recommended to store credentials securely instead of commiting plain text values to your git repository!!!

    Tool expects credentials that belong to an account which has the right permissions to to create and edit confluence pages in the given space.
    Credentials can be used in a form of:
     - passed parameters when calling script (-PconfluenceUser=myUsername -PconfluencePass=myPassword) which can be fetched as a secrets on CI/CD or
     - gradle variables set through gradle properties (uses the 'confluenceUser' and 'confluencePass' keys)
    Often, same credentials are used for Jira & Confluence, in which case it is recommended to pass CLI parameters for both entities as
    -Pusername=myUser -Ppassword=myPassword
    */

    //optional API-token to be added in case the credentials are needed for user and password exchange.
    //apikey = "[API-token]"

    // HTML Content that will be included with every page published
    // directly after the TOC. If left empty no additional content will be
    // added
    // extraPageContent = '<ac:structured-macro ac:name="warning"><ac:parameter ac:name="title" /><ac:rich-text-body>This is a generated page, do not edit!</ac:rich-text-body></ac:structured-macro>
    extraPageContent = ''

    // enable or disable attachment uploads for local file references
    enableAttachments = false

    // variable to limit number of pages retreived per REST-API call
    pageLimit = 100

    // default attachmentPrefix = attachment - All files to attach will require to be linked inside the document.
    // attachmentPrefix = "attachment"


    // Optional proxy configuration, only used to access Confluence
    // schema supports http and https
    // proxy = [host: 'my.proxy.com', port: 1234, schema: 'http']

    // Optional: specify which Confluence OpenAPI Macro should be used to render OpenAPI definitions
    // possible values: ["confluence-open-api", "open-api", true]. true is the same as "confluence-open-api" for backward compatibility
    // useOpenapiMacro = "confluence-open-api"

    // for exportConfluence-Task
    export = [
        srcDir: 'sample_data',
        destDir: './'
    ]

So you see there is nothing special about my code.

Idea:

Maybe this has sth to do with the API V1 cancelled by atlassian this year?
see first block

Adrian has set UseV1Api = true.
But I have set it to false and have the same error. verifyConfluenceApiAccess works with the same credentials.

@PacoVK
Copy link
Collaborator

PacoVK commented Feb 19, 2024

@arutscheidt thanks for bringing this up again. To get more infos about the 404 could you please be so kind and

  • open an issue describing your issue (link to this closes PR is also fine), a new issue is simpler to track than using closed PRs. We solved the initial issue with this PR sucessfully, hence i assume your issue is related to something else.
  • share the actual error in the issue?
  • run the task with --stacktrace and send the relevant stacktrace in the issue?
    based on that we can proceed to investigate what causes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants