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.
Related
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 ?
I have built a Java client for an external web service. When I send a request using Eclipse I get a response, but it is not the response I expect. I think I have traced this to one of the fields (a date field), but I can't work out if it is on my side that the conversion is wrong or on theirs, only that the response returns a different date than the one I sent.
How can I see the SOAP request in the xml format that it is sent in to check how the date field is being sent to the external service?
You just need to use a Jax-WS interceptor/handler. They are very easy to write. Netbeans actually has great built in support for them. But if you want to write one from scratch, check out this question
You can use Wireshark. It's pretty easy. If you don't know how to use it just type "wireshark soap" in Google.
I am new to web programming. My web application can upload files (uploaded by drag and drop method in javascripts ) and i want to retrieve them in servlet using Json . servlet file only needs the contents of the text files to do the calculation.
Can any one suggest how to do this ?
softwares used - netbeans ,tomcat
Thank you.
I'm not quite sure if you mean rendering your files in servlets or actually downloading them from your browser. I'm going to assume you mean rendering them. If so, then what you have to do is set up a URI which is associated with the content you want to render. Let's say this is a simple "hello world" rendering in the browser. what you would do is set up a URI as such:
localhost:3000/helloWorld.html.jsp
What you do on your back end is then wait to receive a http GET request to "/helloWorld.html.jsp" page, and then have your router send over the correct page. Luckily, with tools such as tomcat, the routing from local host is straight forward enough, and as your comments mentioned this is simple enough to do with the ample resources on the web.
Also an important point, you don't need JSON when using servlets (if i understood your problem correctly). If you want to send over data in a JSON format, then all you would do is modify the above steps to listen for "/sendJSON.html.jsp" (this could be an empty jsp), and you send over JSON from your back end in your response.
I'm creating a java web application runing on a Tomcat server.
One of the functions fill in a StringBuffer variable with data.
At the end, I would like to propose the user to download the generated content packaged in a text file. This without having to store the file on the server.
I've been searching for a code snippet but couldn't find anything corresponding ...
I hope I've been clear enough on my problem.
Thanks in advance,
See Making A Download Servlet
Don't forget to add the servlet to your web.xml.
You have to send a content-type along with the response, so that the browser knows what to do with the body of the response.
Normal text has the content-type text/plain, html is text/html. Images are image/gif and so on. For an unknown mime type you normally set "application/octet", which afaik every browser treats as a download. But I recommend to use the propery content type, so the browser might start a matching application to handle the content (e.g. Office for Documents or XML Editor for XML Files ..)
To send a filename along, which the browser suggests for saving, use the following header (example):
Content-Disposition: attachment; filename="downloaded.pdf"
For sending custom headers, use the setHeader() method in the response object.
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