File Upload - How to ?

Sorry, for creating a separate thread for this discussion.

I did performed a search for ContentHandler and ‘multipart/form-data’ but couldnt find anything which really explains what exactly needs to be done to achieve a fileUpload task in wM65.

I have an HTML form with the enctype=‘multipart/form-data’ and with one of the input field as ‘file’ type.

When I submit the form on this dsp page, the receiving flow service on my IS receives this in the pipeline:

VTTest "uploadFile"; filename="C:\Documents and Settings\A17L2ZZ\Desktop\Support\Alloc_QA.txt" Content-Type: text/plain EDI_DOC_ID nvarchar(255) ORTG_LOC_CODE nvarchar(10) NULL

My Questions are:

  1. does this output indicates that the IS have the right ContentHandler already loaded to parse the form data?
  2. If yes, how to extract the contents from the selected file? Are there specific I/p signatures for the receive service?

Please advice…your help is much appreciated.

Thank you,

[url]wmusers.com

Thanks Reamon for directing me to an existing thread…

Unfortunately, I have already gone through the steps defined in that discussion but somehow it isnt working for me!

As suggested in that thread, I did created the same record layout as part of the I/p signatures of my receiving service but this I/p is partially populated ONLY in case if I DONT use the ‘multipart/form-data’.

If I specify the form enctype='‘multipart/form-data’ this I/p document is not populated at all and all I see is what I showed below (content-disposition etc)

Please advice.

Do you have the content handler indicated from the thread loaded on IS?

Not sure, how to check that & to answer your question.

But, within the receiving flow service, I have a call to getTransportInfo and its showing me that the content-type is multipart/form-data:

multipart/form-data; boundary=---------------------------7d929f245f07cc

Is that what you are looking for?

You may have already done this, but try using a savePipeline (not savePipelineToFile as it won’t save non-streamable items) in your service to see what’s there.

Thanks Reamon for being with me on this issue…

Yes, I did used the savePipeline (& restorePipeline later) and attached is what I see. Still I’m not able to get the I/p document populated with values.

Please help me out on how to receive & extract the file contents.

Thanks much for your help!
UploadReceive.jpg

It looks like it is using the default content handler since it is busting things up into name/value pairs. I think the right step at this point is to apply the content handler to IS as described in the other thread.

I finally tried writing my own Multipart ContentHandler, but somehow while I’m trying to register this ConentHandler, the IS is throwing nullPointerException() in the error logs.

This is what I have done so far:

  1. Wrote the ContentHandler class (attached)
  2. Wrote the ContentHandlerfactory class (attached)
  3. Created 2 separate java services for start & shutdown of the contentHandler.
  4. Setup these java services as the startup/shtudown services for the package.
  5. Everything gets complied fine.

Now, while reloading the package I do see a NullPointerException in the error log and my custom handler isnot working?

Any inputs are greatly appreciated.
BTBIContentHandlerFactory_MultiPart_java.txt (307 Bytes)
BTBIContentHandler_MultiPart_java.txt (2.65 KB)

Did you also register that custom handler in the IntegrationServer\lib\mime.types config file and restarted IS?

HTH,
RMG

Yes, I did that too, but dint help.
I added some more error logging and this is what I see in the IS error logs:

com.wm.app.b2b.server.mon.ISMException: Error occurred while invoking a service : null
wm.server.packages:packageInfo java.lang.NullPointerException

No clue what is causing this…

More update:

I guess the NullPointerException is harmless and can be ignored the custom contenthandler still gets registered successfully regardless of this error.

I did tested it with multiple scenarios - first by writing a test java service and calling
ContentHandler handler = ServerAPI.getContentHandler(“multipart/form-data”);
printed the object reference in server logs and it does shows a valid object which is referencing to the custome CH in my package…so things looks good under this basic test.

Next, as 2nd test, I wrote a flow to simulate the real HTML call- with a pub.client.http that calls another flow service (same IS) which receives multipart-contents and process it.
I explicitly set the content-type for the http call to ‘multipart/form-data’ to see if the IS calls my CH. And yes, my custom handler did get called and went till a point before it err-out…here are some logs

create() called…
Factory constructor called…
Inside getValues(). Content-Type = multipart/form-data
Exception occured during getInputValues() javax.mail.MessagingException: Missing start boundary
ContentHandler putInputValues() called…

Now, in real time, when I’m trying to submit a file using my HTML form with encType=‘multipart/form-data’ I dont see any of above logs, which makes me think that the IS is not able to recognize the contentType of the incoming request…not sure why???

Also, I have a getTransportInfo in my receive service and that shows the Content-Type as ‘multipart/form-data; boundary=---------------------------7d9781330b6e’.

Any ideas here… looks like so close but tooo far…Please help!

Well guys, finally I got success coming my way!!! :slight_smile:

I will explain the exact steps in my next post.

Thanks to everyone who provided their support during my research

For the benefit of this great community, here is a summary of my learning:

Essentially, the below thread very well summarizes and explains the whole procedure of processing the ‘multipart/form-data’ contents:
[URL=“wmusers.com”][COLOR=#22229c]wmusers.com

The only thing which is not very clear is how to determine the success of each step, specifically step 1.
You could determine the content handler for each type in your IS by writing a java service:

ContentHandler handler = ServerAPI.getContentHandler(“multipart/form-data”);

and print the ‘handler’ to your server logs.
This will help you identify if at all there is a multpart CH registered already in the IS, if yes, which package it is referring to.

Also, the WmBrokerAdmin package does have the Multipart CH which will get enabled ONLY after you access the BrokerAdmin UI. Merely installing the BroekrAdmin package wont enable the CH, you need to access the UI to get it enabled.

Hope all this info will help!

Can someone please shed some light on this topic? The wmUser forum is down and has not been migrated here so I cannot access the links mentioned above.

I need to upload file from a DSP page. So far, I have created:

  1. a DSP page with form that sends data to upload.dsp page
  2. upload.dsp page that calls IS service to handle the file

I can see in the pipeline name of the file, but content is missing.

  1. I have created and registered MultipartContentHandler and added it to startUp service
  2. I have reloaded package, but I still do not see any change

Is there anything else (register the handler / restart IS) necessary to handle the uploaded file???

You can try search on the Wmusers topics (all threads have been migrated) in this forum try the search functionality on each section:

HTH,
RMG

I did search the forums but I have not found the solution yet.

I was able to register custom content handler in a startup service and I see a log entry when the constructor is called. When I create new instance of ContentHandler in a java service I see a log entry as well.

When I call in a java service ServerAPI.getContentHandler(“multipart/form-data”).getClass().getName() I do see class name of my content handler.

But when I upload a file from one DSP page to another, I do not see any entry in the server log => the content handler is not called at all. However I do see content in pipeline. But the content is incorrectly parsed and I cannot use it.

Moreover, when I make a change in the DSP page. First three times I get sever error “java.lang.IllegalArgumentException: Data key is null”. After that I see content in pipeline, but it is messed up and unusable.

Finally resolved :lol: The problem was, that I post the file to another dsp page which consequently called a flow service for processing the uploaded file.

Now, the post action of the form points directly to the flow service URL and it finally works. And I don’t need to use any custom content handler at all.