Skip to content

Commit

Permalink
Fix stackoverflow feil (#533)
Browse files Browse the repository at this point in the history
* Fix stackoverflow feil

* Fix stackoverflow feil
  • Loading branch information
ugur93 authored Nov 3, 2023
1 parent e47743b commit 44870f7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/deploy_feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
- '**'
- '!main'
- '!dependabot/**'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build_and_deploy:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ on:
pull_request:
types: [ ready_for_review, opened, synchronize ]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build_and_deploy:
name: "Build and deploy to main"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ on:
push:
branches:
- 'main'
env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build_and_deploy:
name: "Build and deploy to feature"
name: "Build and deploy to prod"
permissions:
contents: "write"
id-token: "write"
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/rollback_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
description: 'Deploy tag. Default the previous tag will be deployed'
required: false

env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build-deploy:
name: "Rollback and deploy previous version to prod"
Expand All @@ -19,4 +15,5 @@ jobs:
uses: navikt/bidrag-workflow/.github/workflows/rollback_prod.yaml@main
secrets: inherit
with:
cluster: fss
cluster: fss
deploy_tag: ${{inputs.deploy_tag}}
20 changes: 0 additions & 20 deletions src/main/java/no/nav/bidrag/dokument/aop/AspectExceptionLogger.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream
import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode
import org.apache.pdfbox.pdmodel.common.PDRectangle
import org.apache.pdfbox.util.Matrix
import org.slf4j.LoggerFactory
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileInputStream
Expand Down Expand Up @@ -48,21 +47,34 @@ class PDFDokumentProcessor {
optimaliserForDobbelsidigPrinting()
}
this.document?.isAllSecurityToBeRemoved = true
this.document?.save(documentByteStream)
this.document?.close()
lagreDokument(documentByteStream)
return documentByteStream.toByteArray()
}
} catch (e: Exception) {
LOGGER.error("Det skjedde en feil ved prossesering av PDF dokument", e)
log.error(e) { "Det skjedde en feil ved prossesering av PDF dokument" }
return dokumentFil
} catch (e: StackOverflowError) {
log.error(e) { "Det skjedde en feil ved prossesering av PDF dokument" }
return dokumentFil
} finally {
IOUtils.closeQuietly(documentByteStream)
}
}

private fun lagreDokument(documentByteStream: ByteArrayOutputStream) {
try {
this.document?.save(documentByteStream)
} catch (error: StackOverflowError) {
log.error(error) { "Det skjedde en feil ved lagring av dokument med kompresjon. Forsøker å merge dokumenter uten kompresjon" }
this.document?.save(documentByteStream, CompressParameters.NO_COMPRESSION)
} finally {
this.document?.close()
}
}

fun optimaliserForDobbelsidigPrinting() {
if (documentHasOddNumberOfPages() && documentProperties!!.hasMoreThanOneDocument() && !documentProperties!!.isLastDocument()) {
LOGGER.debug("Dokumentet har oddetall antall sider. Legger til en blank side på slutten av dokumentet.")
log.debug("Dokumentet har oddetall antall sider. Legger til en blank side på slutten av dokumentet.")
document?.addPage(PDPage(PDRectangle.A4))
}
}
Expand Down Expand Up @@ -91,7 +103,7 @@ class PDFDokumentProcessor {

@Throws(IOException::class)
private fun konverterAlleSiderTilA4() {
LOGGER.debug(
log.debug(
"Konverterer {} sider til A4 størrelse. Filstørrelse {}",
document!!.numberOfPages,
bytesIntoHumanReadable(
Expand Down Expand Up @@ -149,9 +161,6 @@ class PDFDokumentProcessor {
}

companion object {
private val LOGGER = LoggerFactory.getLogger(
PDFDokumentProcessor::class.java,
)

@Throws(IOException::class)
fun fileToByte(file: File): ByteArray {
Expand Down Expand Up @@ -215,8 +224,14 @@ class PDFDokumentMerger {
private fun executeMerge(mergedDocument: PDFMergerUtility) {
try {
mergedDocument.mergeDocuments(MemoryUsageSetting.setupTempFileOnly().streamCache)
} catch (e: StackOverflowError) {
log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten kompresjon" }
mergedDocument.mergeDocuments(
MemoryUsageSetting.setupTempFileOnly().streamCache,
CompressParameters.NO_COMPRESSION
)
} catch (e: Exception) {
log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten komprimering" }
log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten kompresjon" }
mergedDocument.mergeDocuments(
MemoryUsageSetting.setupTempFileOnly().streamCache,
CompressParameters.NO_COMPRESSION
Expand Down

0 comments on commit 44870f7

Please sign in to comment.