• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic