RESTful Webservices with PDF as an input file - java

Is is possible to exchange PDF file as a input for RESTful webservices and also I would like to send PNG image as a response to it.
If we can do it through REST services please provide me the references link to implement it using REST services.

I was able to achieve a similar output by converting the file to string/byte[] data and sending it via REST.
My implementation was in Java and the steps used is outline below
Convert the file on disk to byte[] array (apache common-io can convert the file to byte[] in easy step. Try the IOUtils class)
Encoded the byte[] as String (apache common-codec was used for the encoding)
Wrapped the string data in a model class
Converted the model class to json format (GSON was used for the conversion)
Sent the json data over to the server
The server application reversed the process, and the file was available on the server

A rest service isn't the right way for what you want. The input for this kind of services are HTTP request attributes or some kind of pushed data. Maybe it's possible to implement a file upload but it's not typical.
For restful services is also common to tell your service how to handle the requested resource via the used request method (GET, POST, PUT, DELETE)
The response of rest services is normally some kind of structured text output - for instance json.
All in all rest services seems to me not the way to implement your desired scenario.
What about a normal cgi or servlet solution?

Related

Can a REST Service Controller read a text file which is located at the path given in request param?

My requirement is to create a java restful web service which reads a text file and pull out some information from that text file. I am new to restful web services so I don't know exactly how to code this. I am thinking there would be a REST Service Controller which has a post HTTP method that takes a file path as a request parameter.
Now I wonder how that rest controller has an access to that file or can rest controller read it and extract information from that file?
The location to the file would not be enough, you will need to send the protocol to connect to the location of the file, the timeout for the connection, and if the protocol needs some authentication you need to verify it and send the required parameters.
Implementing the rest controller is not issue, after exposing an api you can use InputStream to read the content of the file, check the docs

Apache Axis2 Web service : Gzip resquet and response

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.

How to deliver .jad file using Jersey Rest service?

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.

Servlet 3.0 streaming api for file upload

New Servlet 3.0 API provide us with convenient way to parse multi-part form data. But it stores content of uploaded files in file system or in memory
Is there streaming API for Servlet 3.0 ?
Something like Commons FileUpload. I have to write content directly from InputStream and write to another OutputStream adn I don't want to store temporary file content in disc or memory
I used this once for something similar, though not with servlets. It doesn't fill up your memory with data. Hope it helps:
http://code.google.com/p/io-tools/wiki/Tutorial_EasyStream
Looking at the Servlet 3.0 spec it may not be possible to have a streaming implementation
For parts with form-data as the Content-Disposition, but without a
filename, the string value of the part will also be available via the
getParameter /getParameterValues methods on HttpServletRequest, using
the name of the part.
So the request must be parsed up front so that all the non-file parts can be exposed as HttpServletRequest parameters.
You have to use third party libraries if you need streaming.

How to expose Blob (Image) data via REST webservice

I'm storing images in blob form in a MySql database table. I need to expose these images via a REST webservices and was wondering what my options are. The main option I see is to read the database, create the image and store it on the filesystem and send the path to the image in the REST response. Any other ideas here? I'm thinking I will use RESTeasy for my JAX-RS implementation. Thanks for the help!
You can parse your image into bytes and then can send those bytes in JSON form via web service.

Categories