my dog learned polymorphism*
The moose likes Web Services and the fly likes can I create a web service that generates a .csv or .txt file ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "can I create a web service that generates a .csv or .txt file ?" Watch "can I create a web service that generates a .csv or .txt file ?" New topic
Author

can I create a web service that generates a .csv or .txt file ?

steve francisco
Ranch Hand

Joined: Jan 26, 2005
Posts: 46
I am thinking about publishing a web services that generates a .csv or .txt or .xls format file given some input. When a client passes some input data to this web services, it generates a .csv or .txt file and return it to the client. As a total novice to this subject, I just herad that web services returns soap xml to client. So can it returns the file in those formats and how ?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Web services return SOAP. So you wouldn't be able to return a file, if that is your question. If you wanted to return text in a specific format than you would return that within the SOAP response. If you wanted to return binary you would use a SOAP attachment.


Please ignore post, I have no idea what I am talking about.
Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
Originally posted by William Barnes:
Web services return SOAP. So you wouldn't be able to return a file, if that is your question. If you wanted to return text in a specific format than you would return that within the SOAP response. If you wanted to return binary you would use a SOAP attachment.


SOAP sounds bit "abstract" to people. Could you be more specific, what kind data is suitable to be included in "SOAP" ? How about String, Arraylist, or special data structure ?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

> SOAP sounds bit "abstract"

SOAP is xml. Web services, using SOAP, can pass around anything. But there are ones which are "built in". And string is one of them. Here is one , of many, sites at which you can learn about SOAP.
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
Originally posted by steve francisco:
I am thinking about publishing a web services that generates a .csv or .txt or .xls format file given some input. When a client passes some input data to this web services, it generates a .csv or .txt file and return it to the client. As a total novice to this subject, I just herad that web services returns soap xml to client. So can it returns the file in those formats and how ?


1. Write a plain old java class with a method that creates a file based on input parameters and returns either an output file name or output stream.

2. Test the helper class with your servlet (servlet is the client of the helper).

3. Convert the helper class into a java web service by changing file extension from .java to .jws.

4. Put the .jws file into Axis web app root directory. Axis app will generate a WSDL file for the jws at request time, assuming that you have installed apache axis and deployed sample app axis.war to your server's deploy directory.

5. Convert WSDL to java to use the helper web service in your servlet like below:

java org.apache.axis.wsdl.WSDL2Java --verbose http://server.com/axis/HelperClassName.jws?wsdl

Make sure that you have axis.jar file in your classpath while executing this command, as that is where org.apache.axis.wsdl.WSDL2Java resides.

You will find a number of .java files generated in a subdirectory named your helper. These are the stub files or wrapper classes. You need to compile generated classes and put in your class directory of your application.

6. In your servlet, create an instance of web service locator class generated in the previous step. The exact location of the service will be transparent to the client, the servlet in this case. Using the locator, create a helper web service instance and call necessary method on it.

Good luck!
[ April 04, 2005: Message edited by: Heonkoo Lee ]
steve francisco
Ranch Hand

Joined: Jan 26, 2005
Posts: 46
thanks folks for the reply. I think I understand better about web services now. I want to use RPC method call to invoke a web service that process the file generation. In the RPC call, client will pass a String[][] as parameter like --- String requestFileGeneration(String[][] args). Is there anything I need to pay special attention (like Serialization, etc) ? Is it OK to pass String[][] as parameter in the RPC method call ?
keerthi matta
Greenhorn

Joined: May 31, 2002
Posts: 27
You can try out using MIME type in your WSDL, if byte[] is permissible to your requirement, and if AXIS permits. I have used MIME with Weblogic8.1sp2 to get back a document in byte[] from WebService.

Sample code:

<wsdl:input>
<mime:multipartRelated>
<mime art>
<soap:body parts="inputMetaData" use="literal"/>
</mime art>
<mime art>
<mime:content part="reportContent" type="application/octet-stream"/>
</mime art>
</mime:multipartRelated>
</wsdl:input>
Saqib Rasul
Greenhorn

Joined: Apr 08, 2005
Posts: 11
Originally posted by steve francisco:
thanks folks for the reply. I think I understand better about web services now. I want to use RPC method call to invoke a web service that process the file generation. In the RPC call, client will pass a String[][] as parameter like --- String requestFileGeneration(String[][] args). Is there anything I need to pay special attention (like Serialization, etc) ? Is it OK to pass String[][] as parameter in the RPC method call ?


Watch out for interoperability issues when using a RPC style Web Service. The Document-Literal style Web Service is better.

Regards,

Saqib


<a href="http://galaxy.sagadc.com/" target="_blank" rel="nofollow">http://galaxy.sagadc.com/</a><br />- Web Services in 15 minutes -
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can I create a web service that generates a .csv or .txt file ?