cancel
Showing results for 
Search instead for 
Did you mean: 

issue with PDF upload to sharepoint

GauravKant
Contributor
0 Kudos

Dear Experts,

I have a file to sharepoint integration in which i need to upload PDF files to share point folder in base64 format.

I have done java mapping for base64 conversion but post conversion and upload, file is getting blank at sharepoint folder.

Assuming that the issue is with base64 conversion and file is corrupted post conversion as file size is same as processed file at sharepoint.

Please suggest on this.

Thanks in Advance!! 🙂

PS: I have tested the same using SOAPUI and are able to upload PDF file with file content.

I have inserted file using insert file as base64 option in SOAPUI.

Regards,

Gaurav

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Kudos

Hi Gaurav!

package com.evk.java.train;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.bind.DatatypeConverter;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class BuildXMLWithBase64 extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out)throws StreamTransformationException {
executeMapping(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}

public void executeMapping(InputStream in, OutputStream out) throws StreamTransformationException {
String xmlString = "";
String XML_START_TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
XML_START_TAG += "<ns:UploadPlainDocumentWithFolder xmlns:ns=\"http://schemas.abc.com/xyz/2010/11\">";
String XML_END_TAG = "</ns:UploadPlainDocumentWithFolder>";

xmlString = xmlString + XML_START_TAG + "<PlainDoc><DocumentName>" + "YourDocName" + "</DocumentName>";
xmlString += "<DocumentURL>" + "http://yourURL" + "</DocumentURL>";

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
int nRead;
byte[] data = new byte[16384];
while ((nRead = in.read(data, 0, data.length)) != -1)
  buffer.write(data, 0, nRead);
buffer.flush();
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}

xmlString += "<DocumentBytes>" + DatatypeConverter.printBase64Binary(buffer.toByteArray()) + "</DocumentBytes></PlainDoc>";
xmlString += "<DocLibURL>http://xyz</DocLibURL><ApplicationId>APPL_ID</ApplicationId><UserId>USR_ID</UserId>" + XML_END_TAG;

try {
out.write(xmlString.getBytes("UTF-8"));
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}

public static void main(String[] args) {
try {
FileInputStream inFile = new FileInputStream("C:\\Tests\\FCC_01.png");
FileOutputStream outFile = new FileOutputStream("C:\\Tests\\FCC_01_out.xml");
BuildXMLWithBase64 mapper = new BuildXMLWithBase64();
mapper.executeMapping(inFile, outFile);

outFile.flush();
outFile.close();
}
catch (Exception e) {
e.printStackTrace();
}
}

}

Output:

Regards, Evgeniy.

GauravKant
Contributor

Hi Evgeniy,

Thank you so much. It has solved my problem of base64 conversion.

I really appreciate your insights, and am looking forward to implementing many of your suggestions.

Regards,

Gaurav

Answers (2)

Answers (2)

Andrzej_Filusz
Contributor
0 Kudos

Hi Gaurav,

Are you sure that your Base64 class has the correct implementation? Does it come from a trusted source, like a standard SDK or Apache libraries?

For example: org.apache.xml.security.utils.Base64;

Regards,

Andrzej

GauravKant
Contributor
0 Kudos

Hi Andrzej,

Thanks!!

I have tried with below jars which belong to itextpdf-5.4.1.jar, com.sap.aii.utilxi.core.jar, java-util-1.3.1.jar respectively.

com.itextpdf.text.pdf.codec.Base64;

com.sap.aii.utilxi.base64.api.Base64;

com.oschrenk.io.Base64;

Regards,

Gaurav

Andrzej_Filusz
Contributor
0 Kudos

Hi Gaurav,

I think you should make sure that you've got a problem with Base64 encoding in your java mapping class.

Please download your message (after mapping) to your disk, remove the XML part - leave only Base64 content, decode it using Notepad++ (for example), save to disk and finally compare it with the source PDF file by contents (using Total Commander for example). Are they identical?

Regards,

Andrzej

GauravKant
Contributor
0 Kudos

Hi Andrzej,

Thanks !!

I will try and update on this.

Regards,

Gaurav

GauravKant
Contributor
0 Kudos

Hi Andrzej,

I tried with PI base64 content using notepad++ it is getting blank post Base64 decode and saving on disk.

I tried same with SOAPUI content and i am able to see the data post decode and saving on disk.

