Java Convert XML to bytearray, split, send through Websphere MQ and merge - java

We need to upload and process XML files. I convert them to bytearray and send through Websphere MQ/Spring JMS and process the file in the backend application server. The Websphere MQ has a message size limit of 2MB. We don't have control over that. Please recommend an efficient way to split the file/bytearray and have them assembled/merged in the datazone.
Is it easy to split the XML and pass chunks of XML data as bytearray. Examples/sample code would be fantastic. Please advise. Thanks

https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q026360_.htm
You should be able to use the flag MQMF_SEGMENTATION_ALLOWED and MQGMO_COMPLETE_MSG which lets the MQ API split and reassemble large messages.
However, it's not supported by all platforms, in which case you have to do that programmatically using the the GroupId,MsgSeqNumber,Offset and OriginalLength MQMD fields.

Related

convert AngularJS to word document

I have in my disposal a Spring MVC backed server, using AngularJS in client side to display dynamic content. Was researching possibility to get current content displayed in the browser and convert it to a word document.
I assume there's a way to do build word documents with Java, but to do so i'll have to send existing HTML to the server side - how would i do that? just send the document DOM object?
Suppose i'll be able to do so, what if i want to include 2 images? I do know its possible to send images as base64 string.
To conclude, my general approach would be to try and send all client side data to the server and use Java to generate word document.
I have found docx4j so this approach seems possible.
Is that the right way to go? Any thoughts would be appriciated.
On the server side, you can use a library like Apache POI for creating docx documents.
There are multiple ways to pass data from client to server:
Make an AJAX call
How to send FormData objects with Ajax-requests in jQuery?
Ajax Upload image
Submit a form from the client side to the server using POST. Using multi-part forms will allow you to send attachments to the server
See Handling HTML (multipart form-data) file uploads with Java
On the client side, there are some JS libraries available for creating docx documents:
https://github.com/evidenceprime/html-docx-js
Generate a Word document in JavaScript with Docx.js ?

POSTing xml over HTTPS with Java

This is going to be running on a server which will then send the xml request to another server (over which I have no control). I can't afford to write an xml to the hard drive for every request. So ideally I'd like to create an xml without creating the file.
This shows how to send an xml file (not an object) over https: http://pic.dhe.ibm.com/infocenter/iisinfsv/v9r1/index.jsp?topic=%2Fcom.ibm.swg.im.iis.ia.restapi.doc%2Ftopics%2Fr_restapi_sending_https_java.html I've got that part working, problem is even after changing the content type to xml I think it was simply sending the content of the xml as plain text which seems very inelegant.
I'd rather avoid third party jars as much as possible but I do have access to the apache.axiom and axis 2 library.
So long story short: how do I make an xml object and then send it via HTTPS to a third party web-service that is not using SOAP or REST.
The HTTP request is generally correct to send XML as text, with the correct content type.
If you have a DOM object of some sort, you would just serialize it to XML, as text, either on disk or in a buffer or a string, and then send that, as per the link, to the other server. The other server will parse the XML string and get whatever form of object it wants.

Java Multipart/post download

I have few question related to Web technologies. From my reading ant looking at Apache and Netty documents I could not figure out few things about downloading a large file with HTTP multipart/post request.
Is it possible to send HTTP request indicating request to download a file in smaller multipart (chunks)?
How to download large file in multipart ?
Please correct me if I have not understood the 'multipart' term itself. I know lot of people have faced this problem, where application (client) downloads files in smaller portion, so when network outage happens, application does not need to download whole file from the beginning again. Specially, when the file is not any media file.
Thanks.
Multipart refers to encoding multiple documents in one body, see this for the definition. For http, a multipart upload allows the client to send multiple documents with one post, for example uploading an image, and form fields in one request.
Multipart does not refer to downloading a document in multiple chunks.
You can use http ranges to restart downloading if a network outage occurs.

jboss web services to tranfer files

I dont have any experience for web services. please give me some suggestion about the task below.
the task is:
users will send a txt file (size should less than 20K ) from a .NET application, I need to write a web services which runs by jboss 5.x to read this file and edit this file and send the file back to .NET UI to display the edited version.
question is that if the txt file is just text string or binary string, are there any restriction of the string length? if it's binary string, can I need to use BinaryReader class to read it? or not need special reader to read it? (this could be a dumn question :P)
what if the .NET application can save the file on either the .NET application server or some shared server location, send a download URL to web serivces, can web services download it and read it? JBoss will be run on Linux sever.
After edit the file, how do I send it back?
Thanks for your help!
It's hard to find reliable information about limitations in size, this depends on the libraries you use.
I would rather use an attachment than a single string containing the whole file Handling attachments in SOAP
For .Net see Add Attachments to a SOAP Message by Using DIME
After edit the file, how do I send it
back?
Request processFile(File)
Response UniqueId
Request getProcessedFile(UniqueId)
Response Edited File

Upload file to webservice (java)

I am looking for a solution to upload a file from a client to a server connected through a web service.
The client is written in c# and the web Service in java.
The files can be rather large < 100MB.
What approach would you suggest is best ?
Base64 encode the file and send it as an attachment. If you need to make sure the contents of the attachment do not get changed en route, use MTOM. Otherwise, use DIME.
Agree an encoding on both client and server then serialize the file using that encoding, wrap it in CDATA tags and assign the value to a text node in your SOAP request on the client.
Read the data between the CDATA tags on the server, deserialize it using the agreed encoding and you'll have the byte stream to use as need be.
It's probably a good idea for the encoding to involve some sort of compression if the files are large, although be wary of interop issues if the client is .NET and the server Java.
For the server side, you should have a look at Commons File Upload

Categories

Resources