I am trying to upload an excel file from a DSP page and then parse the file using Apache POI jars and insert the data in DB. The issue is the excel content is not getting passed to the IS service from the DSP page. Below is the DSP code.
The issue is primarily resolved. The data is coming to the flow service from browser. However , the InputStream data is getting corrupted during transfer.
This is mainly happening for excel files. The code works fine for pdf,txt,jpg files. Anyone if you have faced this please share your inputs on this.
Well I have tried this one also. When I am doing a http post using “pub.client:http” by passing the excel file , it is working file , the excel is getting successfully written in the receiver server and I am able to open the file. The issue is when I use the HTML page to pass the file to the receiver server. I even added the below mime type in the settings (Resources>Mime Types), still the InputStream gets corrputed. Sending from browser seems to be the issue. The same dsp successfully uploads pdf,txt,jpg files , but not xlsx.
as trying to point out earlier, Excel (xslx) files might contain characters which cause the stream to get closed during transmission before the file is complete.
the problem is not with the visible data you enter in the Excel file, instead it is intrinsic caused by th fiile format xlax.
When opening the file with an editor which can display control charactes (like Notepad++) you will see the culprit.
There are some control characters among them which cause the stream to be closed before the file is transferred completey.
Is there any workaround/solution for this? As the scenario is working fine when I am using pub.client:http service to send the data. Only when browser is involved , I am seeing this issue and that too for excel files. For pdf , txt ,jpg its working absolutely fine. Is there any content-type/content-handler setting that I can do to correct this?
As I have been searching for this … and I couldn’t find good solution - I’ll give you my example.
The DSP page:
Choose file:
The webMethods part:
pub.flow:getTransportInfo
pub.mime:mergeHeaderAndBody
map contentStream to body/stream and transport/http/requestHdrs to headerLines
pub.mime:createMimeData
map stream to input
pub.mime:getNumParts
pub.mime:getBodyPartHeader
from there you can take mimeHeader/Content-Disposition and parse it to get file name
pub.mime:getBodyPartContent
index 0 will give you content of the file
write steam into the file. That I’ve written in Java.
Java service:
String fileName = IDataUtil.getString( pipeline.getCursor(), “filename” );
InputStream in = (InputStream) IDataUtil.get( pipeline.getCursor(), “data” );
// pipeline
try {
OutputStream out = new FileOutputStream(fileName);
// Transfer bytes from in to out
byte buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
catch (Exception e) {throw new ServiceException(e);}