Regards,

Gaurav

Andrzej_Filusz
Contributor

Hi Gaurav,

Please try to use the Base64 class from Apache libraries (you can take it from lib folder of your SoapUI as Manoj suggested, your version can be different):

xmlsec-1.4.5.jar 
org.apache.xml.security.utils.Base64 
commons-codec-1.3.jar 
org.apache.commons.codec.binary.Base64

If you would still have a problem with a proper Base64 encoding, then please provide your java mapping code. Maybe there is something wrong with it.

Regards,

Andrzej

former_member190293
Active Contributor
0 Kudos

In addition to Andrzej: did you test your mapping in IDE? Can you confirm that your java code works as required? If no, this means that your code is incorrect. Provide us your java code example.

P.S. I usually use javax.xml.bind.DatatypeConverter class for Base64 encoding/decoding and have no issues.

Regards, Evgeniy.

GauravKant
Contributor
0 Kudos

Hi Evgeniy, Andrzej,

PFB code example using for base 64 conversion.

Code:

import java.io.*; //import com.oschrenk.io.Base64; import com.itextpdf.text.pdf.codec.Base64; import com.sap.aii.mapping.api.*; //import com.sap.aii.utilxi.base64.api.Base64; import org.apache.commons.codec.binary.Base64;

public class base64Conversion extends AbstractTransformation { public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {

try {

String targetxml1 =""; String line =""; String source="";

InputStream ins = in.getInputPayload().getInputStream();

BufferedReader br = new BufferedReader( new InputStreamReader(ins));

String XML_START_TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns:UploadPlainDocumentWithFolderxmlns:ns=\"http://schemas.abc.com/xyz/2010/11\">";

String XML_END_TAG = "</ns:UploadPlainDocumentWithFolder>";

targetxml1 = XML_START_TAG+ "<ns:PlainDoc>"+ "<ns:DocumentName>abc.pdf</ns:DocumentName>"+ "<ns:DocumentURL>http://xyz</ns:DocumentURL>" + "<ns:DocumentBytes>";

String targetxml2="</ns:DocumentBytes>" + "</ns:PlainDoc>" + "<ns:DocLibURL>http://xyz</ns:DocLibURL>" + "<ns:ApplicationId>xyz</ns:ApplicationId>" + "<ns:UserId>gaurav</ns:UserId>" + XML_END_TAG;

String base64="";

out.getOutputPayload().getOutputStream().write(targetxml1.getBytes("UTF-8"));

line = br.readLine();

while (line != null)

{ source +=line;

//byte[] str=source.getBytes();

base64=Base64.encodeBytes(source.getBytes());

line=br.readLine();

}

br.close();

out.getOutputPayload().getOutputStream().write(base64.getBytes("UTF-8")); out.getOutputPayload().getOutputStream().write(targetxml2.getBytes("UTF-8"));

}

catch (Exception e) { throw new StreamTransformationException(e.getMessage()); } } }

tags: PFB start and end tags as it is not appearing correctly in code post upload.

Structure for uploading:

Please correct/update if anything wrong with the code...

Thanks alot in advance!!

Regards,

Gaurav

manoj_khavatkopp
Active Contributor
0 Kudos

Gaurav,

Have you tried comparing the RAW data being sent from SOAP UI with the content being sent from PI after execution of soap channel using TraceHTTP ?Do you see any difference in them ?

Br,

Manoj

GauravKant
Contributor
0 Kudos

Hi Manoj,

Thanks!!

Yes, PI base64 data is different from SOAPUI. I tried with many below base64 jars but all are giving different values post conversion.

com.oschrenk.io.Base64;

com.itextpdf.text.pdf.codec.Base64;

com.sap.aii.utilxi.base64.api.Base64;

Could you please guide me on this?

Regards,

Gaurav

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Gaurav,

Have you tried encrypting using Commons-code.jar ,

Because i believe this is the one which SOAP UI uses for encoding and decoding.

Br,

Manoj

GauravKant
Contributor
0 Kudos

Hi Manoj,

Thanks!!

I will try with this jar and update.

Regards,

Gaurav

GauravKant
Contributor
0 Kudos

Hi Manoj,

I tried with Commons-code-1.3.jar but still getting blank file after processing to SharePoint.

Regards,

Gaurav