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

Add related fixes for PDFBox bump #12251

Open
wants to merge 1 commit into
base: 4.3.0-dependency-bumps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/apimgt/org.wso2.carbon.apimgt.impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,14 @@
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.custom.lifecycles.checklist</artifactId>
</dependency>

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupId should be org.wso2.orbit.org.apache.pdfbox

<artifactId>pdfbox-io</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.lcm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.cos.COSDocument;
Expand Down Expand Up @@ -182,9 +182,9 @@ private String fetchDocumentContent(Registry registry, Resource documentResource
inputStream = contentResource.getContentStream();
switch (extension) {
case APIConstants.PDF_EXTENSION:
PDFParser pdfParser = new PDFParser(new RandomAccessBufferedFileInputStream(inputStream));
PDFParser pdfParser = new PDFParser(new RandomAccessReadBuffer(inputStream));
pdfParser.parse();
COSDocument cosDocument = pdfParser.getDocument();
COSDocument cosDocument = pdfParser.parse().getDocument();
PDFTextStripper stripper = new PDFTextStripper();
contentString = stripper.getText(new PDDocument(cosDocument));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.pdfbox.cos.COSDocument;
Expand All @@ -30,7 +30,7 @@ public IndexDocument getIndexedDocument(File2Index fileData) throws SolrExceptio
try {
PDFParser parser = getPdfParser(fileData);
parser.parse();
cosDoc = parser.getDocument();
cosDoc = parser.parse().getDocument();

PDFTextStripper stripper = getPdfTextStripper();
String docText = stripper.getText(new PDDocument(cosDoc));
Expand Down Expand Up @@ -70,7 +70,7 @@ protected PDFTextStripper getPdfTextStripper() throws IOException {
}

protected PDFParser getPdfParser(File2Index fileData) throws IOException {
return new PDFParser(new RandomAccessBufferedFileInputStream(new ByteArrayInputStream(fileData.data)));
return new PDFParser(new RandomAccessReadBuffer(new ByteArrayInputStream(fileData.data)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ public void testShouldReturnIndexedDocumentWhenParameterCorrect() throws IOExcep
String mediaType = "application/pdf+test";
final String MEDIA_TYPE = "mediaType";
PDFParser parser = Mockito.mock(PDFParser.class);
PDDocument pdDocument = Mockito.mock(PDDocument.class);
COSDocument cosDoc = Mockito.mock(COSDocument.class);
PDFTextStripper pdfTextStripper = Mockito.mock(PDFTextStripper.class);
Mockito.doThrow(IOException.class).when(cosDoc).close();
Mockito.when(parser.getDocument()).thenReturn(new COSDocument()).thenReturn(cosDoc);
Mockito.when(parser.parse()).thenReturn(new PDDocument());

Mockito.when(pdDocument.getDocument()).thenReturn(new COSDocument()).thenReturn(cosDoc);
Mockito.when(pdfTextStripper.getText(new PDDocument())).thenReturn("");
PDFIndexer pdfIndexer = new PDFIndexerWrapper(parser, pdfTextStripper);

Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,12 @@
<version>${pdfbox.version}</version>
</dependency>

<dependency>
<groupId>org.apache.pdfbox</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupid should be org.wso2.orbit.org.apache.pdfbox

<artifactId>pdfbox-io</artifactId>
<version>${pdfbox.version}</version>
</dependency>

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
Expand Down Expand Up @@ -2140,7 +2146,7 @@

<carbon.metrics.version>1.3.12</carbon.metrics.version>
<!-- apache pdfbox version -->
<pdfbox.version>2.0.25</pdfbox.version>
<pdfbox.version>3.0.1</pdfbox.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add a separate entry for pdfbox-io version (3.0.1.wso2v1) and change the imports accordingly

<event.processor.stub.version>2.3.5</event.processor.stub.version>
<event.processor.core.version>2.3.5</event.processor.core.version>
<swagger.inflector.version>1.0.16.wso2v1</swagger.inflector.version>
Expand Down