This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes passing a matrix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "passing a matrix" Watch "passing a matrix" New topic
Author

passing a matrix

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

I want to pass a matrix to my web service, perform some computation there and receive a solution. What would you suggest to pass the matrix? XML format?


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Aaron Liu
Greenhorn

Joined: Apr 16, 2010
Posts: 15
of course. what your option?
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Can I pass a serialized object to a web service's method?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
With web services, data is commonly passed in XML or JSON (http://en.wikipedia.org/wiki/Json) format in order to facilitate interoperability.
When using JAX-WS or JAX-RS tools, objects that are to be passed between clients and server are marshaled to XML, using for instance JAXB, or to JSON, using for instance Jackson, and later unmarshaled to Java objects. Commonly, marshaling and unmarshaling are hidden from the developer (but it depends on the development environment etc).
Interoperability is one of the main arguments for using web services. If you do not have any requirements in that area, you may also consider using, for instance, RMI, which will allow you to use plain serialization to pass data between client(s) and server.
Best wishes!
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Thanks. I have the matrix in txt file in that format:

value value ...
.
.
value...

Could you give me an example how to pack it into XML format? And then, how can I invoke web service's method with that matrix as an argument? I will be really grateful for help.

PS what do you mean by interoperability?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
First of all, interoperability is the ability for, for instance, a web service implemented in Java is able to communicate with a client written in another language, like .NET.
Despite using XML (for SOAP web services), interoperability is not guaranteed.

Second, here is how to represent a map using XML; first the XML schema:

The XML schema includes an uniqueness constraint on the key in a key-value list.
Finally, an example of what an XML document adhering to the above schema may look like:

Hope this helps!
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Thanks.
How can I pass that XML file to Webservice (JAX-WS)?
I would like to invoke webservice's method using that XML file as an argument.
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Can anyone help?
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Nobody knows? I do not believe
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you are doing WSDl-first development, then you just paste the XML schema from my posting into your WSDL and use the data type appropriately.
If you are doing Java-first development, then you can use the JAXB schema compiler XJC to generate Java classes corresponding to the schema.
When generating Java classes with XJC, you will loose the uniqueness constraint specified in the XML schema.
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing a matrix
 
Similar Threads
WA #1.....word association
How do I handle "The Matrix" ?
Class Design Problem
Passing Parameters between classes
The question