I am developed a web service that return simple string using axis2 . But i want to apply gzip compression techniques , in my web service. can anyboby give me server code and client code for it. I developed web service from this reference
http://blog.sencide.com/2011/06/create-web-service-using-apache-axis2.html
Please provide proper guidance.
Thanx
Are you trying to do the Zip yourself, or just trying to compress the bits as they travel through the wire?
If you just want to compress the responses from your server, I know Apache has several ways of doing it. I would suggest looking here as a start.
If you are trying to create your own zip file, which you are sending in the response of your WS, and the client is expecting a zip file, then you want to look at java.util.zip. It provides several classes that read/write various ZIP formats. I would look at GZipOutputStream. It appears to work like any other OutputStream, allowing you to write out some byte[] array.
Related
I want to download a very large file using camel, but I don't want to hold the entire file in memory and THEN save it to file.
I want to stream the file in and save or write to a file in chunks.
Is this possible with Camel, and if so, how do I do this?
Note: Is it possible that the endpoint I am downloading the file does not support streaming/chunking? If yes, how can I verify this?
Camel's HTTP component uses Netty to make the request. Netty reads the entire response into memory, so there is no way to do what you are asking for.
You would need to implement your own endpoint for Camel that utilizes another HTTP library which has support for HTTP response streaming.
More documentation is available here :
https://cwiki.apache.org/confluence/display/CAMEL/Netty4+HTTP
You can 3 option to download the file i.e. using:
ftp://[username#]hostname[:port]/directoryname[?options]
sftp://[username#]hostname[:port]/directoryname[?options]
ftps://[username#]hostname[:port]/directoryname[?options]
There is a option of streamDownload in it.
For more check out http://camel.apache.org/ftp.html
I know Java prog. langugage but, I am a complete beginner in Java EE and web services, soap etc. I need to compress a message before sending and add a signature to it with Apache wss4j.
I followed tutorials in Netbeans website and created a web service and a web service client which consumes the corresponding service.(A number adding service and a client) I am reading the official Java EE documents but i couldn't understand and write something. I am searching for example codes and projects but coulndn't find related codes or understand which I found.
These are the ones I found:
http://www.devx.com/Java/Article/28816/1954
http://ws.apache.org/wss4j/xref-test/org/apache/ws/security/message/SignatureTest.html
But where to add these codes in my project. How to add signature and compress? Thanks, in advance.
You can use GZip present in java.util.zip pkg.
java.util.zip.GZIPInputStream;
java.util.zip.GZIPOutputStream;
to zip and unzip you need to use org.apache.axis.encoding.Base64 to encode and decode.
I have to return a JavaME .jad file from restful web service (using Jersey), which is then used to install an app on a mobile phone. Before delivering the .jad file some values in there have to be changed. I was thinking of reading the original file, change the read input and writing it back to some outputstream. Can I just return the output stream in a Jersey Rest services? Is there anything special I have to take of in terms of mime-type, etc.? Does anyone know of some kind of example code or tutorial for this purpose?
Thanks in advance
Either like here:
Input and Output binary streams using JERSEY?
or you could send the StreamingOutput as an entity like this:
return Response.ok(streamingOutput).type("text/vnd.sun.j2me.app-descriptor");
Point is you have to use the OutputStream handed to you via the StreamingOutput.write(OutputStream outputStream) method.
I'm writing a Java desktop client which will send multiple files over the wire to a servlet using a post request. In the servlet I'm getting the input stream from the request to receive the files. The servlet will write the files to disk, one by one as they're read from the stream.
The implementation has a couple of requirements:
Only one HTTP request must be used to the server (so only a single stream)
The servlet must use a reasonable fixed amount of memory, no matter what the size of the files.
I had considered inserting markers into the stream so I know when one file ends and the next one begins. I'd then write some code to parse the stream in the servlet, and start writing the next file as appropriate.
Here's the thing... surely there's a library to do that. I've looked through apache commons and found nothing. Commons File Upload is interesting but since the upload comes from a Java app, not a browser it only solves the receiving end, not the sending.
Any ideas for a library which easily allows multiple file transfers across a single stream with fixed memory expectations even for very large files?
Thanks.
Just use HTTP multipart/form-data encoding on the POST request body. It's described in RFC-2388 and a standard way of uploading (multiple) files by HTTP.
You can do it with just java.net.URLConnection as described in this mini-tutorial, although it would generate lot of boilerplate code. A more convenienced approach would be using Apache Commons HttpClient.
In the servlet side you can then just use Apache Commons Fileupload to process the uploaded files the usual HTTP way (or when you're already on Servlet 3.0, the HttpServletRequest#getParts(), see also this answer for examples).
Do Java REST frameworks like Restlet and Jersey allow one to send a file as input to a web service?
This would encompass the client sending the file and the server then receiving and processing the file.
If you're asking if you can do an HTTP PUT to a Restlet service, then, absolutely, yes you can. You can use the Directory class if you just want to store the file, or you can implement your own ServerResource to handle the new resource.
I haven't used Jersey, but Restlet is a fantastic api.
Well, there's no restriction for them not to do it. REST handles files without any problems.
Take a look at:
http://mikedesjardins.us/wordpress/2007/04/restful-services-on-ftp/
You can also use REST Assured which builds on HTTP Client. It's very simple:
given().multiPart(new File("/somedir/file.bin")).when().post("/fileUpload");